def main(): """ Test Proof """ proof_tool = ProofTool() ( proof_name, fork_proof_name, lca, fork_header, fork_header_map, fork_interlink_map, ) = proof_tool.create_proof_and_forkproof(100, 10, 20) my_proof = Proof() my_proof.set(proof_tool.fetch_proof(proof_name)) p = my_proof.best_level_subproof my_fork_proof = Proof() my_fork_proof.set( proof_tool.fetch_proof(fork_proof_name), header=fork_header, header_map=fork_header_map, interlink_map=fork_interlink_map, ) pp = my_fork_proof.best_level_subproof my_proof_tip = Proof() my_proof_tip.set(my_proof.proof[:lca]) print(blockchain_utils.Hash(my_fork_proof.proof[-1][0]).hex()) print(blockchain_utils.Hash(pp[-1][0]).hex()) print("Best proof has length", len(my_fork_proof.best_level_subproof))
def init_environment(): """ This runs before every test """ global backend global submit_proof global small_contest_proof global small_lca global large_contest_proof global large_lca backend = "ganache" pt = ProofTool() pt.fetch_proof(1000) ( submit_proof_name, small_contest_proof_name, small_lca, small_header, small_header_map, small_interlink_map, ) = pt.create_proof_and_forkproof(1000, 200, 100) ( submit_proof_name, large_contest_proof_name, large_lca, large_header, large_header_map, large_interlink_map, ) = pt.create_proof_and_forkproof(1000, 100, 200) submit_proof = Proof() submit_proof.set(pt.fetch_proof(submit_proof_name)) small_contest_proof = Proof() small_contest_proof.set( pt.fetch_proof(small_contest_proof_name), header=small_header, header_map=small_header_map, interlink_map=small_interlink_map, ) large_contest_proof = Proof() large_contest_proof.set( pt.fetch_proof(large_contest_proof_name), header=large_header, header_map=large_header_map, interlink_map=large_interlink_map, )
def main(): """ Test for backends """ available_backends = ContractInterface.available_backends() parser = argparse.ArgumentParser( description="Benchmark Py-EVM, Ganache and Geth") parser.add_argument( "--backend", choices=available_backends + ["all"], required=True, type=str, help="The name of the EVM", ) group = parser.add_mutually_exclusive_group(required=True) group.add_argument("--blocks", type=int, help="Number of blocks") group.add_argument("--proof", type=str, help="Name of proof") parser.add_argument("--timer", action="store_true", help="Enable timers") args = parser.parse_args() backend = args.backend blocks = args.blocks proof_name = args.proof if backend == "all": backend = available_backends else: backend = [backend] proof_tool = ProofTool("../data/proofs/") if blocks is not None: proof = proof_tool.fetch_proof(blocks) elif proof_name is not None: proof = proof_tool.fetch_proof(proof_name) else: print("You need to provice --blocks of --proof") print("Proof lenght:", len(proof)) _p = Proof() _p.set(proof) for _b in backend: print("Testing", _b) res = run_nipopow(_b, _p) print("Result:", res)
def init_environment(): """ This runs before every test """ global backend global proof global changed_interlink_proof global missing_blocks_proof global replaced_blocks_proof backend = "ganache" proof = Proof() changed_interlink_proof = Proof() missing_blocks_proof = Proof() replaced_blocks_proof = Proof() original_proof = ProofTool("../data/proofs/").fetch_proof(100) proof.set(original_proof) _changed_interlink_proof = change_interlink_hash( original_proof, int(changed_interlink_proof.size / 2)) changed_interlink_proof.set(_changed_interlink_proof) _missing_blocks_proof = original_proof.copy() _missing_blocks_proof = skip_blocks(_missing_blocks_proof, -3) missing_blocks_proof.set(_missing_blocks_proof) _pt = ProofTool() _replaced_blocks_proof = _pt.fetch_proof( "../data/proofs/proof_100_replaced_mid_block.pkl") replaced_blocks_proof.set(_replaced_blocks_proof)
def main(): """ Test for backends """ proof_tool = ProofTool("../data/proofs/") proof_tool.fetch_proof(80) (submit_n, contest_n, _, _, _, _) = proof_tool.create_proof_and_forkproof(80, 10, 25) proof = Proof() proof.set(proof_tool.fetch_proof_by_name(submit_n)) c_proof = Proof() c_proof.set(proof_tool.fetch_proof_by_name(contest_n)) interface = ContractInterface(contract={ "path": "../OldContract.sol", "ctor": [] }, backend="geth") result = interface.call( "submitEventProof", function_args=[proof.headers, proof.siblings, proof.headers[-1]], value=pow(10, 17), ) sum = 0 print(result) for e in result["events"]: print(e[0], "\t", e[1]) sum += e[1] print("Sum:", sum) result = interface.call( "submitContestingProof", function_args=[c_proof.headers, c_proof.siblings, c_proof.headers[-1]], ) interface.end() sum = 0 print(result) for e in result["events"]: print(e[0], "\t", e[1]) sum += e[1] print("Sum:", sum)
def init_proofs(backend, mainchain_blocks, fork_point, additional_blocks): """ create proofs for two contesting chains mainchain_blocks +-------------+ v v --------+-----> Chain A | +-> +--------> Chain B | | ^ ^ | | | | +--------+ | | fork_point additional_blocks """ pt = ProofTool() pt.fetch_proof(mainchain_blocks) ( submit_proof_name, contest_proof_name, contest_lca, contest_header, contest_header_map, contest_interlink_map, ) = pt.create_proof_and_forkproof(mainchain_blocks, fork_point, additional_blocks) submit_proof = Proof() submit_proof.set(pt.fetch_proof(submit_proof_name)) contest_proof = Proof() contest_proof.set( pt.fetch_proof(contest_proof_name), header=contest_header, header_map=contest_header_map, interlink_map=contest_interlink_map, ) return (submit_proof, contest_lca, contest_proof)
def init_environment(): """ This runs before every test """ global backend global interface backend = "ganache" interface = ContractInterface( { "path": "../contractNipopow.sol", "ctor": [genesis, m, k] }, backend=backend, ) global submit_proof global contest_proof pt = ProofTool() pt.fetch_proof(20) ( submit_proof_name, contest_proof_name, contest_lca, contest_header, contest_header_map, contest_interlink_map, ) = pt.create_proof_and_forkproof(100, 50, 50) submit_proof = Proof() submit_proof.set(pt.fetch_proof(submit_proof_name)) contest_proof = Proof() contest_proof.set( pt.fetch_proof(contest_proof_name), header=contest_header, header_map=contest_header_map, interlink_map=contest_interlink_map, )
def main(): """ Create, edit and print chains and proofs """ parser = argparse.ArgumentParser( description="Prints the contents of a NiPoPoW") parser.add_argument("--blocks", required=True, type=int, help="Number of blocks") parser.add_argument("--output", default="proof.pkl", type=str, help="Name of exported proof") args = parser.parse_args() blocks = args.blocks output = args.output if output.find(".pkl") == -1: output += ".pkl" # Create blockchain header, headers_map, interlink_map = create_blockchain(blocks=blocks) print_headers(headers_map) print_interlinks(headers_map, interlink_map) # Create proof proof = make_proof(header, headers_map, interlink_map) print_proof(proof, headers_map) ### Start spoiling proof # remove_genesis(proof) # proof = change_interlink_hash(proof, 0) # proof = skip_blocks(proof, -2) # proof = replace_block(proof, headers_map, interlink_map, int(len(proof)/2)) # print_proof(proof, headers_map) # verify_proof(Hash(proof[0][0]), proof) ### Stop spoiling proof proof_tool = ProofTool("../../data/proofs/") p, f, lca = proof_tool.create_proof_and_forkproof(blocks, forkindex, forkblocks) print(p, f, lca) fixed_fork_proof = proof_tool.fetch_proof(f) verify_proof(Hash(fixed_fork_proof[0][0]), fixed_fork_proof)
def init_environment(): global backend global proof pt = ProofTool("../data/proofs/") proof.set(pt.fetch_proof(500))