Skip to content

test_auth_sender_billing_after_failure()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_auth_sender_billing_after_failure@c74f1a67.

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_auth_sender_billing_after_failure --fork Amsterdam

Verify sender billing distinguishes new vs existing account auth on top-level failure.

For existing accounts, set_delegation refunds new-account state gas to the reservoir and the worst-case ACCOUNT_WRITE to the regular refund counter; both survive the top-level REVERT since delegations are applied before execution. On REVERT, the restored reservoir and the capped regular refund reduce the sender's bill via the billing formula. The sender pays less than in the new-account case.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
@pytest.mark.parametrize(
    "authority_exists",
    [
        pytest.param(False, id="new_account"),
        pytest.param(True, id="existing_account"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_auth_sender_billing_after_failure(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    authority_exists: bool,
) -> None:
    """
    Verify sender billing distinguishes new vs existing account auth
    on top-level failure.

    For existing accounts, set_delegation refunds new-account state
    gas to the reservoir and the worst-case `ACCOUNT_WRITE` to the
    regular refund counter; both survive the top-level REVERT since
    delegations are applied before execution. On REVERT, the restored
    reservoir and the capped regular refund reduce the sender's bill
    via the billing formula. The sender pays less than in the
    new-account case.
    """
    auth_intrinsic_state = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    intrinsic_total = intrinsic_cost(authorization_list_or_count=1)
    intrinsic_regular = intrinsic_total - auth_intrinsic_state
    new_account_refund = fork.gas_costs().REFUND_AUTH_PER_EXISTING_ACCOUNT

    delegate = pre.deploy_contract(code=Op.STOP)
    target = pre.deploy_contract(code=Op.REVERT(0, 0))

    if authority_exists:
        signer = pre.fund_eoa()
    else:
        signer = pre.fund_eoa(0)

    revert_gas = (Op.REVERT(0, 0)).gas_cost(fork)
    auth_refund = new_account_refund if authority_exists else 0
    refund_counter = fork.gas_costs().ACCOUNT_WRITE if authority_exists else 0
    gas_used_before_refund = intrinsic_total + revert_gas - auth_refund
    regular_refund = min(
        gas_used_before_refund // fork.max_refund_quotient(),
        refund_counter,
    )
    expected_cumulative = gas_used_before_refund - regular_refund
    expected_gas_used = max(
        intrinsic_regular + revert_gas,
        auth_intrinsic_state - auth_refund,
    )

    tx = Transaction(
        ty=4,
        to=target,
        state_gas_reservoir=auth_intrinsic_state,
        sender=pre.fund_eoa(),
        authorization_list=[
            AuthorizationTuple(
                address=delegate,
                nonce=0,
                signer=signer,
            ),
        ],
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_cumulative,
        ),
    )

    state_test(
        pre=pre,
        post={
            signer: Account(
                code=Spec7702.delegation_designation(delegate),
            ),
        },
        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.