Skip to content

test_tstore_rollback_on_callcode_revert()

Documentation for tests/cancun/eip1153_tstore/test_tstorage_execution_contexts.py::test_tstore_rollback_on_callcode_revert@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/cancun/eip1153_tstore/test_tstorage_execution_contexts.py::test_tstore_rollback_on_callcode_revert --fork Amsterdam

Test TSTORE is rolled back after CALLCODE sub-call reverts.

Regression test for #911

Contract callee does TSTORE(4, 1), calls a precompile, then REVERTs. Contract caller uses CALLCODE to invoke callee, then checks TLOAD(4). Because CALLCODE executes in the caller's context and the sub-call reverted, TLOAD(4) must return 0.

Source code in tests/cancun/eip1153_tstore/test_tstorage_execution_contexts.py
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
@pytest.mark.ported_from(
    [
        "https://github.com/holiman/goevmlab/blob/master/examples/tstore_bug/main.go",
    ],
)
def test_tstore_rollback_on_callcode_revert(
    state_test: StateTestFiller,
    pre: Alloc,
) -> None:
    """
    Test TSTORE is rolled back after CALLCODE sub-call reverts.

    Regression test for
    https://github.com/ethereum/execution-specs/issues/911

    Contract `callee` does TSTORE(4, 1), calls a precompile, then
    REVERTs. Contract `caller` uses CALLCODE to invoke `callee`, then
    checks TLOAD(4). Because CALLCODE executes in the caller's context
    and the sub-call reverted, TLOAD(4) must return 0.
    """
    callee_code = (
        Op.TSTORE(4, 1)
        + Op.CALL(address=0x06)  # call identity precompile
        + Op.POP
        + Op.REVERT(0, 0)
    )
    callee_address = pre.deploy_contract(callee_code)

    caller_code = Op.SSTORE(
        0, Op.CALLCODE(address=callee_address)
    ) + Op.SSTORE(1, Op.TLOAD(4))
    caller_address = pre.deploy_contract(caller_code)

    sender = pre.fund_eoa()
    tx = Transaction(
        sender=sender,
        to=caller_address,
        gas_limit=1_000_000,
    )

    post = {
        # CALLCODE returns 0 (reverted), TLOAD(4) = 0 (rolled back)
        caller_address: Account(storage={0: 0, 1: 0}),
    }

    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 4 forks.