Reject a transaction whose calldata floor exceeds the cap, isolating
the cap check from the sufficiency check.
EIP-8037 caps max(intrinsic_regular, calldata_floor) at
TX_MAX_GAS_LIMIT. When the EIP-7976 calldata floor crosses the cap
the transaction must be rejected even though the regular intrinsic gas
is within the cap. For the rejection case gas_limit is set above the
floor so the sufficiency check max(intrinsic_total, floor) <= tx.gas
passes and the cap is the only reason for rejection — the exact shape a
client with the sufficiency gate but no cap gate would wrongly execute.
at_cap: tightest calldata floor that fits within the cap —
transaction accepted.
exceeds_cap: one byte more tips the floor over the cap —
transaction rejected.
Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 | @pytest.mark.parametrize(
"exceeds_cap",
[
pytest.param(False, id="at_cap"),
pytest.param(True, id="exceeds_cap", marks=pytest.mark.exception_test),
],
)
@pytest.mark.valid_from("EIP8037")
def test_calldata_floor_exceeding_tx_gas_limit_cap(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
exceeds_cap: bool,
) -> None:
"""
Reject a transaction whose calldata floor exceeds the cap, isolating
the cap check from the sufficiency check.
EIP-8037 caps ``max(intrinsic_regular, calldata_floor)`` at
``TX_MAX_GAS_LIMIT``. When the EIP-7976 calldata floor crosses the cap
the transaction must be rejected even though the regular intrinsic gas
is within the cap. For the rejection case ``gas_limit`` is set above the
floor so the sufficiency check ``max(intrinsic_total, floor) <= tx.gas``
passes and the cap is the only reason for rejection — the exact shape a
client with the sufficiency gate but no cap gate would wrongly execute.
at_cap: tightest calldata floor that fits within the cap —
transaction accepted.
exceeds_cap: one byte more tips the floor over the cap —
transaction rejected.
"""
gas_costs = fork.gas_costs()
cap = fork.transaction_gas_limit_cap()
assert cap is not None
floor_cost = fork.transaction_data_floor_cost_calculator()
floor_token = gas_costs.TX_DATA_TOKEN_FLOOR
# EIP-2780 anchors the floor on the decomposed intrinsic base; the tx
# targets a contract, so the base includes the recipient-access charge.
floor_base = gas_costs.TX_BASE + gas_costs.COLD_ACCOUNT_ACCESS
max_tokens = (cap - floor_base) // floor_token
if fork.is_eip_enabled(7976):
# EIP-7976: all bytes contribute 4 floor tokens regardless of
# value, so the token count is len(data) * 4.
tokens_per_byte = 4
max_bytes = max_tokens // tokens_per_byte
if exceeds_cap:
max_bytes += 1
calldata = b"\x01" * max_bytes
else:
# EIP-7623: non-zero bytes contribute 4 tokens, zero bytes 1.
tokens_per_nonzero = 4
nonzero_bytes = max_tokens // tokens_per_nonzero
zero_bytes = max_tokens - nonzero_bytes * tokens_per_nonzero
if exceeds_cap:
zero_bytes += 1
calldata = b"\x01" * nonzero_bytes + b"\x00" * zero_bytes
contract = pre.deploy_contract(Op.STOP)
floor = floor_cost(data=calldata)
if exceeds_cap:
intrinsic = fork.transaction_intrinsic_cost_calculator()
regular = intrinsic(
calldata=calldata,
return_cost_deducted_prior_execution=True,
)
assert floor > cap, "calldata floor must exceed the cap"
assert regular < cap, "regular intrinsic must stay below the cap"
# Fund the floor in full so the sufficiency check cannot reject the
# transaction first; only the cap check can.
gas_limit = floor + 1_000_000
else:
assert floor <= cap
gas_limit = cap
tx = Transaction(
to=contract,
data=calldata,
gas_limit=gas_limit,
sender=pre.fund_eoa(),
error=TransactionException.INTRINSIC_GAS_TOO_LOW
if exceeds_cap
else None,
)
post = {contract: Account(code=Op.STOP)} if not exceeds_cap else {}
state_test(pre=pre, post=post, tx=tx)
|