Skip to content

test_multi_tx_block_auth_refund_and_sstore()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py::test_multi_tx_block_auth_refund_and_sstore@a9abd46e.

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

Test multi-transaction block with auth refund and SSTORE state gas.

Two transactions in one block: 1. A SetCode tx authorizing an existing account (gets new-account state gas refund to reservoir). The refund reduces intrinsic_state_gas. 2. A regular tx performing an SSTORE (charges STATE_BYTES_PER_STORAGE_SET * cpsb state gas).

Verifies block-level state gas accounting correctly handles both the auth refund from tx1 and the SSTORE charge from tx2.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_set_code.py
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
@pytest.mark.valid_from("EIP8037")
def test_multi_tx_block_auth_refund_and_sstore(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test multi-transaction block with auth refund and SSTORE state gas.

    Two transactions in one block:
    1. A SetCode tx authorizing an existing account (gets new-account state gas
       refund to reservoir). The refund reduces intrinsic_state_gas.
    2. A regular tx performing an SSTORE (charges
       STATE_BYTES_PER_STORAGE_SET * cpsb state gas).

    Verifies block-level state gas accounting correctly handles both
    the auth refund from tx1 and the SSTORE charge from tx2.
    """
    auth_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    contract = pre.deploy_contract(code=Op.STOP)

    # TX 1: auth targeting existing account (gets refund)
    signer = pre.fund_eoa()
    authorization_list = [
        AuthorizationTuple(
            address=contract,
            nonce=0,
            signer=signer,
        ),
    ]
    sender_1 = pre.fund_eoa()
    tx_1 = Transaction(
        to=contract,
        state_gas_reservoir=auth_state_gas,
        authorization_list=authorization_list,
        sender=sender_1,
    )

    # TX 2: SSTORE zero-to-nonzero (charges state gas)
    storage = Storage()
    sstore_contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(1), 1),
    )
    sender_2 = pre.fund_eoa()
    tx_2 = Transaction(
        to=sstore_contract,
        state_gas_reservoir=sstore_state_gas,
        sender=sender_2,
    )

    blockchain_test(
        pre=pre,
        blocks=[Block(txs=[tx_1, tx_2])],
        post={sstore_contract: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.