Skip to content

Commit 7028116

Browse files
felix314159spencer-tb
authored andcommitted
fix(fill): use fork_at(), use is_eip_enabled(eip_number=7976) to pick the correct token formula
1 parent f7e18b1 commit 7028116

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/ethereum/forks/amsterdam/transactions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,8 @@ def calculate_intrinsic_cost(
676676
# Data token floor cost for access list bytes.
677677
access_list_gas += tokens_in_access_list * GAS_TX_DATA_TOKEN_FLOOR
678678

679-
# Data token floor cost for access list bytes.
680-
access_list_cost += tokens_in_access_list * GAS_TX_DATA_TOKEN_FLOOR
681-
682-
auth_cost = Uint(0)
679+
auth_regular_gas = Uint(0)
680+
auth_state_gas = Uint(0)
683681
if isinstance(tx, SetCodeTransaction):
684682
auth_regular_gas = PER_AUTH_BASE_COST * ulen(tx.authorizations)
685683
auth_state_gas = (

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,26 @@ def test_calldata_floor_exceeding_tx_gas_limit_cap(
161161
gas_limit_cap = fork.transaction_gas_limit_cap()
162162
assert gas_limit_cap is not None
163163

164-
# calldata_floor = tokens * GAS_TX_DATA_TOKEN_FLOOR + GAS_TX_BASE
165-
# Non-zero bytes contribute 4 tokens each, zero bytes 1 token.
166-
# Exact equality with the cap is not always reachable because
167-
# the floor advances in steps of GAS_TX_DATA_TOKEN_FLOOR.
168-
# Use nonzero bytes for bulk tokens, then zero bytes (1 token
169-
# each) to get as close to the cap as possible.
170164
floor_token = gas_costs.GAS_TX_DATA_TOKEN_FLOOR
171165
tx_base = gas_costs.GAS_TX_BASE
172-
tokens_per_nonzero = 4
173-
174166
max_tokens = (gas_limit_cap - tx_base) // floor_token
175-
nonzero_bytes = max_tokens // tokens_per_nonzero
176-
zero_bytes = max_tokens - nonzero_bytes * tokens_per_nonzero
177-
178-
if exceeds_cap:
179-
zero_bytes += 1
180167

181-
calldata = b"\x01" * nonzero_bytes + b"\x00" * zero_bytes
168+
if fork.is_eip_enabled(eip_number=7976):
169+
# EIP-7976: all bytes contribute 4 floor tokens regardless of
170+
# value, so the token count is len(data) * 4.
171+
tokens_per_byte = 4
172+
max_bytes = max_tokens // tokens_per_byte
173+
if exceeds_cap:
174+
max_bytes += 1
175+
calldata = b"\x01" * max_bytes
176+
else:
177+
# EIP-7623: non-zero bytes contribute 4 tokens, zero bytes 1.
178+
tokens_per_nonzero = 4
179+
nonzero_bytes = max_tokens // tokens_per_nonzero
180+
zero_bytes = max_tokens - nonzero_bytes * tokens_per_nonzero
181+
if exceeds_cap:
182+
zero_bytes += 1
183+
calldata = b"\x01" * nonzero_bytes + b"\x00" * zero_bytes
182184
contract = pre.deploy_contract(Op.STOP)
183185

184186
tx = Transaction(

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def test_sstore_state_gas_at_transition(
5252
operation requires state gas. Both blocks use TX_MAX_GAS_LIMIT
5353
which provides enough gas in either regime.
5454
"""
55-
gas_limit_cap = fork.transaction_gas_limit_cap()
55+
after_fork = fork.fork_at(timestamp=15_000)
56+
gas_limit_cap = after_fork.transaction_gas_limit_cap()
5657
assert gas_limit_cap is not None
5758
contract_before = pre.deploy_contract(
5859
code=Op.SSTORE(0, 1),
@@ -123,7 +124,8 @@ def test_tx_gas_above_cap_at_transition(
123124
reservoir. This test sends a tx at the cap (always valid) and one
124125
above the cap (rejected before, accepted after).
125126
"""
126-
gas_limit_cap = fork.transaction_gas_limit_cap()
127+
after_fork = fork.fork_at(timestamp=15_000)
128+
gas_limit_cap = after_fork.transaction_gas_limit_cap()
127129
assert gas_limit_cap is not None
128130
storage_before = Storage()
129131
contract_before = pre.deploy_contract(
@@ -193,9 +195,10 @@ def test_reservoir_available_after_transition(
193195
no reservoir. After the fork, gas above the cap feeds the reservoir,
194196
which child calls can draw from for state operations.
195197
"""
196-
gas_limit_cap = fork.transaction_gas_limit_cap()
198+
after_fork = fork.fork_at(timestamp=15_000)
199+
gas_limit_cap = after_fork.transaction_gas_limit_cap()
197200
assert gas_limit_cap is not None
198-
sstore_state_gas = fork.sstore_state_gas()
201+
sstore_state_gas = after_fork.sstore_state_gas()
199202

200203
child_storage = Storage()
201204
child = pre.deploy_contract(

0 commit comments

Comments
 (0)