Skip to content

Commit a255109

Browse files
committed
Merge eips/amsterdam/eip-7981 into devnets/bal/4
2 parents b742d05 + 030c92e commit a255109

12 files changed

Lines changed: 1153 additions & 4 deletions

File tree

packages/testing/src/execution_testing/forks/base_fork.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ class TransactionDataFloorCostCalculator(Protocol):
6161
Calculate the transaction floor cost due to its calldata for a given fork.
6262
"""
6363

64-
def __call__(self, *, data: BytesConvertible) -> int:
64+
def __call__(
65+
self,
66+
*,
67+
data: BytesConvertible,
68+
access_list: List[AccessList] | None = None,
69+
) -> int:
6570
"""Return transaction gas cost of calldata given its contents."""
6671
pass
6772

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
EIP-7981: Increase Access List Cost.
3+
4+
Price access lists for data to reduce maximum block size.
5+
6+
https://eips.ethereum.org/EIPS/eip-7981
7+
"""
8+
9+
from typing import List, Sized
10+
11+
from execution_testing.base_types import AccessList
12+
from execution_testing.base_types.conversions import BytesConvertible
13+
14+
from ....base_fork import (
15+
BaseFork,
16+
TransactionDataFloorCostCalculator,
17+
TransactionIntrinsicCostCalculator,
18+
)
19+
20+
21+
class EIP7981(BaseFork):
22+
"""EIP-7981 class."""
23+
24+
@classmethod
25+
def _access_list_floor_tokens(
26+
cls, access_list: List[AccessList] | None
27+
) -> int:
28+
"""
29+
Return ``access_list_bytes * 4`` floor tokens for the access list.
30+
31+
Every byte of each address (20 bytes) and storage key (32 bytes)
32+
contributes four floor tokens, so zero and non-zero bytes are
33+
charged equally per EIP-7981.
34+
"""
35+
if not access_list:
36+
return 0
37+
total_bytes = 0
38+
for access in access_list:
39+
total_bytes += len(access.address)
40+
for slot in access.storage_keys:
41+
total_bytes += len(slot)
42+
return total_bytes * 4
43+
44+
@classmethod
45+
def transaction_data_floor_cost_calculator(
46+
cls,
47+
) -> TransactionDataFloorCostCalculator:
48+
"""
49+
Add access list floor tokens to the inherited calldata floor cost.
50+
"""
51+
super_fn = super(EIP7981, cls).transaction_data_floor_cost_calculator()
52+
gas_costs = cls.gas_costs()
53+
54+
def fn(
55+
*,
56+
data: BytesConvertible,
57+
access_list: List[AccessList] | None = None,
58+
) -> int:
59+
return (
60+
super_fn(data=data)
61+
+ cls._access_list_floor_tokens(access_list)
62+
* gas_costs.TX_DATA_TOKEN_FLOOR
63+
)
64+
65+
return fn
66+
67+
@classmethod
68+
def transaction_intrinsic_cost_calculator(
69+
cls,
70+
) -> TransactionIntrinsicCostCalculator:
71+
"""
72+
Charge access list data at the floor token cost on top of the
73+
inherited intrinsic cost and enforce the combined data floor.
74+
"""
75+
super_fn = super(EIP7981, cls).transaction_intrinsic_cost_calculator()
76+
gas_costs = cls.gas_costs()
77+
data_floor_cost_calculator = (
78+
cls.transaction_data_floor_cost_calculator()
79+
)
80+
81+
def fn(
82+
*,
83+
calldata: BytesConvertible = b"",
84+
contract_creation: bool = False,
85+
access_list: List[AccessList] | None = None,
86+
authorization_list_or_count: Sized | int | None = None,
87+
return_cost_deducted_prior_execution: bool = False,
88+
) -> int:
89+
intrinsic_cost: int = super_fn(
90+
calldata=calldata,
91+
contract_creation=contract_creation,
92+
access_list=access_list,
93+
authorization_list_or_count=authorization_list_or_count,
94+
return_cost_deducted_prior_execution=True,
95+
)
96+
intrinsic_cost += (
97+
cls._access_list_floor_tokens(access_list)
98+
* gas_costs.TX_DATA_TOKEN_FLOOR
99+
)
100+
101+
if return_cost_deducted_prior_execution:
102+
return intrinsic_cost
103+
104+
return max(
105+
intrinsic_cost,
106+
data_floor_cost_calculator(
107+
data=calldata, access_list=access_list
108+
),
109+
)
110+
111+
return fn

packages/testing/src/execution_testing/forks/forks/eips/prague/eip_7623.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ def transaction_data_floor_cost_calculator(
6262
calldata_gas_calculator = cls.calldata_gas_calculator()
6363
gas_costs = cls.gas_costs()
6464

65-
def fn(*, data: BytesConvertible) -> int:
65+
def fn(
66+
*,
67+
data: BytesConvertible,
68+
access_list: List[AccessList] | None = None,
69+
) -> int:
70+
del access_list
6671
return (
6772
calldata_gas_calculator(data=data, floor=True)
6873
+ gas_costs.TX_BASE

packages/testing/src/execution_testing/forks/forks/forks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,12 @@ def transaction_data_floor_cost_calculator(
812812
) -> TransactionDataFloorCostCalculator:
813813
"""At frontier, the transaction data floor cost is a constant zero."""
814814

815-
def fn(*, data: BytesConvertible) -> int:
816-
del data
815+
def fn(
816+
*,
817+
data: BytesConvertible,
818+
access_list: List[AccessList] | None = None,
819+
) -> int:
820+
del data, access_list
817821
return 0
818822

819823
return fn

src/ethereum/forks/amsterdam/transactions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030

3131
TX_MAX_GAS_LIMIT = Uint(16_777_216)
3232

33+
ACCESS_LIST_ADDRESS_FLOOR_TOKENS = Uint(80)
34+
"""
35+
Floor data tokens contributed by a single access list address per
36+
[EIP-7981].
37+
38+
[EIP-7981]: https://eips.ethereum.org/EIPS/eip-7981
39+
"""
40+
41+
ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS = Uint(128)
42+
"""
43+
Floor data tokens contributed by a single access list storage key per
44+
[EIP-7981].
45+
46+
[EIP-7981]: https://eips.ethereum.org/EIPS/eip-7981
47+
"""
48+
3349

3450
@slotted_freezable
3551
@dataclass
@@ -601,6 +617,10 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
601617
access_list_cost += (
602618
ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY
603619
)
620+
tokens_in_access_list += ACCESS_LIST_ADDRESS_FLOOR_TOKENS
621+
tokens_in_access_list += (
622+
ulen(access.slots) * ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS
623+
)
604624

605625
# Data token floor cost for access list bytes.
606626
access_list_cost += tokens_in_access_list * GasCosts.TX_DATA_TOKEN_FLOOR
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for EIP-7981: Increase Access List Cost."""

0 commit comments

Comments
 (0)