Skip to content

Commit 42b6492

Browse files
committed
Add identity tests for CALL
1 parent 3460eae commit 42b6492

File tree

7 files changed

+186
-974
lines changed

7 files changed

+186
-974
lines changed

Diff for: converted-ethereum-tests.txt

-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,3 @@ GeneralStateTests/stPreCompiledContracts/blake2B.json
100100

101101
([#1067](https://github.com/ethereum/execution-spec-tests/pull/1120))
102102
GeneralStateTests/stPreCompiledContracts/idPrecomps.json
103-
104-
([#1244](https://github.com/ethereum/execution-spec-tests/pull/1244))
105-
GeneralStateTests/stPreCompiledContracts2/CALLBlake2f.json
106-
GeneralStateTests/stPreCompiledContracts2/CALLCODEBlake2f.json

Diff for: docs/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ The following changes may be potentially breaking (all clients were tested with
8686
- ✨ Add gas cost of delegation access in CALL opcode ([#1208](https://github.com/ethereum/execution-spec-tests/pull/1208)).
8787
- ✨ Add EIP-7698 failed nonce and short data tests ([#1211](https://github.com/ethereum/execution-spec-tests/pull/1211)).
8888
- ✨ Add EIP-2537 additional pairing precompile tests cases, and then update all BLS12 test vectors ([#1275](https://github.com/ethereum/execution-spec-tests/pull/1275), [#1289](https://github.com/ethereum/execution-spec-tests/pull/1289)).
89-
- ✨ Add test cases for EIP-152 Blake2 and Identity precompiles ([#1244](https://github.com/ethereum/execution-spec-tests/pull/1244)).
9089

9190
## [v4.0.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.0.0) - 2025-02-14 - 💕
9291

Diff for: tests/frontier/precompiles/test_identity.py

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""abstract: Test identity precompile output size."""
2+
3+
from dataclasses import dataclass
4+
from typing import Tuple
5+
6+
import pytest
7+
8+
from ethereum_test_tools import (
9+
Account,
10+
Alloc,
11+
Bytecode,
12+
Environment,
13+
StateTestFiller,
14+
Transaction,
15+
)
16+
from ethereum_test_tools import Opcodes as Op
17+
from ethereum_test_types.helpers import TestParameterGroup
18+
19+
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-152.md"
20+
REFERENCE_SPEC_VERSION = "5510973b40973b6aa774f04c9caba823c8ff8460"
21+
22+
IDENTITY_PRECOMPILE_ADDRESS = 0x04
23+
24+
25+
class CallInputs:
26+
"""Defines inputs to CALL for the Identity precompile."""
27+
28+
def __init__(
29+
self,
30+
gas=0x1F4,
31+
value=0x0,
32+
args_offset=0x20,
33+
args_size=0x0,
34+
output_offset=0x20,
35+
output_size=0x0,
36+
):
37+
"""Create a new instance with the provided values."""
38+
self.gas = gas
39+
self.value = value
40+
self.args_offset = args_offset
41+
self.args_size = args_size
42+
self.output_offset = output_offset
43+
self.output_size = output_size
44+
45+
46+
@pytest.mark.valid_from("Byzantium")
47+
@pytest.mark.parametrize(
48+
["inputs", "store_values_code", "stored_value_offset", "expected"],
49+
[
50+
pytest.param(CallInputs(gas=0xFF), Op.MSTORE(0, 0x1), 0x0, 0x1, id="identity_0"),
51+
pytest.param(
52+
CallInputs(args_offset=0x0),
53+
Op.MSTORE(0, 0x0),
54+
0x0,
55+
0x0,
56+
id="identity_1",
57+
),
58+
pytest.param(
59+
CallInputs(gas=0x30D40, value=0x13, args_offset=0x0),
60+
Bytecode(),
61+
0x0,
62+
0x0,
63+
id="identity_1_nonzero",
64+
),
65+
pytest.param(
66+
CallInputs(args_offset=0x25),
67+
Op.MSTORE(0, 0xF34578907F),
68+
0x0,
69+
0xF34578907F,
70+
id="identity_2",
71+
),
72+
pytest.param(
73+
CallInputs(args_offset=0x25),
74+
Op.MSTORE(0, 0xF34578907F),
75+
0x0,
76+
0xF34578907F,
77+
id="identity_3",
78+
),
79+
pytest.param(
80+
CallInputs(gas=0x64),
81+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
82+
0x0,
83+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
84+
id="identity_4",
85+
),
86+
pytest.param(
87+
CallInputs(gas=0x11),
88+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
89+
0x0,
90+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
91+
id="identity_4_gas17",
92+
),
93+
pytest.param(
94+
CallInputs(gas=0x12),
95+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
96+
0x0,
97+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
98+
id="identity_4_gas18",
99+
),
100+
pytest.param(
101+
CallInputs(gas=0x258, args_offset=0xF4240),
102+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
103+
0x0,
104+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
105+
id="identity_5",
106+
),
107+
pytest.param(
108+
CallInputs(gas=0x258, output_offset=0x40),
109+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
110+
+ Op.MSTORE(0x20, 0x1234),
111+
0x20,
112+
0x1234,
113+
id="identity_6",
114+
),
115+
],
116+
)
117+
def test_call_identity_precompile(
118+
state_test: StateTestFiller,
119+
pre: Alloc,
120+
inputs: CallInputs,
121+
store_values_code: Bytecode,
122+
stored_value_offset: int,
123+
expected: int,
124+
):
125+
"""Test identity precompile RETURNDATA is sized correctly based on the input size."""
126+
env = Environment()
127+
128+
account = pre.deploy_contract(
129+
store_values_code
130+
+ Op.SSTORE(
131+
2,
132+
Op.CALL(
133+
gas=inputs.gas,
134+
address=IDENTITY_PRECOMPILE_ADDRESS,
135+
value=inputs.value,
136+
args_offset=inputs.args_offset,
137+
args_size=inputs.args_size,
138+
output_offset=inputs.output_offset,
139+
output_size=inputs.output_size,
140+
),
141+
)
142+
+ Op.SSTORE(0, Op.MLOAD(stored_value_offset))
143+
+ Op.STOP,
144+
storage={0: 0xDEADBEEF, 2: 0xDEADBEEF},
145+
)
146+
147+
tx = Transaction(
148+
to=account,
149+
sender=pre.fund_eoa(),
150+
gas_limit=1_000_000,
151+
protected=True,
152+
)
153+
154+
post = {account: Account(storage={0: expected, 2: 0x1})}
155+
156+
state_test(env=env, pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)