コード例 #1
0
def init_environment():
    """
    This runs before every test
    """

    global interface
    interface = make_interface("ganache")

    mainblocks = 100
    fork_index = 50
    forkblocks = 100
    pt = ProofTool("../data/proofs/")
    (
        proof_name,
        fork_name,
        lca,
        fork_header,
        fork_header_map,
        fork_interlink_map,
    ) = pt.create_proof_and_forkproof(mainblocks, fork_index, forkblocks)

    global proof
    proof = Proof()
    proof.set(pt.fetch_proof_by_name(proof_name))

    global fork
    fork = Proof()
    fork.set(
        pt.fetch_proof_by_name(fork_name),
        header=fork_header,
        header_map=fork_header_map,
        interlink_map=fork_interlink_map,
    )
コード例 #2
0
def test_dispute_invalid(init_environment):
    """
    Try to dispute valid proof
    """

    block_of_interest_index = 0
    interface = make_interface(backend)
    invalid_index = int(proof.size / 2)

    invalid_proof = Proof()
    invalid_proof.set(change_interlink_hash(proof.proof, invalid_index))

    res = submit_event_proof(
        interface, invalid_proof, block_of_interest_index, profile=True
    )
    assert res["result"] == True

    res = dispute_existing_proof(
        interface,
        invalid_proof,
        block_of_interest_index,
        invalid_index,
        profile=True,
    )
    assert res["result"] == True
コード例 #3
0
def test_smaller_k(init_environment):
    """
    Submit a proof with k=1
    """

    proof = Proof()
    proof.set(pt.fetch_proof("../data/proofs/proof_100_m15_k1.pkl"))

    interface = make_interface(backend)

    with pytest.raises(Exception) as ex:
        submit_event_proof(interface, proof, 0)
コード例 #4
0
def init_environment():
    """
    This runs before every test
    """

    global backend
    global proof
    backend = "ganache"

    blocks = 10

    proof = Proof()
    proof.set(ProofTool("../data/proofs/").fetch_proof(blocks))
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
def init_environment():
    """
    This runs before every test
    """

    backend = "ganache"
    global interface
    interface = make_interface(backend)

    global proof
    global headless_proof
    proof = Proof()
    headless_proof = Proof()

    original_proof = ProofTool("../data/proofs/").fetch_proof(100)
    proof.set(original_proof)

    _headless_proof = original_proof.copy()
    remove_genesis(_headless_proof)
    headless_proof.set(_headless_proof)
コード例 #10
0
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,
    )
コード例 #11
0
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,
    )