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
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507 | @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,
gas_limit=5_000_000,
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),
},
)
|