Skip to content

test_eofcreate_memory()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_memory.py::test_eofcreate_memory@83970623.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_memory.py::test_eofcreate_memory --fork Osaka

Tests auxdata sizes in EOFCREATE including multiple offset conditions.

EOFCREATE either succeeds or fails based on memory access cost, resulting in new address or zero in the create address slot.

The name id of *-mem-cost refers to the bit-length of the result of the calculated memory expansion cost. Their length choice is designed to cause problems on shorter bit-length representations with native integers.

The offset_field param indicates what part of the input data arguments are being tested, either the offset of the data in memory or the size of the data in memory.

The test_arg param is the value passed into the field being tested (offset or size), intending to trigger integer size bugs for that particular field.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_memory.py
 27
 28
 29
 30
 31
 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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@pytest.mark.parametrize(
    "offset_field",
    [
        pytest.param(True, id="offset"),
        pytest.param(False, id="size"),
    ],
)
@pytest.mark.parametrize(
    ("test_arg", "success"),
    [
        pytest.param(0, True, id="zero"),
        pytest.param(0xFF, True, id="8-bit"),
        pytest.param(0x100, True, id="9-bit"),
        pytest.param(0xFFFF, True, id="16-bit"),
        pytest.param(0x10000, True, id="17-bit"),
        pytest.param(0x1FFFF20, False, id="32-bit-mem-cost"),
        pytest.param(0x2D412E0, False, id="33-bit-mem-cost"),
        pytest.param(0xFFFFFFFF, False, id="32-bit"),
        pytest.param(0x100000000, False, id="33-bit"),
        pytest.param(0x1FFFFFFFF20, False, id="64-bit-mem-cost"),
        pytest.param(0x2D413CCCF00, False, id="65-bit-mem-cost"),
        pytest.param(0xFFFFFFFFFFFFFFFF, False, id="64-bit"),
        pytest.param(0x10000000000000000, False, id="65-bit"),
        pytest.param(0xFFFFFFFFFFFFFFFF, False, id="128-bit"),
        pytest.param(0x10000000000000000, False, id="129-bit"),
        pytest.param(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, False, id="256-bit"),
    ],
)
def test_eofcreate_memory(
    state_test: StateTestFiller,
    pre: Alloc,
    offset_field: str,
    test_arg: int,
    success: bool,
):
    """
    Tests auxdata sizes in EOFCREATE including multiple offset conditions.

    EOFCREATE either succeeds or fails based on memory access cost, resulting in new address
    or zero in the create address slot.

    The name id of `*-mem-cost` refers to the bit-length of the result of the calculated memory
    expansion cost. Their length choice is designed to cause problems on shorter bit-length
    representations with native integers.

    The `offset_field` param indicates what part of the input data arguments are being tested,
    either the offset of the data in memory or the size of the data in memory.

    The `test_arg` param is the value passed into the field being tested (offset or size),
    intending to trigger integer size bugs for that particular field.
    """
    env = Environment()

    sender = pre.fund_eoa(10**27)

    initial_storage = Storage(
        {
            slot_create_address: value_canary_to_be_overwritten,  # type: ignore
            slot_code_worked: value_canary_to_be_overwritten,  # type: ignore
        }
    )
    calling_contract_address = pre.deploy_contract(
        code=Container(
            sections=[
                Section.Code(
                    code=Op.SSTORE(
                        slot_create_address,
                        Op.EOFCREATE[0](
                            value=0,
                            salt=0,
                            input_offset=test_arg if offset_field else 32,
                            input_size=32 if offset_field else test_arg,
                        ),
                    )
                    + Op.SSTORE(slot_code_worked, value_code_worked)
                    + Op.STOP,
                ),
                Section.Container(container=smallest_initcode_subcontainer),
            ]
        ),
        storage=initial_storage,
    )
    destination_contract_address = compute_eofcreate_address(
        calling_contract_address, 0, smallest_initcode_subcontainer
    )

    post = {
        calling_contract_address: Account(
            storage={
                slot_create_address: destination_contract_address,
                slot_code_worked: value_code_worked,
            }
            if success
            else initial_storage,
        ),
        destination_contract_address: Account(code=smallest_runtime_subcontainer)
        if success
        else Account.NONEXISTENT,
    }

    tx = Transaction(sender=sender, to=calling_contract_address, gas_limit=2_000_000_000)

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

Parametrized Test Cases

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

