Skip to content

Test Mcopy Memory Expansion

Documentation for tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py.

Generate fixtures for these test cases for Cancun with:

Cancun only:

fill -v tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py --fork=Cancun --evm-bin=/path/to/evm-tool-dev-version
For all forks up to and including Cancun:
fill -v tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py --until=Cancun --evm-bin=/path/to/evm-tool-dev-version

abstract: Tests EIP-5656: MCOPY - Memory copying instruction

Test copy operations of [EIP-5656: MCOPY - Memory copying instruction](https://eips.ethereum.org/EIPS/eip-5656)
that produce a memory expansion, and potentially an out-of-gas error.

test_mcopy_memory_expansion(state_test, pre, post, tx)

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

Source code in tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py
165
166
167
168
169
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
@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.valid_from("Cancun")
def test_mcopy_memory_expansion(
    state_test: StateTestFiller,
    pre: Mapping[str, Account],
    post: Mapping[str, Account],
    tx: Transaction,
):
    """
    Perform MCOPY operations that expand the memory, and verify the gas it costs to do so.
    """
    state_test(
        env=Environment(),
        pre=pre,
        post=post,
        txs=[tx],
    )

test_mcopy_huge_memory_expansion(state_test, pre, post, tx)

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

Source code in tests/cancun/eip5656_mcopy/test_mcopy_memory_expansion.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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
@pytest.mark.parametrize(
    "dest,src,length",
    [
        (2**256 - 1, 0x00, 0x01),
        (2**256 - 2, 0x00, 0x01),
        (2**255 - 1, 0x00, 0x01),
        (0x00, 2**256 - 1, 0x01),
        (0x00, 2**256 - 2, 0x01),
        (0x00, 2**255 - 1, 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_src_single_byte_expansion",
        "max_src_minus_one_single_byte_expansion",
        "half_max_src_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.valid_from("Cancun")
def test_mcopy_huge_memory_expansion(
    state_test: StateTestFiller,
    pre: Mapping[str, Account],
    post: Mapping[str, Account],
    tx: Transaction,
):
    """
    Perform MCOPY operations that expand the memory by huge amounts, and verify that it correctly
    runs out of gas.
    """
    state_test(
        env=Environment(),
        pre=pre,
        post=post,
        txs=[tx],
    )