Skip to content

test_pre_delegated_authority_no_charge_after_failure()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_pre_delegated_authority_no_charge_after_failure@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_pre_delegated_authority_no_charge_after_failure --fork Amsterdam

Verify re-delegating an already-delegated authority carries no top-frame state charge, whether or not the top frame then fails.

The indicator is not net-new, so set_delegation charges no AUTH_BASE. A failing top frame must not turn that into a charge: the state dimension stays empty and the header reports the execution total alone.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
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
319
320
321
322
323
324
325
326
327
328
329
330
@pytest.mark.parametrize(
    "failure_mode",
    [
        pytest.param("revert", id="revert"),
        pytest.param("halt", id="halt"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_pre_delegated_authority_no_charge_after_failure(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    failure_mode: str,
) -> None:
    """
    Verify re-delegating an already-delegated authority carries no
    top-frame state charge, whether or not the top frame then fails.

    The indicator is not net-new, so ``set_delegation`` charges no
    ``AUTH_BASE``. A failing top frame must not turn that into a charge:
    the state dimension stays empty and the header reports the execution
    total alone.
    """
    first = pre.deploy_contract(code=Op.STOP)

    ending = Op.REVERT(0, 0) if failure_mode == "revert" else Op.INVALID
    recipient = pre.deploy_contract(code=ending)

    signer = pre.fund_eoa(delegation=first)
    authorization_list = [
        AuthorizationTuple(
            address=recipient,
            # The delegation setup already moved the nonce to 1.
            nonce=1,
            signer=signer,
            creates_account=False,
            writes_delegation=False,
            first_write=True,
        )
    ]

    intrinsic_execution, top_frame_execution, top_frame_state = _auth_gas(
        fork,
        authorization_list,
        recipient_type=RecipientType.DELEGATION_7702,
    )
    assert top_frame_state == 0, (
        "re-delegating an existing indicator is not net-new state"
    )

    gas_limit = intrinsic_execution + top_frame_execution + 50_000

    if failure_mode == "halt":
        # An exceptional halt burns the whole budget.
        expected_gas_used = gas_limit
    else:
        # REVERT returns the gas it did not spend.
        expected_gas_used = (
            intrinsic_execution
            + top_frame_execution
            + ending.execution_cost(fork)
        )

    tx = Transaction(
        to=signer,
        authorization_list=authorization_list,
        gas_limit=gas_limit,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            status=0, cumulative_gas_used=expected_gas_used
        ),
    )

    post = {
        signer: Account(code=Spec7702.delegation_designation(recipient)),
    }
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.