Skip to content

test_push0_contracts()

Documentation for tests/shanghai/eip3855_push0/test_push0.py::test_push0_contracts@verkle@v0.0.6.

Generate fixtures for these test cases for Shanghai with:

Shanghai only:

fill -v tests/shanghai/eip3855_push0/test_push0.py::test_push0_contracts --fork=Shanghai --evm-bin=/path/to/evm-tool-dev-version

For all forks up to and including Shanghai:

fill -v tests/shanghai/eip3855_push0/test_push0.py::test_push0_contracts --until=Shanghai

Tests PUSH0 within various deployed contracts.

Source code in tests/shanghai/eip3855_push0/test_push0.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@pytest.mark.parametrize(
    "contract_code,expected_storage",
    [
        # Use PUSH0 to set a key for SSTORE.
        pytest.param(
            Op.SSTORE(Op.PUSH0, 1),
            Account(storage={0x00: 0x01}),
            id="key_sstore",
        ),
        # Fill stack with PUSH0, then OR all values and save using SSTORE.
        pytest.param(
            (Op.PUSH0 * 1024) + (Op.OR * 1023) + Op.SSTORE(Op.SWAP1, 1),
            Account(storage={0x00: 0x01}),
            id="fill_stack",
        ),
        # Stack overflow by using PUSH0 1025 times.
        pytest.param(
            Op.SSTORE(Op.PUSH0, 1) + (Op.PUSH0 * 1025),
            Account(storage={0x00: 0x00}),
            id="stack_overflow",
        ),
        # Update an already existing storage value.
        pytest.param(
            Op.SSTORE(Op.PUSH0, 2) + Op.SSTORE(1, Op.PUSH0),
            Account(storage={0x00: 0x02, 0x01: 0x00}),
            id="storage_overwrite",
        ),
        # Jump to a JUMPDEST next to a PUSH0, must succeed.
        pytest.param(
            Op.PUSH1(4) + Op.JUMP + Op.PUSH0 + Op.JUMPDEST + Op.SSTORE(Op.PUSH0, 1) + Op.STOP,
            Account(storage={0x00: 0x01}),
            id="before_jumpdest",
        ),
        # Test PUSH0 gas cost.
        pytest.param(
            CodeGasMeasure(
                code=Op.PUSH0,
                extra_stack_items=1,
            ),
            Account(storage={0x00: 0x02}),
            id="gas_cost",
        ),
    ],
)
def test_push0_contracts(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    post: Alloc,
    sender: EOA,
    contract_code: Bytecode,
    expected_storage: Account,
):
    """
    Tests PUSH0 within various deployed contracts.
    """
    push0_contract = pre.deploy_contract(contract_code)
    tx = Transaction(to=push0_contract, gas_limit=100_000, sender=sender)
    post[push0_contract] = expected_storage
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Skipped Parameters

For more concise readability, the table below does not list the following parameter values: fork, blockchain_test, state_test, state_test_only, eof_test, eof_state_test.

Test ID contract_code expected_storage
key_sstore nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
fill_stack nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
stack_overflow nonce=0 balance=0 code=b'' storage=Storage(root={0: 0})
storage_overwrite nonce=0 balance=0 code=b'' storage=Storage(root={0: 2, 1: 0})
before_jumpdest nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
gas_cost nonce=0 balance=0 code=b'' storage=Storage(root={0: 2})
key_sstore nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
fill_stack nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
stack_overflow nonce=0 balance=0 code=b'' storage=Storage(root={0: 0})
storage_overwrite nonce=0 balance=0 code=b'' storage=Storage(root={0: 2, 1: 0})
before_jumpdest nonce=0 balance=0 code=b'' storage=Storage(root={0: 1})
gas_cost nonce=0 balance=0 code=b'' storage=Storage(root={0: 2})