Skip to content

Commit a519d24

Browse files
committed
feat(spec-specs, tests): EIP-8037 - apply calldata floor to sender refund (#2728)
1 parent 80ddcb3 commit a519d24

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/ethereum/forks/amsterdam/fork.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,9 @@ def process_transaction(
11121112

11131113
# Transactions with less execution_gas_used than the floor pay at the
11141114
# floor cost.
1115-
tx_gas_used = max(tx_gas_used_after_refund, intrinsic.calldata_floor)
1115+
tx_gas_used_after_refund = max(
1116+
tx_gas_used_after_refund, intrinsic.calldata_floor
1117+
)
11161118

11171119
tx_gas_left = tx.gas - tx_gas_used_after_refund
11181120
gas_refund_amount = tx_gas_left * effective_gas_price
@@ -1148,7 +1150,7 @@ def process_transaction(
11481150
block_output.block_state_gas_used += tx_state_gas
11491151
block_output.blob_gas_used += tx_blob_gas_used
11501152

1151-
block_output.cumulative_gas_used += tx_gas_used
1153+
block_output.cumulative_gas_used += tx_gas_used_after_refund
11521154
receipt = make_receipt(
11531155
tx, tx_output.error, block_output.cumulative_gas_used, tx_output.logs
11541156
)

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from execution_testing import (
1515
Account,
1616
Alloc,
17+
Block,
18+
BlockchainTestFiller,
1719
Environment,
1820
Fork,
1921
Op,
@@ -195,3 +197,44 @@ def test_calldata_floor_exceeding_tx_gas_limit_cap(
195197

196198
post = {contract: Account(code=Op.STOP)} if not exceeds_cap else {}
197199
state_test(pre=pre, post=post, tx=tx)
200+
201+
202+
@pytest.mark.valid_from("EIP8037")
203+
def test_calldata_floor_applied_to_sender_refund(
204+
blockchain_test: BlockchainTestFiller,
205+
pre: Alloc,
206+
fork: Fork,
207+
) -> None:
208+
"""
209+
Verify the calldata floor is applied to the sender gas refund.
210+
211+
With a STOP callee and large all-nonzero calldata, execution gas
212+
falls below the calldata floor. The sender must be charged
213+
`calldata_floor * gas_price`, so the final balance reflects the
214+
floor-applied value, not the pre-floor execution cost.
215+
"""
216+
gas_limit_cap = fork.transaction_gas_limit_cap()
217+
assert gas_limit_cap is not None
218+
calldata = b"\xff" * 1024
219+
calldata_floor = fork.transaction_intrinsic_cost_calculator()(
220+
calldata=calldata,
221+
)
222+
gas_price = 10**9
223+
initial = gas_limit_cap * gas_price
224+
225+
contract = pre.deploy_contract(code=Op.STOP)
226+
sender = pre.fund_eoa(amount=initial)
227+
228+
tx = Transaction(
229+
to=contract,
230+
data=calldata,
231+
gas_limit=gas_limit_cap,
232+
gas_price=gas_price,
233+
sender=sender,
234+
)
235+
236+
blockchain_test(
237+
pre=pre,
238+
blocks=[Block(txs=[tx])],
239+
post={sender: Account(balance=initial - calldata_floor * gas_price)},
240+
)

0 commit comments

Comments
 (0)