Skip to content

test_worst_codecopy()

Documentation for tests/benchmark/test_worst_memory.py::test_worst_codecopy@0f7c73a7.

Generate fixtures for these test cases for Prague with:

fill -v tests/benchmark/test_worst_memory.py::test_worst_codecopy --fork Prague

Test running a block filled with CODECOPY executions.

Source code in tests/benchmark/test_worst_memory.py
132
133
134
135
136
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@pytest.mark.valid_from("Cancun")
@pytest.mark.parametrize(
    "max_code_size_ratio",
    [
        pytest.param(0, id="0 bytes"),
        pytest.param(0.25, id="0.25x max code size"),
        pytest.param(0.50, id="0.50x max code size"),
        pytest.param(0.75, id="0.75x max code size"),
        pytest.param(1.00, id="max code size"),
    ],
)
@pytest.mark.parametrize(
    "fixed_src_dst",
    [
        True,
        False,
    ],
)
def test_worst_codecopy(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    max_code_size_ratio: float,
    fixed_src_dst: bool,
):
    """Test running a block filled with CODECOPY executions."""
    env = Environment()
    max_code_size = fork.max_code_size()

    size = int(max_code_size * max_code_size_ratio)

    code_prefix = Op.PUSH32(size)
    src_dst = 0 if fixed_src_dst else Op.MOD(Op.GAS, 7)
    attack_block = Op.CODECOPY(src_dst, src_dst, Op.DUP1)  # DUP1 copies size.
    code = code_loop_precompile_call(code_prefix, attack_block, fork)

    # The code generated above is not guaranteed to be of max_code_size, so we pad it since
    # a test parameter targets CODECOPYing a contract with max code size. Padded bytecode values
    # are not relevant.
    code = code + Op.INVALID * (max_code_size - len(code))
    assert len(code) == max_code_size, (
        f"Code size {len(code)} is not equal to max code size {max_code_size}."
    )

    tx = Transaction(
        to=pre.deploy_contract(code=code),
        gas_limit=env.gas_limit,
        sender=pre.fund_eoa(),
    )

    state_test(
        genesis_environment=env,
        pre=pre,
        post={},
        tx=tx,
    )

Parametrized Test Cases

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

Test ID (Abbreviated) fixed_src_dst max_code_size_ratio
...fork_Cancun-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Cancun-state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Cancun-state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Cancun-state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Cancun-state_test-fixed_src_dst_True-max code size True 1.0
...fork_Cancun-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Cancun-state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Cancun-state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Cancun-state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Cancun-state_test-fixed_src_dst_False-max code size False 1.0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_True-max code size True 1.0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Cancun-blockchain_test_from_state_test-fixed_src_dst_False-max code size False 1.0
...fork_Prague-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Prague-state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Prague-state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Prague-state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Prague-state_test-fixed_src_dst_True-max code size True 1.0
...fork_Prague-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Prague-state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Prague-state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Prague-state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Prague-state_test-fixed_src_dst_False-max code size False 1.0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_True-max code size True 1.0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Prague-blockchain_test_from_state_test-fixed_src_dst_False-max code size False 1.0
...fork_Osaka-state_test-fixed_src_dst_True-0 bytes True 0
...fork_Osaka-state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Osaka-state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Osaka-state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Osaka-state_test-fixed_src_dst_True-max code size True 1.0
...fork_Osaka-state_test-fixed_src_dst_False-0 bytes False 0
...fork_Osaka-state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Osaka-state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Osaka-state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Osaka-state_test-fixed_src_dst_False-max code size False 1.0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-0 bytes True 0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-0.25x max code size True 0.25
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-0.50x max code size True 0.5
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-0.75x max code size True 0.75
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_True-max code size True 1.0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-0 bytes False 0
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-0.25x max code size False 0.25
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-0.50x max code size False 0.5
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-0.75x max code size False 0.75
...fork_Osaka-blockchain_test_from_state_test-fixed_src_dst_False-max code size False 1.0