Test ID (Abbreviated) test_arg success offset_field
...fork_Osaka-blockchain_test-zero-offset 0 True True
...fork_Osaka-blockchain_test-zero-size 0 True False
...fork_Osaka-blockchain_test-8-bit-offset 255 True True
...fork_Osaka-blockchain_test-8-bit-size 255 True False
...fork_Osaka-blockchain_test-9-bit-offset 256 True True
...fork_Osaka-blockchain_test-9-bit-size 256 True False
...fork_Osaka-blockchain_test-16-bit-offset 65535 True True
...fork_Osaka-blockchain_test-16-bit-size 65535 True False
...fork_Osaka-blockchain_test-17-bit-offset 65536 True True
...fork_Osaka-blockchain_test-17-bit-size 65536 True False
...fork_Osaka-blockchain_test-32-bit-mem-cost-offset 33554208 False True
...fork_Osaka-blockchain_test-32-bit-mem-cost-size 33554208 False False
...fork_Osaka-blockchain_test-33-bit-mem-cost-offset 47452896 False True
...fork_Osaka-blockchain_test-33-bit-mem-cost-size 47452896 False False
...fork_Osaka-blockchain_test-32-bit-offset 4294967295 False True
...fork_Osaka-blockchain_test-32-bit-size 4294967295 False False
...fork_Osaka-blockchain_test-33-bit-offset 4294967296 False True
...fork_Osaka-blockchain_test-33-bit-size 4294967296 False False
...fork_Osaka-blockchain_test-64-bit-mem-cost-offset 2199023255328 False True
...fork_Osaka-blockchain_test-64-bit-mem-cost-size 2199023255328 False False
...fork_Osaka-blockchain_test-65-bit-mem-cost-offset 3109888511744 False True
...fork_Osaka-blockchain_test-65-bit-mem-cost-size 3109888511744 False False
...fork_Osaka-blockchain_test-64-bit-offset 18446744073709551615 False True
...fork_Osaka-blockchain_test-64-bit-size 18446744073709551615 False False
...fork_Osaka-blockchain_test-65-bit-offset 18446744073709551616 False True
...fork_Osaka-blockchain_test-65-bit-size 18446744073709551616 False False
...fork_Osaka-blockchain_test-128-bit-offset 18446744073709551615 False True
...fork_Osaka-blockchain_test-128-bit-size 18446744073709551615 False False
...fork_Osaka-blockchain_test-129-bit-offset 18446744073709551616 False True
...fork_Osaka-blockchain_test-129-bit-size 18446744073709551616 False False
...fork_Osaka-blockchain_test-256-bit-offset 340282366920938463463374607431768211455 False True
...fork_Osaka-blockchain_test-256-bit-size 340282366920938463463374607431768211455 False False
...fork_Osaka-state_test-zero-offset 0 True True
...fork_Osaka-state_test-zero-size 0 True False
...fork_Osaka-state_test-8-bit-offset 255 True True
...fork_Osaka-state_test-8-bit-size 255 True False
...fork_Osaka-state_test-9-bit-offset 256 True True
...fork_Osaka-state_test-9-bit-size 256 True False
...fork_Osaka-state_test-16-bit-offset 65535 True True
...fork_Osaka-state_test-16-bit-size 65535 True False
...fork_Osaka-state_test-17-bit-offset 65536 True True
...fork_Osaka-state_test-17-bit-size 65536 True False
...fork_Osaka-state_test-32-bit-mem-cost-offset 33554208 False True
...fork_Osaka-state_test-32-bit-mem-cost-size 33554208 False False
...fork_Osaka-state_test-33-bit-mem-cost-offset 47452896 False True
...fork_Osaka-state_test-33-bit-mem-cost-size 47452896 False False
...fork_Osaka-state_test-32-bit-offset 4294967295 False True
...fork_Osaka-state_test-32-bit-size 4294967295 False False
...fork_Osaka-state_test-33-bit-offset 4294967296 False True
...fork_Osaka-state_test-33-bit-size 4294967296 False False
...fork_Osaka-state_test-64-bit-mem-cost-offset 2199023255328 False True
...fork_Osaka-state_test-64-bit-mem-cost-size 2199023255328 False False
...fork_Osaka-state_test-65-bit-mem-cost-offset 3109888511744 False True
...fork_Osaka-state_test-65-bit-mem-cost-size 3109888511744 False False
...fork_Osaka-state_test-64-bit-offset 18446744073709551615 False True
...fork_Osaka-state_test-64-bit-size 18446744073709551615 False False
...fork_Osaka-state_test-65-bit-offset 18446744073709551616 False True
...fork_Osaka-state_test-65-bit-size 18446744073709551616 False False
...fork_Osaka-state_test-128-bit-offset 18446744073709551615 False True
...fork_Osaka-state_test-128-bit-size 18446744073709551615 False False
...fork_Osaka-state_test-129-bit-offset 18446744073709551616 False True
...fork_Osaka-state_test-129-bit-size 18446744073709551616 False False
...fork_Osaka-state_test-256-bit-offset 340282366920938463463374607431768211455 False True
...fork_Osaka-state_test-256-bit-size 340282366920938463463374607431768211455 False False