Skip to content

test_sstore_via_delegation_pointer()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_sstore_via_delegation_pointer@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py::test_sstore_via_delegation_pointer --fork Bogota

Test SSTORE state gas charged when called via delegation pointer.

A contract performs an SSTORE. An EOA delegates to that contract via EIP-7702. Calling the EOA (delegation pointer) executes the contract code in the EOA's context. The SSTORE state gas should be charged from the reservoir just as it would for a direct call.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_delegation_pointer.py
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
@pytest.mark.valid_from("EIP8037")
def test_sstore_via_delegation_pointer(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SSTORE state gas charged when called via delegation pointer.

    A contract performs an SSTORE. An EOA delegates to that contract
    via EIP-7702. Calling the EOA (delegation pointer) executes the
    contract code in the EOA's context. The SSTORE state gas should
    be charged from the reservoir just as it would for a direct call.
    """
    storage = Storage()
    contract_code = Op.SSTORE(storage.store_next(1), 1)
    contract = pre.deploy_contract(code=contract_code)

    # EOA with pre-existing delegation to the contract
    delegator = pre.fund_eoa(delegation=contract)

    # The authorization re-targets an already-delegated authority whose
    # nonce (1, from the delegation setup) no longer matches nonce=0, so
    # it is invalid and charges no top-frame state gas.
    authorization = AuthorizationTuple(
        address=contract,
        nonce=0,
        signer=delegator,
        creates_account=False,
        writes_delegation=False,
        first_write=False,
    )
    intrinsic_execution = fork.transaction_intrinsic_cost_calculator()(
        authorization_list_or_count=[authorization],
        recipient_type=RecipientType.DELEGATION_7702,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_execution = fork.transaction_top_frame_execution_gas(
        recipient_type=RecipientType.DELEGATION_7702,
        delegation_warm=False,
        authorizations=[authorization],
    )
    auth_state_gas = fork.transaction_top_frame_state_gas(
        recipient_type=RecipientType.DELEGATION_7702,
        authorizations=[authorization],
    )
    assert auth_state_gas == 0

    block_execution = (
        intrinsic_execution
        + top_frame_execution
        + contract_code.execution_cost(fork)
    )
    block_state = auth_state_gas + contract_code.state_cost(fork)
    assert block_state > block_execution

    sender = pre.fund_eoa()
    tx = Transaction(
        to=delegator,
        state_gas_reservoir=block_state,
        authorization_list=[authorization],
        sender=sender,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=block_execution + block_state,
        ),
    )

    # SSTORE writes to the delegator's storage context
    post = {delegator: Account(storage=storage)}
    state_test(
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(
            gas_used=max(block_execution, block_state)
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 2 forks.