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
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810 | @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),
},
)
|