Skip to content

Commit b10bd8f

Browse files
committed
Add identity returndata tests and additional blake2 test cases
1 parent 3dc21a8 commit b10bd8f

File tree

3 files changed

+548
-29
lines changed

3 files changed

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

0 commit comments

Comments
 (0)