Skip to content

test_account_write_authority_is_sender()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_account_write_authority_is_sender@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_account_write_authority_is_sender --fork Amsterdam

An authority that is the transaction sender pays no ACCOUNT_WRITE: the sender's account was already written at inclusion (nonce bump and fee deduction, priced into TX_BASE), so the delegation write is not the first write to it within the transaction.

The self-sponsored authorization still pays AUTH_BASE for its net-new delegation indicator. This case guards the first-write rule against over-charging accounts the transaction has already paid to write.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py
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
319
320
def test_account_write_authority_is_sender(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    An authority that is the transaction sender pays no
    ``ACCOUNT_WRITE``: the sender's account was already written at
    inclusion (nonce bump and fee deduction, priced into ``TX_BASE``),
    so the delegation write is not the first write to it within the
    transaction.

    The self-sponsored authorization still pays ``AUTH_BASE`` for its
    net-new delegation indicator. This case guards the first-write rule
    against over-charging accounts the transaction has already paid to
    write.
    """
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)
    delegation_target = pre.deploy_contract(code=Op.STOP)

    # The sender's nonce is bumped at inclusion, before authorizations
    # are processed, so the self-sponsored authorization signs nonce 1.
    authorization = AuthorizationTuple(
        address=delegation_target,
        nonce=1,
        signer=sender,
        first_write=False,
    )

    total_gas_cost = authorization_transaction_cost(fork, [authorization])

    tx = Transaction(
        sender=sender,
        to=recipient,
        value=0,
        authorization_list=[authorization],
        gas_limit=total_gas_cost,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=total_gas_cost,
        ),
    )

    post = {
        sender: Account(
            nonce=2,
            code=Spec7702.delegation_designation(delegation_target),
        ),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.