Skip to content

test_call_zero_value_to_self_destructed_same_tx_account()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_zero_value_to_self_destructed_same_tx_account@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_zero_value_to_self_destructed_same_tx_account --fork Amsterdam

Verify CALL with zero value to a same transaction selfdestructed account charges no new account state gas.

Value transfer gates the new account creation charge. Under the correct spec the block header reflects only the CREATE's single new account state gas charge. A spurious charge on the zero value CALL (value gate broken) would double the state gas component.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1559
1560
1561
1562
1563
1564
1565
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
@pytest.mark.parametrize(
    "create_opcode",
    [
        pytest.param(Op.CREATE, id="create"),
        pytest.param(Op.CREATE2, id="create2"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_call_zero_value_to_self_destructed_same_tx_account(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify CALL with zero value to a same transaction selfdestructed
    account charges no new account state gas.

    Value transfer gates the new account creation charge. Under the
    correct spec the block header reflects only the CREATE's single
    new account state gas charge. A spurious charge on the zero
    value CALL (value gate broken) would double the state gas
    component.
    """
    inner_code = Op.SELFDESTRUCT(Op.ADDRESS)
    mstore_value, size = init_code_at_high_bytes(inner_code)

    orchestrator_code = (
        Op.MSTORE(0, mstore_value)
        + (
            Op.CREATE2(1, 0, size, 0)
            if create_opcode == Op.CREATE2
            else Op.CREATE(1, 0, size)
        )
        + Op.MSTORE(0x20, Op.DUP1)
        + Op.POP
        + Op.POP(Op.CALL(gas=Op.GAS, address=Op.MLOAD(0x20), value=0))
    )
    orchestrator = pre.deploy_contract(code=orchestrator_code, balance=3)

    # The reservoir already pins the gas limit, and is sized for the
    # CREATE's single account creation. Pinning the header is what
    # proves the zero-value CALL added no second charge.
    state_gas = orchestrator_code.state_cost(fork)
    execution_gas = (
        fork.transaction_intrinsic_cost_calculator()()
        + orchestrator_code.execution_cost(fork)
        + inner_code.execution_cost(fork)
    )
    expected_gas_used = max(execution_gas, state_gas)
    assert expected_gas_used == state_gas, (
        "expected state gas to dominate execution gas"
    )

    tx = Transaction(
        to=orchestrator,
        state_gas_reservoir=state_gas,
        sender=pre.fund_eoa(),
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(txs=[tx], header_verify=Header(gas_used=expected_gas_used))
        ],
        post={},
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.