Skip to content

test_bal_precompile_funded()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py::test_bal_precompile_funded@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_precompile_funded --fork Amsterdam

Ensure BAL records precompile value transfer.

Alice sends value to precompile (pure value transfer). If value > 0: BAL must include balance_changes. If value = 0: BAL must have empty balance_changes.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(10**18, id="with_value"),
        pytest.param(0, id="no_value"),
    ],
)
@pytest.mark.with_all_precompiles
def test_bal_precompile_funded(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
    precompile: Address,
    value: int,
) -> None:
    """
    Ensure BAL records precompile value transfer.

    Alice sends value to precompile (pure value transfer).
    If value > 0: BAL must include balance_changes.
    If value = 0: BAL must have empty balance_changes.
    """
    alice = pre.fund_eoa()

    addr_int = int.from_bytes(precompile, "big")

    # Map precompile addresses to their required minimal input sizes
    # - Most precompiles accept zero-padded input of appropriate length
    # - For 0x0a (POINT_EVALUATION), use a known valid input from mainnet
    if addr_int == 0x0A:
        # Valid point evaluation input from mainnet tx:
        # https://etherscan.io/tx/0xcb3dc8f3b14f1cda0c16a619a112102a8ec70dce1b3f1b28272227cf8d5fbb0e
        tx_data = (
            bytes.fromhex(
                # versioned_hash (32)
                "018156B94FE9735E573BAB36DAD05D60FEB720D424CCD20AAF719343C31E4246"
            )
            + bytes.fromhex(
                # z (32)
                "019123BCB9D06356701F7BE08B4494625B87A7B02EDC566126FB81F6306E915F"
            )
            + bytes.fromhex(
                # y (32)
                "6C2EB1E94C2532935B8465351BA1BD88EABE2B3FA1AADFF7D1CD816E8315BD38"
            )
            + bytes.fromhex(
                # kzg_commitment (48)
                "A9546D41993E10DF2A7429B8490394EA9EE62807BAE6F326D1044A51581306F58D4B9DFD5931E044688855280FF3799E"
            )
            + bytes.fromhex(
                # kzg_proof (48)
                "A2EA83D9391E0EE42E0C650ACC7A1F842A7D385189485DDB4FD54ADE3D9FD50D608167DCA6C776AAD4B8AD5C20691BFE"
            )
        )
    else:
        precompile_min_input = {
            0x01: 128,  # ECRECOVER
            0x02: 0,  # SHA256 (accepts empty)
            0x03: 0,  # RIPEMD160 (accepts empty)
            0x04: 0,  # IDENTITY (accepts empty)
            0x05: 96,  # MODEXP
            0x06: 128,  # BN256ADD
            0x07: 96,  # BN256MUL
            0x08: 0,  # BN256PAIRING (empty is valid)
            0x09: 213,  # BLAKE2F
            0x0B: 256,  # BLS12_G1_ADD
            0x0C: 160,  # BLS12_G1_MSM
            0x0D: 512,  # BLS12_G2_ADD
            0x0E: 288,  # BLS12_G2_MSM
            0x0F: 384,  # BLS12_PAIRING
            0x10: 64,  # BLS12_MAP_FP_TO_G1
            0x11: 128,  # BLS12_MAP_FP2_TO_G2
            0x100: 160,  # P256VERIFY
        }

        input_size = precompile_min_input.get(addr_int, 0)
        tx_data = bytes([0x00] * input_size if input_size > 0 else [])

    tx = Transaction(
        sender=alice,
        to=precompile,
        value=value,
        data=tx_data,
    )

    block = Block(
        txs=[tx],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1)
                    ],
                ),
                precompile: BalAccountExpectation(
                    balance_changes=[
                        BalBalanceChange(
                            block_access_index=1, post_balance=value
                        )
                    ]
                    if value > 0
                    else [],
                    storage_reads=[],
                    storage_changes=[],
                    code_changes=[],
                ),
            }
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(nonce=1),
        },
    )

Parametrized Test Cases

This test generates 36 parametrized test cases across 1 fork.