def merkle_test(r): print "***************" print "Running merkle_test("+str(r)+"), starting at "+str(datetime.datetime.now())+"." p = pebble.PebbleGraph(r, debug=True) pebbling_algos.trivial_pebble(p, p.size()-1) print "Building Merkle tree..." mt = trees.MerkleNode(p.list_values()) print "Merkle tree setup complete. Root: "+mt.root() print "merkle_test("+str(r)+") completed at "+str(datetime.datetime.now())+"." print "***************" p.close_files()
def __init__(self, r, debug=False): self.debug = debug if self.debug: print "P: Starting up." self.r = r self.p = pebble.PebbleGraph(r) pebbling_algos.trivial_pebble(self.p, self.p.size()-1) # code to build MT #self.mt = trees.MerkleNode(self.p.list_values()) self.mt = shelve.open(filename) self.mt["leaf_values"] = self.p.list_values() self.mt["leaf_keys"] = trees.MT([0, self.p.size()], self.mt, "") if self.debug: print "P: Good to go, __init__ completed."
def __init__(self, r, debug=False): self.debug = debug if self.debug: print "P: Starting up." self.r = r self.p = pebble.PebbleGraph(r) pebbling_algos.trivial_pebble(self.p, self.p.size() - 1) # code to build MT #self.mt = trees.MerkleNode(self.p.list_values()) self.mt = shelve.open(filename) self.mt["leaf_values"] = self.p.list_values() self.mt["leaf_keys"] = trees.MT([0, self.p.size()], self.mt, "") if self.debug: print "P: Good to go, __init__ completed."
def pebble_all_trivial(r): print("***************") print("Running pebble_all_trivial("+str(r)+").") p = pebble.PebbleGraph(r, debug=True) for i in range(p.size()): print("Pebbling vertex "+str(i)) pebbling_algos.trivial_pebble(p, i) if(p.is_pebbled(i)): print("Vertex "+str(i)+" successfully pebbled, using "+str(p.max_pebbles)+" pebble(s) in total.") else: print "Vertex " + str(i) + " was not successfully pebbled." p.reset() print("pebble_all_trivial("+str(r)+") completed at "+str(datetime.datetime.now())+".") print("***************") p.close_files()
def pebble_graph_trivial(r, print_much=True, pre_gen_graph=False, debug_flag=False): if (print_much): print "***************" print "Running pebble_graph_trivial(" + str( r) + ", pre_gen_graph=" + str( pre_gen_graph) + "), starting at " + str( datetime.datetime.now()) + "." start_generate = time.time() p = pebble.PebbleGraph(r, pre_generated_graph=pre_gen_graph, debug=debug_flag) end_generate = time.time() start_pebble = time.time() pebbling_algos.trivial_pebble(p, p.size - 1) if p.is_pebbled(p.size - 1) and print_much: print "The final vertex in PTC(" + str( r) + ") was successfully pebbled." if not p.is_pebbled(p.size - 1): print "ERROR: The final vertex in PTC(" + str( r) + ") was not successfully pebbled." if (print_much): print "Vertices in graph: " + str(p.size) print "Seconds elapsed to generate graph: " + str(end_generate - start_generate) print "Vertices generated per second: " + str( p.size / (end_generate - start_generate)) print "Seconds elapsed to pebble Butterfly PTC " + str( r) + " graph: " + str(time.time() - start_pebble) if (print_much): print "Vertices pebbled per second: " + str( p.size / (time.time() - start_pebble)) print "Total seconds elapsed: " + str(time.time() - start_generate) print "Vertices generated and pebbled per second: " + str( p.size / (time.time() - start_generate)) print "pebble_graph_trivial(" + str(r) + ", pre_gen_graph=" + str( pre_gen_graph) + ") completed at " + str( datetime.datetime.now()) + "." print "***************" p.close_files()
def pebble_graph_trivial(r): print "***************" print "Running pebble_graph_trivial(" + str(r) + "), starting at " + str(datetime.datetime.now()) + "." start_generate = time.time() p = pebble.PebbleGraph(r) # debug is automatically set to false end_generate = time.time() start_pebble = time.time() pebbling_algos.trivial_pebble(p, p.size() - 1) if p.is_pebbled(p.size() - 1): print "The final vertex in PTC(" + str(r) + ") was successfully pebbled." else: print "ERROR: The final vertex in PTC(" + str(r) + ") was not successfully pebbled." print "Vertices in graph: " + str(p.size()) print "Seconds elapsed to generate graph: " + str(end_generate - start_generate) print "Vertices generated per second: " + str(p.size() / (end_generate - start_generate)) print "Seconds elapsed to pebble graph: " + str(time.time() - start_pebble) print "Vertices pebbled per second: " + str(p.size() / (time.time() - start_pebble)) print "Total seconds elapsed: " + str(time.time() - start_generate) print "Vertices generated and pebbled per second: " + str(p.size() / (time.time() - start_generate)) print "pebble_graph_trivial(" + str(r) + ") completed at " + str(datetime.datetime.now()) + "." print "***************" p.close_files()
def __init__(self, r, pre_gen_graph=False, debug=False): self.debug = debug if self.debug: print "P: Starting up." self.r = r self.p = pebble.PebbleGraph(r, pre_generated_graph=pre_gen_graph) self.ptc_size = self.p.size pebbling_algos.trivial_pebble(self.p, self.ptc_size-1) self.merkle_tree_rows = 1 while(2**(self.merkle_tree_rows - 1) < self.ptc_size): self.merkle_tree_rows += 1 self.merkle_tree_size = 2**(self.merkle_tree_rows) - 2 # This is actually one less than the size. It actually stands for the number of the last node numbered 0 - n. # Finishes filling bottom row of merkle tree. self.p.pebble_value.seek(self.ptc_size * self.p.hash_length) for i in range(2**(self.merkle_tree_rows-1) - self.ptc_size): self.p.pebble_value.write("\00" * self.p.hash_length) self.merkle_root = "" if self.debug: print "P: Good to go, __init__ completed."
def __init__(self, r, pre_gen_graph=False, debug=False): self.debug = debug if self.debug: print "P: Starting up." self.r = r self.p = pebble.PebbleGraph(r, pre_generated_graph=pre_gen_graph) self.ptc_size = self.p.size pebbling_algos.trivial_pebble(self.p, self.ptc_size - 1) self.merkle_tree_rows = 1 while (2**(self.merkle_tree_rows - 1) < self.ptc_size): self.merkle_tree_rows += 1 self.merkle_tree_size = 2**( self.merkle_tree_rows ) - 2 # This is actually one less than the size. It actually stands for the number of the last node numbered 0 - n. # Finishes filling bottom row of merkle tree. self.p.pebble_value.seek(self.ptc_size * self.p.hash_length) for i in range(2**(self.merkle_tree_rows - 1) - self.ptc_size): self.p.pebble_value.write("\00" * self.p.hash_length) self.merkle_root = "" if self.debug: print "P: Good to go, __init__ completed."