Skip to content

Commit 67c1983

Browse files
committed
refactor(test-tests): Add BAL expectation to state leak test; fix lint
1 parent d5735c5 commit 67c1983

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,20 +2208,18 @@ def test_bal_cross_tx_storage_revert_to_zero(
22082208
)
22092209

22102210

2211-
# RIPEMD-160 precompile address (used in Parity Touch Bug test)
2212-
RIPEMD_160 = Address(0x03)
2213-
2214-
2215-
def test_bal_cross_block_precompile_state_leak(
2211+
def test_bal_cross_block_ripemd160_state_leak(
22162212
pre: Alloc,
22172213
blockchain_test: BlockchainTestFiller,
22182214
) -> None:
22192215
"""
2220-
Ensure internal EVM state for precompile handling does not leak between blocks.
2216+
Ensure internal EVM state for RIMPEMD-160 precompile handling does not
2217+
leak between blocks.
22212218
22222219
The EVM may track internal state related to the Parity Touch Bug (EIP-161)
2223-
when calling RIPEMD-160 (0x03) with zero value. If this state is not properly
2224-
reset between blocks, it can cause incorrect BAL entries in subsequent blocks.
2220+
when calling RIPEMD-160 (0x03) with zero value. If this state is not
2221+
properly reset between blocks, it can cause incorrect BAL entries in
2222+
subsequent blocks.
22252223
22262224
Prerequisites for triggering the bug:
22272225
1. RIPEMD-160 (0x03) must already exist in state before the call.
@@ -2233,21 +2231,22 @@ def test_bal_cross_block_precompile_state_leak(
22332231
- Block 2: RIPEMD-160 NOT in BAL (never touched in this block)
22342232
22352233
Bug behavior:
2236-
- Block 2 incorrectly has RIPEMD-160 in its BAL due to leaked internal state.
2234+
- Block 2 incorrectly has RIPEMD-160 in its BAL due to leaked
2235+
internal state.
22372236
"""
22382237
alice = pre.fund_eoa()
22392238
bob = pre.fund_eoa()
2240-
22412239
# Pre-fund RIPEMD-160 so it exists before the call.
22422240
# This is required to trigger the internal state tracking.
2243-
pre[RIPEMD_160] = Account(balance=1)
2241+
ripemd160_addr = Address(0x03)
2242+
pre.fund_address(ripemd160_addr, amount=1)
22442243

22452244
# Contract that calls RIPEMD-160 with zero value
22462245
ripemd_caller = pre.deploy_contract(
2247-
code=Op.CALL(50_000, RIPEMD_160, 0, 0, 0, 0, 0) + Op.STOP
2246+
code=Op.CALL(50_000, ripemd160_addr, 0, 0, 0, 0, 0) + Op.STOP
22482247
)
2249-
2250-
# Contract that triggers an exception (stack underflow from ADD on empty stack)
2248+
# Contract that triggers an exception
2249+
# (stack underflow from ADD on empty stack)
22512250
exception_contract = pre.deploy_contract(code=Op.ADD)
22522251

22532252
# Block 1: Call RIPEMD-160 successfully
@@ -2259,6 +2258,16 @@ def test_bal_cross_block_precompile_state_leak(
22592258
gas_limit=100_000,
22602259
)
22612260
],
2261+
expected_block_access_list=BlockAccessListExpectation(
2262+
account_expectations={
2263+
alice: BalAccountExpectation(
2264+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)]
2265+
),
2266+
bob: None,
2267+
ripemd_caller: BalAccountExpectation.empty(),
2268+
ripemd160_addr: BalAccountExpectation.empty(),
2269+
}
2270+
),
22622271
)
22632272

22642273
# Block 2: Exception triggers internal exception handling.
@@ -2272,6 +2281,16 @@ def test_bal_cross_block_precompile_state_leak(
22722281
gas_limit=100_000,
22732282
)
22742283
],
2284+
expected_block_access_list=BlockAccessListExpectation(
2285+
account_expectations={
2286+
alice: None,
2287+
bob: BalAccountExpectation(
2288+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)]
2289+
),
2290+
# this is the important check
2291+
ripemd160_addr: None,
2292+
}
2293+
),
22752294
)
22762295

22772296
blockchain_test(
@@ -2280,6 +2299,6 @@ def test_bal_cross_block_precompile_state_leak(
22802299
post={
22812300
alice: Account(nonce=1),
22822301
bob: Account(nonce=1),
2283-
RIPEMD_160: Account(balance=1),
2302+
ripemd160_addr: Account(balance=1),
22842303
},
22852304
)

0 commit comments

Comments
 (0)