Skip to content

Test Datacopy Memory Expansion

Documentation for tests/prague/eip7692_eof_v1/eip7480_data_section/test_datacopy_memory_expansion.py.

Generate fixtures for these test cases for Prague with:

Prague only:

fill -v tests/prague/eip7692_eof_v1/eip7480_data_section/test_datacopy_memory_expansion.py --fork=Prague --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Prague:
fill -v tests/prague/eip7692_eof_v1/eip7480_data_section/test_datacopy_memory_expansion.py --until=Prague --evm-bin=/path/to/evm-tool-dev-version

Memory expansion tests for DATACOPY

test_datacopy_memory_expansion(state_test, env, pre, post, tx)

Perform DATACOPY operations that expand the memory, and verify the gas it costs to do so.

Source code in tests/prague/eip7692_eof_v1/eip7480_data_section/test_datacopy_memory_expansion.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@pytest.mark.parametrize(
    "dest,src,length",
    [
        (0x00, 0x00, 0x01),
        (0x100, 0x00, 0x01),
        (0x1F, 0x00, 0x01),
        (0x20, 0x00, 0x01),
        (0x1000, 0x00, 0x01),
        (0x1000, 0x00, 0x40),
        (0x00, 0x00, 0x00),
        (2**256 - 1, 0x00, 0x00),
        (0x00, 2**256 - 1, 0x00),
        (2**256 - 1, 2**256 - 1, 0x00),
    ],
    ids=[
        "single_byte_expansion",
        "single_byte_expansion_2",
        "single_byte_expansion_word_boundary",
        "single_byte_expansion_word_boundary_2",
        "multi_word_expansion",
        "multi_word_expansion_2",
        "zero_length_expansion",
        "huge_dest_zero_length",
        "huge_src_zero_length",
        "huge_dest_huge_src_zero_length",
    ],
)
@pytest.mark.parametrize("successful", [True, False])
@pytest.mark.parametrize(
    "initial_memory",
    [
        bytes(range(0x00, 0x100)),
        bytes(),
    ],
    ids=[
        "from_existent_memory",
        "from_empty_memory",
    ],
)
@pytest.mark.parametrize(
    "data_section",
    [
        bytes(),
        b"\xfc",
        bytes(range(0x00, 0x20)),
        bytes(range(0x00, 0x100)),
    ],
    ids=["empty_data_section", "byte_data_section", "word_data_section", "large_data_section"],
)
def test_datacopy_memory_expansion(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    post: Mapping[str, Account],
    tx: Transaction,
):
    """
    Perform DATACOPY operations that expand the memory, and verify the gas it costs to do so.
    """
    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )

test_datacopy_huge_memory_expansion(state_test, env, pre, post, tx)

Perform DATACOPY operations that expand the memory by huge amounts, and verify that it correctly runs out of gas.

Source code in tests/prague/eip7692_eof_v1/eip7480_data_section/test_datacopy_memory_expansion.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@pytest.mark.parametrize(
    "dest,src,length",
    [
        (2**256 - 1, 0x00, 0x01),
        (2**256 - 2, 0x00, 0x01),
        (2**255 - 1, 0x00, 0x01),
        (0x00, 0x00, 2**256 - 1),
        (0x00, 0x00, 2**256 - 2),
        (0x00, 0x00, 2**255 - 1),
    ],
    ids=[
        "max_dest_single_byte_expansion",
        "max_dest_minus_one_single_byte_expansion",
        "half_max_dest_single_byte_expansion",
        "max_length_expansion",
        "max_length_minus_one_expansion",
        "half_max_length_expansion",
    ],
)
@pytest.mark.parametrize(
    "subcall_exact_cost",
    [2**128 - 1],
    ids=[""],
)  # Limit subcall gas, otherwise it would be impossibly large
@pytest.mark.parametrize("successful", [False])
@pytest.mark.parametrize(
    "initial_memory",
    [
        bytes(range(0x00, 0x100)),
        bytes(),
    ],
    ids=[
        "from_existent_memory",
        "from_empty_memory",
    ],
)
@pytest.mark.parametrize(
    "data_section",
    [
        bytes(),
        b"\xfc",
        bytes(range(0x00, 0x20)),
        bytes(range(0x00, 0x100)),
    ],
    ids=["empty_data_section", "byte_data_section", "word_data_section", "large_data_section"],
)
def test_datacopy_huge_memory_expansion(
    state_test: StateTestFiller,
    env: Environment,
    pre: Mapping[str, Account],
    post: Mapping[str, Account],
    tx: Transaction,
):
    """
    Perform DATACOPY operations that expand the memory by huge amounts, and verify that it
    correctly runs out of gas.
    """
    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )