Skip to content

test_account_write_first_write_of_authority()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py::test_account_write_first_write_of_authority@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_first_write_of_authority --fork Amsterdam

ACCOUNT_WRITE is charged on the first write to the authority within the transaction, independent of whether its account leaf already exists.

Applying an authorization writes the authority's leaf (code and nonce), so the first authorization on any authority not yet written in the transaction pays ACCOUNT_WRITE:

  • non_existent: the authority also pays NEW_ACCOUNT for the fresh leaf (and AUTH_BASE for the net-new indicator).
  • existing_eoa: the leaf exists, but the delegation write is still this transaction's first write to it, so ACCOUNT_WRITE is charged all the same (plus AUTH_BASE).
Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_authorization_charges.py
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
@pytest.mark.parametrize(
    "authority_prestate", ["non_existent", "existing_eoa"]
)
def test_account_write_first_write_of_authority(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    authority_prestate: str,
) -> None:
    """
    ``ACCOUNT_WRITE`` is charged on the first write to the authority
    within the transaction, independent of whether its account leaf
    already exists.

    Applying an authorization writes the authority's leaf (code and
    nonce), so the first authorization on any authority not yet written
    in the transaction pays ``ACCOUNT_WRITE``:

    - ``non_existent``: the authority also pays ``NEW_ACCOUNT`` for the
      fresh leaf (and ``AUTH_BASE`` for the net-new indicator).
    - ``existing_eoa``: the leaf exists, but the delegation write is
      still this transaction's first write to it, so ``ACCOUNT_WRITE``
      is charged all the same (plus ``AUTH_BASE``).
    """
    sender = pre.fund_eoa()
    recipient = pre.deploy_contract(code=Op.STOP)

    if authority_prestate == "non_existent":
        scenario = build_authorization(
            pre, AuthorizationAction.CREATES_ACCOUNT
        )
    else:
        scenario = build_authorization(
            pre, AuthorizationAction.SETS_NEW_DELEGATION
        )

    authorization_list = [scenario.authorization]
    total_gas_cost = authorization_transaction_cost(fork, authorization_list)

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

    post = {
        scenario.authority: scenario.applied_account,
    }

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.