Skip to content

Commit 7882fc1

Browse files
committed
Add identity returndata tests and additional blake2 test cases
1 parent c38722f commit 7882fc1

File tree

3 files changed

+546
-29
lines changed

3 files changed

+546
-29
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""abstract: Test identity precompile output size."""
2+
3+
import pytest
4+
5+
from ethereum_test_tools import (
6+
Account,
7+
Alloc,
8+
Environment,
9+
StateTestFiller,
10+
Transaction,
11+
)
12+
from ethereum_test_tools import Opcodes as Op
13+
14+
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-152.md"
15+
REFERENCE_SPEC_VERSION = "5510973b40973b6aa774f04c9caba823c8ff8460"
16+
17+
IDENTITY_PRECOMPILE_ADDRESS = 0x04
18+
19+
20+
@pytest.mark.valid_from("Byzantium")
21+
@pytest.mark.parametrize(
22+
["args_size", "output_size", "returndatasize"],
23+
[
24+
pytest.param(16, 32, 16, id="output_16"),
25+
pytest.param(32, 16, 32, id="output_32"),
26+
],
27+
)
28+
def test_identity_precompile_returndata(
29+
state_test: StateTestFiller,
30+
pre: Alloc,
31+
args_size: int,
32+
output_size: int,
33+
returndatasize: int,
34+
):
35+
"""Test identity precompile RETURNDATA is sized correctly based on the input size."""
36+
env = Environment()
37+
38+
account = pre.deploy_contract(
39+
Op.MSTORE(0, 0)
40+
+ Op.GAS
41+
+ Op.MSTORE(0, 0x112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00)
42+
+ Op.CALL(
43+
address=IDENTITY_PRECOMPILE_ADDRESS,
44+
args_offset=0,
45+
args_size=args_size,
46+
output_offset=0x10,
47+
output_size=output_size,
48+
)
49+
+ Op.POP
50+
+ Op.SSTORE(0, Op.RETURNDATASIZE)
51+
+ Op.STOP,
52+
storage={0: 0xDEADBEEF},
53+
)
54+
55+
tx = Transaction(
56+
to=account,
57+
sender=pre.fund_eoa(),
58+
gas_limit=1_000_000,
59+
protected=True,
60+
)
61+
62+
# Delegatecall to the precompile will fail and consume the specified gas amount
63+
# Otherwise delegatecall will succeed and no gas will be consumed
64+
post = {account: Account(storage={0: returndatasize})}
65+
66+
state_test(env=env, pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)