Skip to content

test_invalid_auth_rule1_refill_by_reason()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_invalid_auth_rule1_refill_by_reason@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_invalid_auth_rule1_refill_by_reason --fork Amsterdam

Verify an invalid authorization refills its full intrinsic state gas.

A rejected authorization is skipped during processing. Its whole state portion of NEW_ACCOUNT plus AUTH_BASE refills the reservoir and one ACCOUNT_WRITE refunds to the refund counter. The regular per authorization base cost stays charged and the authority is never created. Swept over the reasons an authorization is rejected.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
@pytest.mark.parametrize(
    "invalidity",
    [
        pytest.param("nonce_mismatch", id="nonce_mismatch"),
        pytest.param("nonce_at_u64_max", id="nonce_at_u64_max"),
        pytest.param("chain_id_mismatch", id="chain_id_mismatch"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_invalid_auth_rule1_refill_by_reason(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    invalidity: str,
) -> None:
    """
    Verify an invalid authorization refills its full intrinsic state gas.

    A rejected authorization is skipped during processing. Its whole
    state portion of NEW_ACCOUNT plus AUTH_BASE refills the reservoir
    and one ACCOUNT_WRITE refunds to the refund counter. The regular
    per authorization base cost stays charged and the authority is
    never created. Swept over the reasons an authorization is rejected.
    """
    per_auth_state = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    total_intrinsic = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=1,
    )
    intrinsic_regular = total_intrinsic - per_auth_state
    account_write = fork.gas_costs().ACCOUNT_WRITE

    target = pre.deploy_contract(code=Op.STOP)
    signer = pre.fund_eoa(amount=0)

    if invalidity == "nonce_mismatch":
        auth = AuthorizationTuple(address=target, nonce=99, signer=signer)
    elif invalidity == "nonce_at_u64_max":
        auth = AuthorizationTuple(
            address=target,
            nonce=2**64 - 1,
            signer=signer,
        )
    elif invalidity == "chain_id_mismatch":
        auth = AuthorizationTuple(
            address=target,
            nonce=0,
            chain_id=9999,
            signer=signer,
        )
    else:
        raise ValueError(f"unknown invalidity: {invalidity!r}")

    # The skipped auth refills its whole state portion to the reservoir
    # so the net state charge is zero, and one ACCOUNT_WRITE returns to
    # the capped refund counter.
    auth_refund = per_auth_state
    refund_counter = account_write

    header_gas_used = max(intrinsic_regular, per_auth_state - auth_refund)
    gas_used_before_refund = total_intrinsic - auth_refund
    regular_refund = min(
        gas_used_before_refund // fork.max_refund_quotient(),
        refund_counter,
    )
    receipt_cumulative_gas_used = gas_used_before_refund - regular_refund

    tx = Transaction(
        to=target,
        state_gas_reservoir=per_auth_state,
        authorization_list=[auth],
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=receipt_cumulative_gas_used,
        ),
    )

    state_test(
        pre=pre,
        post={signer: Account.NONEXISTENT},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=header_gas_used),
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.