Skip to content

Commit c3a7b6b

Browse files
chfastfelix314159
andauthored
feat(tests): EIP-7976 reject exact-balance tx in Prague/Amsterdam floor gap (#2878)
* feat(tests): EIP-7976 reject in Prague/Amsterdam floor gap with exact-balance sender EIP-7976 raises the per-byte calldata floor cost. A transaction whose `gas_limit` lies in `[Prague_floor, Amsterdam_floor)` must reject at pre-validate with `INTRINSIC_GAS_BELOW_FLOOR_GAS_COST`. This test pins gas_limit at the midpoint of that gap for 100 and 1000 zero-byte calldata transactions. Sender balance equals `gas_limit * gas_price`, so an implementation that defaults to the Prague floor cannot fall through to a silent "accept and execute" — any pre-validate divergence produces a different post-state. * refactor(tests): use `valid_at` marker and improve docstring consistency --------- Co-authored-by: Felix H <felix314159@users.noreply.github.com>
1 parent bbacd74 commit c3a7b6b

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
abstract: Tests for floor-boundary rejection with exact-balance funding in [EIP-7976: Increase Calldata Floor Cost](https://eips.ethereum.org/EIPS/eip-7976).
3+
""" # noqa: E501
4+
5+
import pytest
6+
from execution_testing import (
7+
Alloc,
8+
Bytes,
9+
Fork,
10+
StateTestFiller,
11+
Transaction,
12+
TransactionException,
13+
)
14+
15+
from ...prague.eip7623_increase_calldata_cost.spec import Spec as Spec7623
16+
from .spec import ref_spec_7976
17+
18+
REFERENCE_SPEC_GIT_PATH = ref_spec_7976.git_path
19+
REFERENCE_SPEC_VERSION = ref_spec_7976.version
20+
21+
pytestmark = pytest.mark.valid_at("EIP7976")
22+
23+
24+
@pytest.mark.exception_test
25+
@pytest.mark.parametrize(
26+
"zero_bytes",
27+
[
28+
pytest.param(100, id="100_zero_bytes"),
29+
pytest.param(1000, id="1000_zero_bytes"),
30+
],
31+
)
32+
def test_below_amsterdam_floor_with_exact_balance_sender(
33+
state_test: StateTestFiller,
34+
pre: Alloc,
35+
fork: Fork,
36+
zero_bytes: int,
37+
) -> None:
38+
"""
39+
Reject when gas_limit sits between Prague and Amsterdam floor.
40+
41+
EIP-7976 raises the per-byte calldata floor cost. A transaction
42+
with `gas_limit` in `[Prague_floor, Amsterdam_floor)` must reject
43+
with `INTRINSIC_GAS_BELOW_FLOOR_GAS_COST`. The sender is funded
44+
with exactly `gas_limit * gas_price` so an implementation that
45+
uses the Prague floor cannot fall back to silent execution.
46+
47+
Type-0 only on purpose; broader type-1/2/3/4 coverage lives in
48+
`test_transaction_validity.py`.
49+
"""
50+
tx_data = Bytes(b"\x00" * zero_bytes)
51+
intrinsic_regular = fork.transaction_intrinsic_cost_calculator()(
52+
calldata=tx_data,
53+
return_cost_deducted_prior_execution=True,
54+
)
55+
amsterdam_floor = fork.transaction_data_floor_cost_calculator()(
56+
data=tx_data,
57+
)
58+
# Prague counts each zero byte as one token at TX_DATA_TOKEN_FLOOR
59+
# gas/token. Cannot be derived from amsterdam_floor because EIP-7976
60+
# changes both the per-token rate (10->16) and the floor tokenization
61+
# (zero/nonzero both weighted by 4).
62+
prague_floor = 21000 + Spec7623.TX_DATA_TOKEN_FLOOR * zero_bytes
63+
gas_limit = (prague_floor + amsterdam_floor) // 2
64+
assert intrinsic_regular <= gas_limit
65+
assert prague_floor <= gas_limit < amsterdam_floor
66+
67+
gas_price = 10
68+
sender = pre.fund_eoa(amount=gas_limit * gas_price)
69+
tx = Transaction(
70+
sender=sender,
71+
to=pre.fund_eoa(amount=0),
72+
data=tx_data,
73+
gas_limit=gas_limit,
74+
gas_price=gas_price,
75+
error=TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
76+
)
77+
78+
state_test(pre=pre, post={}, tx=tx)

0 commit comments

Comments
 (0)