1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
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 | def test_bal_selfdestruct_to_7702_delegation(
pre: Alloc,
blockchain_test: BlockchainTestFiller,
) -> None:
"""
Test BAL with SELFDESTRUCT to 7702 delegated account.
Tx1: Alice delegates to Oracle.
Tx2: Victim (balance=100) selfdestructs to Alice.
SELFDESTRUCT transfers balance without executing recipient code.
Expected BAL:
- Alice tx1: code_changes (delegation), nonce_changes
- Alice tx2: balance_changes (+100)
- Victim tx2: balance_changes (100→0)
- Oracle: MUST NOT appear (SELFDESTRUCT doesn't execute recipient code)
"""
# Alice (EOA) will receive delegation then receive selfdestruct balance
# Use explicit initial balance for clarity
alice_initial_balance = 10**18 # 1 ETH default
alice = pre.fund_eoa(amount=alice_initial_balance)
bob = pre.fund_eoa(amount=0) # Just to be the recipient of tx
# Oracle contract that Alice will delegate to
oracle = pre.deploy_contract(code=Op.SSTORE(0x01, 0x42) + Op.STOP)
victim_balance = 100
# Victim contract that selfdestructs to Alice
victim = pre.deploy_contract(
code=Op.SELFDESTRUCT(alice),
balance=victim_balance,
)
# Relayer for tx1 (delegation)
relayer = pre.fund_eoa()
# Tx1: Alice authorizes delegation to Oracle
tx1 = Transaction(
sender=relayer,
to=bob,
value=10,
authorization_list=[
AuthorizationTuple(
address=oracle,
nonce=0,
signer=alice,
)
],
)
# Caller contract that triggers selfdestruct on victim
caller = pre.deploy_contract(code=Op.CALL(100_000, victim, 0, 0, 0, 0, 0))
# Tx2: Trigger selfdestruct on victim (victim sends balance to Alice)
tx2 = Transaction(
nonce=1,
sender=relayer,
to=caller,
)
alice_final_balance = alice_initial_balance + victim_balance
account_expectations = {
alice: BalAccountExpectation(
# tx1: nonce change for auth, code change for delegation
nonce_changes=[BalNonceChange(block_access_index=1, post_nonce=1)],
code_changes=[
BalCodeChange(
block_access_index=1,
new_code=Spec7702.delegation_designation(oracle),
)
],
# tx2: balance change from selfdestruct
balance_changes=[
BalBalanceChange(
block_access_index=2, post_balance=alice_final_balance
)
],
),
bob: BalAccountExpectation(
balance_changes=[
BalBalanceChange(block_access_index=1, post_balance=10)
]
),
relayer: BalAccountExpectation(
nonce_changes=[
BalNonceChange(block_access_index=1, post_nonce=1),
BalNonceChange(block_access_index=2, post_nonce=2),
],
),
caller: BalAccountExpectation.empty(),
# Victim (selfdestructing contract): balance changes to 0
# Explicitly verify ALL fields to avoid false positives
victim: BalAccountExpectation(
nonce_changes=[], # Contract nonce unchanged
balance_changes=[
BalBalanceChange(block_access_index=2, post_balance=0)
],
code_changes=[], # Code unchanged (post-Cancun SELFDESTRUCT)
storage_changes=[], # No storage changes
storage_reads=[], # No storage reads
),
# Oracle MUST NOT appear in tx2 - SELFDESTRUCT doesn't execute
# recipient code, so delegation target is never accessed
oracle: None,
}
block = Block(
txs=[tx1, tx2],
expected_block_access_list=BlockAccessListExpectation(
account_expectations=account_expectations
),
)
post = {
alice: Account(
nonce=1,
code=Spec7702.delegation_designation(oracle),
balance=alice_final_balance,
),
bob: Account(balance=10),
relayer: Account(nonce=2),
# Victim still exists but with 0 balance (post-Cancun SELFDESTRUCT)
victim: Account(balance=0),
}
blockchain_test(
pre=pre,
blocks=[block],
post=post,
)
|