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@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

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

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
30
31
32
33
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
@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.
    """
    auth_state_gas = fork.transaction_intrinsic_state_gas(
        authorization_count=1,
    )
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    storage = Storage()
    contract = pre.deploy_contract(
        code=Op.SSTORE(storage.store_next(1), 1),
    )

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

    sender = pre.fund_eoa()
    tx = Transaction(
        to=delegator,
        state_gas_reservoir=auth_state_gas + sstore_state_gas,
        authorization_list=[
            AuthorizationTuple(
                address=contract,
                nonce=0,
                signer=delegator,
            ),
        ],
        sender=sender,
    )

    # SSTORE writes to the delegator's storage context
    post = {delegator: Account(storage=storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.