Skip to content

Commit 852715c

Browse files
felix314159nerolationmarioevzspencer-tb
authored
feat(spec-specs, tests): Add EIP-7976 Increase Calldata Floor Cost (#2861)
* feat(tests): adds EIP-7976 test and required framework changes (#2115) * feat(tests): adds tests and src changes for 7976 Co-authored-by: Toni Wahrstätter <51536394+nerolation@users.noreply.github.com> * feat: EIP got updated * fix: ruff * feat: implemented PR feedback * fix: make eip-7934 block-size filler fork-aware for amsterdam by enforcing tx gas caps and adaptive calldata sizing so --until=amsterdam fills pass * fix: fix * fix: fix * fix: mypy --------- Co-authored-by: Toni Wahrstätter <51536394+nerolation@users.noreply.github.com> * refactor(tests-eip-7976): Condition tests to EIP inclusion * chores: update refspec * fix(tests): drop GAS_ prefix from gas_costs attribute references Align the EIP-7976 mixin and tests with the GasCosts dataclass rename on forks/amsterdam (GAS_TX_BASE -> TX_BASE, GAS_TX_DATA_TOKEN_FLOOR -> TX_DATA_TOKEN_FLOOR, GAS_VERY_LOW -> VERY_LOW, etc.). * fix(tests): compose EIP-7976 floor cost via calldata_gas_calculator Override `calldata_gas_calculator` (floor mode only) instead of `transaction_data_floor_cost_calculator`. The previous override shadowed EIP-7981's `transaction_data_floor_cost_calculator` in the Amsterdam MRO (auto-loader sorts by EIP number ascending, so EIP7976 is more derived and its method wins without calling super), dropping the access list floor contribution. Routing the change through `calldata_gas_calculator` lets EIP-7623's data floor calculator pick it up, which EIP-7981 then extends via super. * fix: ci fails due to static tests out of gas * fix: mario feedback * fix: remove duplicate test --------- Co-authored-by: Toni Wahrstätter <51536394+nerolation@users.noreply.github.com> Co-authored-by: marioevz <marioevz@gmail.com> Co-authored-by: spencer-tb <spencer.tb@ethereum.org>
1 parent b7a2066 commit 852715c

15 files changed

Lines changed: 2446 additions & 9 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
EIP-7976: Increase Calldata Floor Cost.
3+
4+
Increase the calldata floor cost to 64/64 gas per byte to reduce maximum block
5+
size.
6+
7+
https://eips.ethereum.org/EIPS/eip-7976
8+
"""
9+
10+
from dataclasses import replace
11+
12+
from execution_testing.base_types import Bytes
13+
from execution_testing.base_types.conversions import BytesConvertible
14+
15+
from ....base_fork import BaseFork, CalldataGasCalculator
16+
from ....gas_costs import GasCosts
17+
18+
19+
class EIP7976(BaseFork):
20+
"""EIP-7976 class."""
21+
22+
@classmethod
23+
def gas_costs(cls) -> GasCosts:
24+
"""Transaction data floor token cost is increased from 10 to 16."""
25+
return replace(
26+
super(EIP7976, cls).gas_costs(),
27+
TX_DATA_TOKEN_FLOOR=16,
28+
)
29+
30+
@classmethod
31+
def calldata_gas_calculator(cls) -> CalldataGasCalculator:
32+
"""
33+
In floor mode, count four tokens per calldata byte uniformly so
34+
the data floor cost becomes ``4 * bytes * TX_DATA_TOKEN_FLOOR``
35+
(64/64 gas per byte). Standard mode keeps EIP-7623 semantics so
36+
that composition with downstream EIPs (e.g. EIP-7981) stays
37+
intact via ``super().transaction_data_floor_cost_calculator()``.
38+
"""
39+
super_fn = super(EIP7976, cls).calldata_gas_calculator()
40+
gas_costs = cls.gas_costs()
41+
42+
def fn(*, data: BytesConvertible, floor: bool = False) -> int:
43+
if floor:
44+
return len(Bytes(data)) * 4 * gas_costs.TX_DATA_TOKEN_FLOOR
45+
return super_fn(data=data, floor=False)
46+
47+
return fn

src/ethereum/forks/amsterdam/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
611611
GasCosts.AUTH_PER_EMPTY_ACCOUNT * len(tx.authorizations)
612612
)
613613

614-
# Floor tokens from calldata.
615-
floor_tokens_in_calldata = tokens_in_calldata
614+
# EIP-7976 floor tokens: all calldata bytes count uniformly.
615+
floor_tokens_in_calldata = ulen(tx.data) * GasCosts.TX_DATA_TOKEN_STANDARD
616616

617617
# Total floor tokens.
618618
total_floor_tokens = floor_tokens_in_calldata + tokens_in_access_list

src/ethereum/forks/amsterdam/vm/gas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class GasCosts:
106106
TX_BASE = Uint(21000)
107107
TX_CREATE = Uint(32000)
108108
TX_DATA_TOKEN_STANDARD = Uint(4)
109-
TX_DATA_TOKEN_FLOOR = Uint(10)
109+
TX_DATA_TOKEN_FLOOR = Uint(16)
110110
TX_ACCESS_LIST_ADDRESS = Uint(2400)
111111
TX_ACCESS_LIST_STORAGE_KEY = Uint(1900)
112112

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Test [EIP-7976: Increase calldata floor cost](https://eips.ethereum.org/EIPS/eip-7976).
3+
"""

0 commit comments

Comments
 (0)