Skip to content

test_bal_outer_revert_with_inner_insufficient_funds()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_outer_revert_with_inner_insufficient_funds@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_outer_revert_with_inner_insufficient_funds --fork Amsterdam

Outer REVERT + inner CALL/CREATE that fails on insufficient funds.

Inner writes two slots and then attempts a value-bearing CALL or CREATE that fails (balance=0 < value). The opcode's state-touching costs are charged before the balance check, so the failed CALL's target stays in BAL with empty changes, while CREATE fails before track_address and the would-be address does not appear at all. Inner's writes demote to reads under outer's REVERT; the post-state checks confirm none of the rolled-back state leaked through.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
@pytest.mark.parametrize(
    "inner_op",
    [pytest.param("call", id="call"), pytest.param("create", id="create")],
)
def test_bal_outer_revert_with_inner_insufficient_funds(
    pre: Alloc,
    state_test: StateTestFiller,
    inner_op: str,
) -> None:
    """
    Outer REVERT + inner CALL/CREATE that fails on insufficient funds.

    Inner writes two slots and then attempts a value-bearing CALL or
    CREATE that fails (balance=0 < value). The opcode's state-touching
    costs are charged before the balance check, so the failed CALL's
    target stays in BAL with empty changes, while CREATE fails before
    `track_address` and the would-be address does not appear at all.
    Inner's writes demote to reads under outer's REVERT; the post-state
    checks confirm none of the rolled-back state leaked through.
    """
    alice = pre.fund_eoa()
    slot_a, slot_b = 1, 2
    insufficient_value = 100

    if inner_op == "call":
        target = pre.deploy_contract(code=Op.STOP)
        inner = pre.deploy_contract(
            code=(
                Op.SSTORE(slot_a, 0x42)
                + Op.SSTORE(
                    slot_b,
                    Op.CALL(
                        gas=100_000,
                        address=target,
                        value=insufficient_value,
                    ),
                )
                + Op.STOP
            ),
            balance=0,
        )
        extra_account = target
        extra_bal: BalAccountExpectation | None = BalAccountExpectation.empty()
        extra_post: Account | None = Account(balance=0)
    elif inner_op == "create":
        initcode_bytes = bytes(Initcode(deploy_code=Op.STOP))
        inner = pre.deploy_contract(
            code=(
                Op.MSTORE(0, Op.PUSH32(initcode_bytes))
                + Op.SSTORE(slot_a, 0x42)
                + Op.SSTORE(
                    slot_b,
                    Op.CREATE(
                        value=insufficient_value,
                        offset=32 - len(initcode_bytes),
                        size=len(initcode_bytes),
                    ),
                )
                + Op.STOP
            ),
            balance=0,
        )
        extra_account = compute_create_address(address=inner, nonce=1)
        extra_bal = None
        extra_post = Account.NONEXISTENT
    else:
        raise ValueError(f"unknown inner_op: {inner_op}")

    outer = pre.deploy_contract(
        code=Op.CALL(gas=Op.GAS, address=inner) + Op.REVERT(0, 0)
    )

    tx = Transaction(sender=alice, to=outer)

    state_test(
        pre=pre,
        post={
            alice: Account(nonce=1),
            outer: Account(balance=0, storage={}),
            inner: Account(balance=0, storage={}),
            extra_account: extra_post,
        },
        tx=tx,
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                outer: BalAccountExpectation.empty(),
                inner: BalAccountExpectation(storage_reads=[slot_a, slot_b]),
                extra_account: extra_bal,
            },
        ),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.