Skip to content

Commit 8ccd21f

Browse files
authored
feat(tests): EIP-8037 CREATE-tx collision refunds state-gas reservoir (#2875)
1 parent 5f132e7 commit 8ccd21f

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,66 @@ def test_create_tx_collision_refunds_intrinsic_new_account(
19331933
)
19341934

19351935

1936+
@pytest.mark.pre_alloc_mutable()
1937+
@pytest.mark.execute(pytest.mark.skip(reason="Requires specific gas price"))
1938+
@pytest.mark.valid_from("EIP8037")
1939+
def test_create_tx_collision_refunds_reservoir(
1940+
blockchain_test: BlockchainTestFiller,
1941+
pre: Alloc,
1942+
fork: Fork,
1943+
) -> None:
1944+
"""
1945+
Verify the state-gas reservoir is refunded on a depth-0 CREATE-tx
1946+
address collision when `gas_limit > TX_MAX_GAS_LIMIT`.
1947+
1948+
EIP-8037 splits `gas_limit` into the capped regular budget and a
1949+
state-gas reservoir. On collision the inner regular gas is burnt
1950+
and `intrinsic_state_gas` is refunded; the reservoir must also
1951+
be refunded to the sender. `header.gas_used` is fixed at the
1952+
regular cap regardless of reservoir handling, so the sender's
1953+
post-balance is the primary discriminating assertion.
1954+
"""
1955+
gas_limit_cap = fork.transaction_gas_limit_cap()
1956+
assert gas_limit_cap is not None
1957+
1958+
init_code = Op.STOP
1959+
# +1 above intrinsic_state_gas (= create_state_gas(code_size=0)
1960+
# for empty-code CREATE-tx) makes message.state_gas_reservoir > 0.
1961+
reservoir = fork.create_state_gas(code_size=0) + 1
1962+
gas_limit = gas_limit_cap + reservoir
1963+
initial_fund = 10**18
1964+
1965+
sender = pre.fund_eoa(initial_fund)
1966+
collision_target = compute_create_address(address=sender, nonce=0)
1967+
pre[collision_target] = Account(nonce=1)
1968+
1969+
tx_gas_price = 7
1970+
tx = Transaction(
1971+
to=None,
1972+
data=init_code,
1973+
gas_limit=gas_limit,
1974+
sender=sender,
1975+
gas_price=tx_gas_price,
1976+
)
1977+
1978+
blockchain_test(
1979+
pre=pre,
1980+
blocks=[
1981+
Block(
1982+
txs=[tx],
1983+
header_verify=Header(gas_used=gas_limit_cap),
1984+
),
1985+
],
1986+
post={
1987+
sender: Account(
1988+
balance=initial_fund - gas_limit_cap * tx_gas_price,
1989+
nonce=1,
1990+
),
1991+
collision_target: Account(nonce=1, code=b"", storage={}),
1992+
},
1993+
)
1994+
1995+
19361996
@pytest.mark.parametrize(
19371997
"initcode_size_delta",
19381998
[

0 commit comments

Comments
 (0)