Skip to content

test_create_with_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_with_reservoir@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_with_reservoir --fork Amsterdam

Test CREATE/CREATE2 with state gas funded from the reservoir.

The factory is forwarded only the execution gas it needs, so the new-account charge can only come from the reservoir riding along. One gas short of that grant the factory halts instead.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
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
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
@pytest.mark.with_all_create_opcodes
@pytest.mark.parametrize(
    "gas_delta",
    [pytest.param(0, id="exact_fit"), pytest.param(-1, id="one_short")],
)
@pytest.mark.valid_from("EIP8037")
def test_create_with_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    create_opcode: Op,
    gas_delta: int,
    fork: Fork,
) -> None:
    """
    Test CREATE/CREATE2 with state gas funded from the reservoir.

    The factory is forwarded only the execution gas it needs, so the
    new-account charge can only come from the reservoir riding along.
    One gas short of that grant the factory halts instead.
    """
    init_code = Op.STOP
    mstore_value, size = init_code_at_high_bytes(init_code)

    create_call = create_opcode(
        value=0, offset=0, size=size, init_code_size=size
    )

    factory_code = Op.MSTORE(0, mstore_value, new_memory_size=32) + Op.POP(
        create_call
    )
    factory = pre.deploy_contract(code=factory_code)

    storage = Storage()
    contract = pre.deploy_contract(
        code=Op.SSTORE(
            storage.store_next(1 if gas_delta == 0 else 0, "create_succeeded"),
            Op.CALL(
                gas=factory_code.execution_cost(fork),
                address=factory,
            ),
        ),
        storage=storage.canary(),
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=factory_code.state_cost(fork) + gas_delta,
        sender=pre.fund_eoa(),
    )

    created = compute_create_address(
        address=factory,
        nonce=1,
        salt=0,
        initcode=init_code,
        opcode=create_opcode,
    )

    post = {
        contract: Account(storage=storage),
        created: Account(nonce=1, code=b"")
        if gas_delta == 0
        else Account.NONEXISTENT,
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.