Skip to content

test_warm_coinbase_call_out_of_gas()

Documentation for tests/shanghai/eip3651_warm_coinbase/test_warm_coinbase.py::test_warm_coinbase_call_out_of_gas@83970623.

Generate fixtures for these test cases for Prague with:

fill -v tests/shanghai/eip3651_warm_coinbase/test_warm_coinbase.py::test_warm_coinbase_call_out_of_gas --fork Prague

Test that the coinbase is warm by accessing the COINBASE with each of the following opcodes.

  • CALL
  • CALLCODE
  • DELEGATECALL
  • STATICCALL
Source code in tests/shanghai/eip3651_warm_coinbase/test_warm_coinbase.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@pytest.mark.valid_from("Shanghai")
@pytest.mark.parametrize(
    "use_sufficient_gas",
    [True, False],
    ids=["sufficient_gas", "insufficient_gas"],
)
@pytest.mark.parametrize(
    "opcode,contract_under_test_code,call_gas_exact",
    [
        (
            "call",
            Op.POP(Op.CALL(0, Op.COINBASE, 0, 0, 0, 0, 0)),
            # Extra gas: COINBASE + 4*PUSH1 + 2*DUP1 + POP
            GAS_REQUIRED_CALL_WARM_ACCOUNT + 22,
        ),
        (
            "callcode",
            Op.POP(Op.CALLCODE(0, Op.COINBASE, 0, 0, 0, 0, 0)),
            # Extra gas: COINBASE + 4*PUSH1 + 2*DUP1 + POP
            GAS_REQUIRED_CALL_WARM_ACCOUNT + 22,
        ),
        (
            "delegatecall",
            Op.POP(Op.DELEGATECALL(0, Op.COINBASE, 0, 0, 0, 0)),
            # Extra: COINBASE + 3*PUSH1 + 2*DUP1 + POP
            GAS_REQUIRED_CALL_WARM_ACCOUNT + 19,
        ),
        (
            "staticcall",
            Op.POP(Op.STATICCALL(0, Op.COINBASE, 0, 0, 0, 0)),
            # Extra: COINBASE + 3*PUSH1 + 2*DUP1 + POP
            GAS_REQUIRED_CALL_WARM_ACCOUNT + 19,
        ),
    ],
    ids=["CALL", "CALLCODE", "DELEGATECALL", "STATICCALL"],
)
def test_warm_coinbase_call_out_of_gas(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    post: Alloc,
    sender: Address,
    fork: Fork,
    opcode: str,
    contract_under_test_code: Bytecode,
    call_gas_exact: int,
    use_sufficient_gas: bool,
):
    """
    Test that the coinbase is warm by accessing the COINBASE with each
    of the following opcodes.

    - CALL
    - CALLCODE
    - DELEGATECALL
    - STATICCALL
    """
    contract_under_test_address = pre.deploy_contract(contract_under_test_code)

    if not use_sufficient_gas:
        call_gas_exact -= 1

    caller_code = Op.SSTORE(
        0,
        Op.CALL(call_gas_exact, contract_under_test_address, 0, 0, 0, 0, 0),
    )
    caller_address = pre.deploy_contract(caller_code)

    tx = Transaction(
        ty=0x0,
        chain_id=0x01,
        nonce=0,
        to=caller_address,
        gas_limit=100000000,
        gas_price=10,
        sender=sender,
    )

    if use_sufficient_gas and fork >= Shanghai:
        post[caller_address] = Account(
            storage={
                # On shanghai and beyond, calls with only 100 gas to
                # coinbase will succeed.
                0: 1,
            }
        )
    else:
        post[caller_address] = Account(
            storage={
                # Before shanghai, calls with only 100 gas to
                # coinbase will fail.
                0: 0,
            }
        )

    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
        tag="opcode_" + opcode,
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) opcode contract_under_test_code call_gas_exact use_sufficient_gas
...fork_Shanghai-blockchain_test-CALL-sufficient_gas call 122 True
...fork_Shanghai-blockchain_test-CALL-insufficient_gas call 122 False
...fork_Shanghai-blockchain_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Shanghai-blockchain_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Shanghai-blockchain_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Shanghai-blockchain_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Shanghai-blockchain_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Shanghai-blockchain_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Shanghai-state_test-CALL-sufficient_gas call 122 True
...fork_Shanghai-state_test-CALL-insufficient_gas call 122 False
...fork_Shanghai-state_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Shanghai-state_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Shanghai-state_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Shanghai-state_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Shanghai-state_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Shanghai-state_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Cancun-blockchain_test-CALL-sufficient_gas call 122 True
...fork_Cancun-blockchain_test-CALL-insufficient_gas call 122 False
...fork_Cancun-blockchain_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Cancun-blockchain_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Cancun-blockchain_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Cancun-blockchain_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Cancun-blockchain_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Cancun-blockchain_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Cancun-state_test-CALL-sufficient_gas call 122 True
...fork_Cancun-state_test-CALL-insufficient_gas call 122 False
...fork_Cancun-state_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Cancun-state_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Cancun-state_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Cancun-state_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Cancun-state_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Cancun-state_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Prague-blockchain_test-CALL-sufficient_gas call 122 True
...fork_Prague-blockchain_test-CALL-insufficient_gas call 122 False
...fork_Prague-blockchain_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Prague-blockchain_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Prague-blockchain_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Prague-blockchain_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Prague-blockchain_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Prague-blockchain_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Prague-state_test-CALL-sufficient_gas call 122 True
...fork_Prague-state_test-CALL-insufficient_gas call 122 False
...fork_Prague-state_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Prague-state_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Prague-state_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Prague-state_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Prague-state_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Prague-state_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Osaka-blockchain_test-CALL-sufficient_gas call 122 True
...fork_Osaka-blockchain_test-CALL-insufficient_gas call 122 False
...fork_Osaka-blockchain_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Osaka-blockchain_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Osaka-blockchain_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Osaka-blockchain_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Osaka-blockchain_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Osaka-blockchain_test-STATICCALL-insufficient_gas staticcall 119 False
...fork_Osaka-state_test-CALL-sufficient_gas call 122 True
...fork_Osaka-state_test-CALL-insufficient_gas call 122 False
...fork_Osaka-state_test-CALLCODE-sufficient_gas callcode 122 True
...fork_Osaka-state_test-CALLCODE-insufficient_gas callcode 122 False
...fork_Osaka-state_test-DELEGATECALL-sufficient_gas delegatecall 119 True
...fork_Osaka-state_test-DELEGATECALL-insufficient_gas delegatecall 119 False
...fork_Osaka-state_test-STATICCALL-sufficient_gas staticcall 119 True
...fork_Osaka-state_test-STATICCALL-insufficient_gas staticcall 119 False