def __init__(self, data): assert isinstance(data, list) assert len(data) > 0, 'Cannot construct an empty Merkle Tree.' num_leaves = 2**ceil(log2(len(data))) self.data = data + [FieldElement(0)] * (num_leaves - len(data)) self.height = int(log2(num_leaves)) self.facts = {} self.root = self.build_tree()
# a STARK proving mechanism # from StarkWare101 Workshop # in San Fransisco, 2/17/20 ########## # PART 1 # ########## # first step is to create a list of length 1023 # first two elements are FieldElement objects # representing 1 and 3141592 respectively. a = [FieldElement(1), FieldElement(3141592)] while len(a) < 1023: a.append(a[-2] * a[-2] + a[-1] * a[-1]) # quick unit test to verify a[] constructed properly assert len(a) == 1023, 'The trace must consist of exactly 1023 elements.' assert a[0] == FieldElement(1), 'The first element in the trace must be the unit element.' for i in range(2, 1023): assert a[i] == a[i - 1] * a[i - 1] + a[i - 2] * a[i - 2], f'The FibonacciSq recursion rule does not apply for index {i}' assert a[1022] == FieldElement(2338775057), 'Wrong last element!' print('Success!') # need a generator from field element class # need to generator a group of size 1024 g = FieldElement.generator() ** (3 * 2 ** 20)