Skip to content

Commit 484aa38

Browse files
committed
feat(tests): Additional cases for BLOCKCHASH
1 parent d9eb924 commit 484aa38

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2929
- ✨ Expand cases to test *CALL opcodes causing OOG ([#1703](https://github.com/ethereum/execution-specs/pull/1703)).
3030
- ✨ Add tests for `modexp` and `ripemd` precompiled contracts ([#1691](https://github.com/ethereum/execution-specs/pull/1691)).
3131
- ✨ Add `ecrecover` precompile tests originating form `evmone` unittests ([#1685](https://github.com/ethereum/execution-specs/pull/1685)).
32+
- ✨ Add stack overflow tests and expand `BLOCKHASH` tests ([#1728](https://github.com/ethereum/execution-specs/pull/1728)).
3233

3334
## [v5.3.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v5.3.0) - 2025-10-09
3435

tests/frontier/opcodes/test_blockhash.py

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
Storage,
1111
Transaction,
1212
)
13+
from execution_testing.forks import Byzantium
14+
from execution_testing.forks.helpers import Fork
1315

1416

1517
@pytest.mark.valid_from("Frontier")
18+
@pytest.mark.parametrize(
19+
"first_block", ["none", "empty", "with_tx", "over_256"]
20+
)
1621
def test_genesis_hash_available(
17-
blockchain_test: BlockchainTestFiller, pre: Alloc
22+
blockchain_test: BlockchainTestFiller,
23+
pre: Alloc,
24+
fork: Fork,
25+
first_block: str,
1826
) -> None:
1927
"""
2028
Verify BLOCKHASH returns genesis and block 1 hashes.
@@ -29,45 +37,58 @@ def test_genesis_hash_available(
2937
Bug context: revm blockchaintest runner wasn't inserting block_hashes,
3038
causing failures in tests with BLOCKHASH-derived addresses.
3139
"""
32-
storage = Storage()
40+
Storage()
3341

3442
# Store ISZERO(BLOCKHASH(0)) and ISZERO(BLOCKHASH(1))
3543
# Both should be 0 (false) if hashes exist
36-
code = Op.SSTORE(
37-
storage.store_next(0), Op.ISZERO(Op.BLOCKHASH(0))
38-
) + Op.SSTORE(storage.store_next(0), Op.ISZERO(Op.BLOCKHASH(1)))
44+
code = Op.SSTORE(0, Op.ISZERO(Op.BLOCKHASH(0))) + Op.SSTORE(
45+
1, Op.ISZERO(Op.BLOCKHASH(1))
46+
)
3947

4048
contract = pre.deploy_contract(code=code)
4149
sender = pre.fund_eoa()
4250

43-
blocks = [
44-
Block(
45-
txs=[
46-
Transaction(
47-
sender=sender,
48-
to=contract,
49-
gas_limit=100_000,
50-
protected=False,
51-
)
52-
]
53-
),
54-
Block(
55-
txs=[
56-
Transaction(
57-
sender=sender,
58-
to=contract,
59-
gas_limit=100_000,
60-
protected=False,
61-
)
62-
]
63-
),
64-
]
51+
blocks = (
52+
[
53+
Block(
54+
txs=[
55+
Transaction(
56+
sender=sender,
57+
to=contract,
58+
gas_limit=100_000,
59+
protected=fork >= Byzantium,
60+
)
61+
]
62+
)
63+
]
64+
if first_block == "with_tx"
65+
else [Block()]
66+
if first_block == "empty"
67+
else [Block()] * 256
68+
if first_block == "over_256"
69+
else []
70+
) + (
71+
[
72+
Block(
73+
txs=[
74+
Transaction(
75+
sender=sender,
76+
to=contract,
77+
gas_limit=100_000,
78+
protected=fork >= Byzantium,
79+
)
80+
]
81+
)
82+
]
83+
)
6584

6685
post = {
6786
contract: Account(
6887
storage={
69-
0: 0, # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
70-
1: 0, # ISZERO(BLOCKHASH(1)) = 0 (block 1 hash exists)
88+
# ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
89+
0: 1 if first_block == "over_256" else 0,
90+
# ISZERO(BLOCKHASH(1)) = 0 (if block 1 hash exists)
91+
1: 1 if first_block == "none" else 0,
7192
}
7293
)
7394
}

0 commit comments

Comments
 (0)