Skip to content

test_floor_validity_across_amsterdam_transition()

Documentation for tests/amsterdam/eip7976_increase_calldata_floor_cost/test_fork_transition.py::test_floor_validity_across_amsterdam_transition@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7976_increase_calldata_floor_cost/test_fork_transition.py::test_floor_validity_across_amsterdam_transition --fork Amsterdam

Pin the EIP-7976 validity-threshold change across the boundary.

The gas limit must reserve the calldata floor for the transaction to be valid. A transaction whose gas limit exactly meets the old (EIP-7623) floor is accepted in the pre-fork block, but the identical shape is rejected once the fork activates because the new floor is higher for this calldata; one below the old floor is already rejected pre-fork, one just below the new floor is rejected post-fork, and one at the new floor is accepted post-fork.

The zero-byte arm pins the uniform token counting on the validity threshold itself, independently of the billed-gas path.

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_fork_transition.py
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
@pytest.mark.inclusion_test
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedBeforeFork()
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedBeforeFork()
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.AcceptedAfterFork()
@EIPChecklist.ModifiedTransactionValidityConstraint.Test.ForkTransition.RejectedAfterFork()
@pytest.mark.parametrize(
    "data",
    [
        pytest.param(ALL_ZERO_DATA, id="all_zero_bytes"),
        pytest.param(ALL_NONZERO_DATA, id="all_nonzero_bytes"),
    ],
)
@pytest.mark.parametrize(
    "scenario",
    [
        pytest.param("exact_floors_accepted", id="exact_floors_accepted"),
        pytest.param(
            "below_old_floor_rejected_before_fork",
            marks=pytest.mark.exception_test,
            id="below_old_floor_rejected_before_fork",
        ),
        pytest.param(
            "old_floor_rejected_after_fork",
            marks=pytest.mark.exception_test,
            id="old_floor_rejected_after_fork",
        ),
        pytest.param(
            "below_new_floor_rejected_after_fork",
            marks=pytest.mark.exception_test,
            id="below_new_floor_rejected_after_fork",
        ),
    ],
)
def test_floor_validity_across_amsterdam_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: TransitionFork,
    scenario: str,
    data: bytes,
) -> None:
    """
    Pin the EIP-7976 validity-threshold change across the boundary.

    The gas limit must reserve the calldata floor for the transaction to
    be valid. A transaction whose gas limit exactly meets the old
    (EIP-7623) floor is accepted in the pre-fork block, but the
    identical shape is rejected once the fork activates because the new
    floor is higher for this calldata; one below the old floor is
    already rejected pre-fork, one just below the new floor is rejected
    post-fork, and one at the new floor is accepted post-fork.

    The zero-byte arm pins the uniform token counting on the validity
    threshold itself, independently of the billed-gas path.
    """
    gas_price = 1_000_000_000
    target = pre.fund_eoa(amount=1)

    old_floor, new_floor = expected_floors(fork, data)
    # The old-floor-rejected-after-fork arm only exists because the new
    # floor exceeds the old one for this calldata size.
    assert new_floor > old_floor

    below_floor_error = TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST
    sender_initial_balance = 10**18
    pre_fork_sender = pre.fund_eoa(sender_initial_balance)
    post_fork_sender = pre.fund_eoa(sender_initial_balance)

    def transfer_tx(
        sender: Address, gas_limit: int, valid: bool
    ) -> Transaction:
        return Transaction(
            sender=sender,
            to=target,
            data=data,
            gas_limit=gas_limit,
            gas_price=gas_price,
            error=None if valid else below_floor_error,
        )

    untouched = Account(nonce=0, balance=sender_initial_balance)
    blocks: list[Block]

    if scenario == "exact_floors_accepted":
        blocks = [
            Block(
                timestamp=PRE_FORK_TIMESTAMP,
                txs=[transfer_tx(pre_fork_sender, old_floor, valid=True)],
            ),
            Block(
                timestamp=POST_FORK_TIMESTAMP,
                txs=[transfer_tx(post_fork_sender, new_floor, valid=True)],
            ),
        ]
        post = {
            pre_fork_sender: Account(
                nonce=1,
                balance=sender_initial_balance - old_floor * gas_price,
            ),
            post_fork_sender: Account(
                nonce=1,
                balance=sender_initial_balance - new_floor * gas_price,
            ),
        }
    elif scenario == "below_old_floor_rejected_before_fork":
        blocks = [
            Block(
                timestamp=PRE_FORK_TIMESTAMP,
                txs=[transfer_tx(pre_fork_sender, old_floor - 1, valid=False)],
                exception=below_floor_error,
            ),
        ]
        post = {pre_fork_sender: untouched, post_fork_sender: untouched}
    elif scenario == "old_floor_rejected_after_fork":
        blocks = [
            Block(
                timestamp=PRE_FORK_TIMESTAMP,
                txs=[transfer_tx(pre_fork_sender, old_floor, valid=True)],
            ),
            # The identical gas limit that was accepted pre-fork no
            # longer reserves the raised floor.
            Block(
                timestamp=POST_FORK_TIMESTAMP,
                txs=[transfer_tx(post_fork_sender, old_floor, valid=False)],
                exception=below_floor_error,
            ),
        ]
        post = {
            pre_fork_sender: Account(
                nonce=1,
                balance=sender_initial_balance - old_floor * gas_price,
            ),
            post_fork_sender: untouched,
        }
    else:
        # One below the new floor is still rejected post-fork; together
        # with the exact-floor acceptance this pins the post-fork
        # threshold at exactly the new floor.
        blocks = [
            Block(
                timestamp=POST_FORK_TIMESTAMP,
                txs=[
                    transfer_tx(post_fork_sender, new_floor - 1, valid=False)
                ],
                exception=below_floor_error,
            ),
        ]
        post = {pre_fork_sender: untouched, post_fork_sender: untouched}

    blockchain_test(pre=pre, blocks=blocks, post=post)

Parametrized Test Cases

This test generates 8 parametrized test cases across 1 fork.