Skip to content

Commit 3bb2921

Browse files
author
Stuart Reed
committed
Add identity tests for CALL
1 parent acd4b12 commit 3bb2921

File tree

7 files changed

+202
-974
lines changed

7 files changed

+202
-974
lines changed

converted-ethereum-tests.txt

Lines changed: 0 additions & 4 deletions
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

docs/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ The following changes may be potentially breaking (all clients were tested with
9090
- ✨ Add gas cost of delegation access in CALL opcode ([#1208](https://github.com/ethereum/execution-spec-tests/pull/1208)).
9191
- ✨ Add EIP-7698 failed nonce and short data tests ([#1211](https://github.com/ethereum/execution-spec-tests/pull/1211)).
9292
- ✨ 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)).
93-
- ✨ Add test cases for EIP-152 Blake2 and Identity precompiles ([#1244](https://github.com/ethereum/execution-spec-tests/pull/1244)).
9493

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

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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=0x0,
33+
args_size=0x20,
34+
ret_offset=0x0,
35+
ret_size=0x20,
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.ret_offset = ret_offset
43+
self.ret_size = ret_size
44+
45+
46+
@pytest.mark.valid_from("Byzantium")
47+
@pytest.mark.parametrize(
48+
[
49+
"inputs",
50+
"store_values_code",
51+
"stored_value_offset",
52+
"expected_stored_value",
53+
"expected_call_result",
54+
],
55+
[
56+
pytest.param(CallInputs(gas=0xFF), Op.MSTORE(0, 0x1), 0x0, 0x1, 0x1, id="identity_0"),
57+
pytest.param(
58+
CallInputs(args_size=0x0),
59+
Op.MSTORE(0, 0x0),
60+
0x0,
61+
0x0,
62+
0x1,
63+
id="identity_1",
64+
),
65+
pytest.param(
66+
CallInputs(gas=0x30D40, value=0x13, args_size=0x0),
67+
Bytecode(),
68+
0x0,
69+
0x0,
70+
0x1,
71+
id="identity_1_nonzero",
72+
),
73+
pytest.param(
74+
CallInputs(args_size=0x25),
75+
Op.MSTORE(0, 0xF34578907F),
76+
0x0,
77+
0xF34578907F,
78+
0x1,
79+
id="identity_2",
80+
),
81+
pytest.param(
82+
CallInputs(args_size=0x25),
83+
Op.MSTORE(0, 0xF34578907F),
84+
0x0,
85+
0xF34578907F,
86+
0x1,
87+
id="identity_3",
88+
),
89+
pytest.param(
90+
CallInputs(gas=0x64),
91+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
92+
0x0,
93+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
94+
0x1,
95+
id="identity_4",
96+
),
97+
pytest.param(
98+
CallInputs(gas=0x11),
99+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
100+
0x0,
101+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
102+
0x0,
103+
id="identity_4_gas17",
104+
),
105+
pytest.param(
106+
CallInputs(gas=0x12),
107+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
108+
0x0,
109+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
110+
0x1,
111+
id="identity_4_gas18",
112+
),
113+
pytest.param(
114+
CallInputs(gas=0x258, args_size=0xF4240),
115+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),
116+
0x0,
117+
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
118+
0xDEADBEEF,
119+
id="identity_5",
120+
),
121+
pytest.param(
122+
CallInputs(gas=0x258, ret_size=0x40),
123+
Op.MSTORE(0, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
124+
+ Op.MSTORE(0x20, 0x1234),
125+
0x20,
126+
0x1234,
127+
0x1,
128+
id="identity_6",
129+
),
130+
],
131+
)
132+
def test_call_identity_precompile(
133+
state_test: StateTestFiller,
134+
pre: Alloc,
135+
inputs: CallInputs,
136+
store_values_code: Bytecode,
137+
stored_value_offset: int,
138+
expected_stored_value: int,
139+
expected_call_result: int,
140+
):
141+
"""Test identity precompile RETURNDATA is sized correctly based on the input size."""
142+
env = Environment()
143+
144+
account = pre.deploy_contract(
145+
store_values_code
146+
+ Op.SSTORE(
147+
2,
148+
Op.CALL(
149+
gas=inputs.gas,
150+
address=IDENTITY_PRECOMPILE_ADDRESS,
151+
value=inputs.value,
152+
args_offset=inputs.args_offset,
153+
args_size=inputs.args_size,
154+
ret_offset=inputs.ret_offset,
155+
ret_size=inputs.ret_size,
156+
),
157+
)
158+
+ Op.SSTORE(0, Op.MLOAD(stored_value_offset))
159+
+ Op.STOP,
160+
storage={0: 0xDEADBEEF, 2: 0xDEADBEEF},
161+
)
162+
163+
tx = Transaction(
164+
to=account,
165+
sender=pre.fund_eoa(),
166+
gas_limit=1_000_000,
167+
protected=True,
168+
)
169+
170+
post = {account: Account(storage={0: expected_stored_value, 2: expected_call_result})}
171+
172+
state_test(env=env, pre=pre, post=post, tx=tx)

tests/frontier/precompiles/test_identity_returndata_size.py renamed to tests/frontier/precompiles/test_identity_returndatasize.py

File renamed without changes.

0 commit comments

Comments
 (0)