Skip to content

Test Push0

Documentation for tests/shanghai/eip3855_push0/test_push0.py.

Generate fixtures for these test cases with:

fill -v tests/shanghai/eip3855_push0/test_push0.py

abstract: Tests EIP-3855: PUSH0 Instruction

Tests for [EIP-3855: PUSH0 Instruction](https://eips.ethereum.org/EIPS/eip-3855).

note: Tests ported from:

- [ethereum/tests/pull/1033](https://github.com/ethereum/tests/pull/1033).

test_push0_key_sstore(state_test, env, pre, post, tx, addr_1)

Use PUSH0 to set a key for SSTORE.

Source code in tests/shanghai/eip3855_push0/test_push0.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def test_push0_key_sstore(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Use PUSH0 to set a key for SSTORE.
    """
    code = Op.SSTORE(Op.PUSH0, 1)

    pre[addr_1] = Account(code=code)
    post[addr_1] = Account(storage={0x00: 0x01})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="key_sstore")

test_push0_fill_stack(state_test, env, pre, post, tx, addr_1)

Fill stack with PUSH0, then OR all values and save using SSTORE.

Source code in tests/shanghai/eip3855_push0/test_push0.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def test_push0_fill_stack(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Fill stack with PUSH0, then OR all values and save using SSTORE.
    """
    code = Op.PUSH0 * 1024
    code += Op.OR * 1023
    code += Op.SSTORE(Op.SWAP1, 1)

    pre[addr_1] = Account(code=code)
    post[addr_1] = Account(storage={0x00: 0x01})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="fill_stack")

test_push0_stack_overflow(state_test, env, pre, post, tx, addr_1)

Stack overflow by using PUSH0 1025 times.

Source code in tests/shanghai/eip3855_push0/test_push0.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def test_push0_stack_overflow(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Stack overflow by using PUSH0 1025 times.
    """
    code = Op.SSTORE(Op.PUSH0, 1)
    code += Op.PUSH0 * 1025

    pre[addr_1] = Account(code=code)
    post[addr_1] = Account(storage={0x00: 0x00})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="stack_overflow")

test_push0_storage_overwrite(state_test, env, pre, post, tx, addr_1)

Update an already existing storage value.

Source code in tests/shanghai/eip3855_push0/test_push0.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def test_push0_storage_overwrite(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Update an already existing storage value.
    """
    code = Op.SSTORE(Op.PUSH0, 2) + Op.SSTORE(1, Op.PUSH0)

    pre[addr_1] = Account(code=code, storage={0x00: 0x0A, 0x01: 0x0A})
    post[addr_1] = Account(storage={0x00: 0x02, 0x01: 0x00})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="storage_overwrite")

test_push0_during_staticcall(state_test, env, pre, post, tx, addr_1)

Test PUSH0 during STATICCALL.

Source code in tests/shanghai/eip3855_push0/test_push0.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def test_push0_during_staticcall(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Test PUSH0 during STATICCALL.
    """
    addr_2 = to_address(0x200)

    code_1 = (
        Op.SSTORE(0, Op.STATICCALL(100000, 0x200, 0, 0, 0, 0))
        + Op.SSTORE(0, 1)
        + Op.RETURNDATACOPY(0x1F, 0, 1)
        + Op.SSTORE(1, Op.MLOAD(0))
    )
    code_2 = Op.MSTORE8(Op.PUSH0, 0xFF) + Op.RETURN(Op.PUSH0, 1)

    pre[addr_1] = Account(code=code_1)
    pre[addr_2] = Account(code=code_2)
    post[addr_1] = Account(storage={0x00: 0x01, 0x01: 0xFF})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="during_staticcall")

test_push0_before_jumpdest(state_test, env, pre, post, tx, addr_1)

Jump to a JUMPDEST next to a PUSH0, must succeed.

Source code in tests/shanghai/eip3855_push0/test_push0.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def test_push0_before_jumpdest(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Jump to a JUMPDEST next to a PUSH0, must succeed.
    """
    code = Op.PUSH1(4) + Op.JUMP + Op.PUSH0 + Op.JUMPDEST + Op.SSTORE(Op.PUSH0, 1) + Op.STOP

    pre[addr_1] = Account(code=code)
    post[addr_1] = Account(storage={0x00: 0x01})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="before_jumpdest")

test_push0_gas_cost(state_test, env, pre, post, tx, addr_1)

Test PUSH0 gas cost.

Source code in tests/shanghai/eip3855_push0/test_push0.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def test_push0_gas_cost(
    state_test: StateTestFiller,
    env: Environment,
    pre: dict,
    post: dict,
    tx: Transaction,
    addr_1: str,
):
    """
    Test PUSH0 gas cost.
    """
    code = CodeGasMeasure(
        code=Op.PUSH0,
        extra_stack_items=1,
    )

    pre[addr_1] = Account(code=code)
    post[addr_1] = Account(storage={0x00: 0x02})

    state_test(env=env, pre=pre, post=post, txs=[tx], tag="gas_cost")