Skip to content

Commit 454978e

Browse files
committed
new(tests): EIP-2537 mainnet tests
1 parent 8413847 commit 454978e

2 files changed

Lines changed: 98 additions & 3 deletions

File tree

tests/prague/eip2537_bls_12_381_precompiles/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
from ethereum_test_forks import Fork
78
from ethereum_test_tools import EOA, Address, Alloc, Bytecode, Storage, Transaction, keccak256
89
from ethereum_test_tools import Opcodes as Op
910

@@ -155,7 +156,7 @@ def call_contract_address(pre: Alloc, call_contract_code: Bytecode) -> Address:
155156
@pytest.fixture
156157
def sender(pre: Alloc) -> EOA:
157158
"""Sender of the transaction."""
158-
return pre.fund_eoa(1_000_000_000_000_000_000)
159+
return pre.fund_eoa()
159160

160161

161162
@pytest.fixture
@@ -169,9 +170,12 @@ def post(call_contract_address: Address, call_contract_post_storage: Storage):
169170

170171

171172
@pytest.fixture
172-
def tx_gas_limit(precompile_gas: int) -> int:
173+
def tx_gas_limit(fork: Fork, input_data: bytes, precompile_gas: int) -> int:
173174
"""Transaction gas limit used for the test (Can be overridden in the test)."""
174-
return 10_000_000 + precompile_gas
175+
intrinsic_gas_cost_calc = fork.transaction_intrinsic_cost_calculator()
176+
intrinsic_gas_cost = intrinsic_gas_cost_calc(calldata=input_data)
177+
extra_gas = 100_000 # Memory expansion, sstores, return data, keccak, etc.
178+
return intrinsic_gas_cost + extra_gas + precompile_gas
175179

176180

177181
@pytest.fixture
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
abstract: Tests all precompiles of [EIP-2537: Precompile for BLS12-381 curve operations](https://eips.ethereum.org/EIPS/eip-2537)
3+
Tests all precompiles of [EIP-2537: Precompile for BLS12-381 curve operations](https://eips.ethereum.org/EIPS/eip-2537).
4+
""" # noqa: E501
5+
6+
import pytest
7+
8+
from ethereum_test_tools import Alloc, Environment, StateTestFiller, Transaction
9+
10+
from .spec import FP, FP2, Scalar, Spec, ref_spec_2537
11+
12+
REFERENCE_SPEC_GIT_PATH = ref_spec_2537.git_path
13+
REFERENCE_SPEC_VERSION = ref_spec_2537.version
14+
15+
16+
@pytest.mark.parametrize(
17+
"precompile_address,input_data,expected_output,vector_gas_value",
18+
[
19+
pytest.param(
20+
Spec.G1ADD,
21+
Spec.G1 + Spec.INF_G1,
22+
Spec.G1,
23+
None,
24+
id="G1ADD",
25+
),
26+
pytest.param(
27+
Spec.G1MSM,
28+
Spec.G1 + Scalar(1) + Spec.INF_G1 + Scalar(1),
29+
Spec.G1,
30+
None,
31+
id="G1MSM",
32+
),
33+
pytest.param(
34+
Spec.G2ADD,
35+
Spec.G2 + Spec.INF_G2,
36+
Spec.G2,
37+
None,
38+
id="G2ADD",
39+
),
40+
pytest.param(
41+
Spec.G2MSM,
42+
Spec.G2 + Scalar(1) + Spec.INF_G2 + Scalar(1),
43+
Spec.G2,
44+
None,
45+
id="G2MSM",
46+
),
47+
pytest.param(
48+
Spec.PAIRING,
49+
Spec.G1 + Spec.INF_G2,
50+
Spec.PAIRING_TRUE,
51+
None,
52+
id="PAIRING",
53+
),
54+
pytest.param(
55+
Spec.MAP_FP_TO_G1,
56+
FP(
57+
799950832265136997107648781861994410980648980263584507133499364313075404851459407870655748616451882783569609925573 # noqa: E501
58+
),
59+
Spec.INF_G1,
60+
None,
61+
id="fp_map_to_inf",
62+
),
63+
pytest.param(
64+
Spec.MAP_FP2_TO_G2,
65+
FP2(
66+
(
67+
3510328712861478240121438855244276237335901234329585006107499559909114695366216070652508985150831181717984778988906, # noqa: E501
68+
2924545590598115509050131525615277284817672420174395176262156166974132393611647670391999011900253695923948997972401, # noqa: E501
69+
)
70+
),
71+
Spec.INF_G2,
72+
None,
73+
id="fp_map_to_inf",
74+
),
75+
],
76+
)
77+
@pytest.mark.valid_at("Prague")
78+
@pytest.mark.mainnet
79+
def test_eip_2537(
80+
state_test: StateTestFiller,
81+
pre: Alloc,
82+
post: dict,
83+
tx: Transaction,
84+
):
85+
"""Test the all precompiles of EIP-2537."""
86+
state_test(
87+
env=Environment(),
88+
pre=pre,
89+
tx=tx,
90+
post=post,
91+
)

0 commit comments

Comments
 (0)