1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295 | 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,
gas_limit=1_000_000,
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,
gas_limit=1_000_000,
gas_price=0xA,
)
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,
)
|