Skip to content

Commit bf73eb7

Browse files
feat: add curve params and negative tests
1 parent 64451b4 commit bf73eb7

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

tests/osaka/eip7951_p256verify_precompiles/spec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class Spec:
9393
# Gas constants
9494
P256VERIFY_GAS = 3450
9595

96+
# Curve Parameters
97+
P = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF ## Base field modulus
98+
A = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC ## Curve Coefficient
99+
B = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B ## Curve Coefficient
100+
N = 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551 ## Subgroup Order
101+
96102
# Other constants
97103
SUCCESS_RETURN_VALUE = b"\x01".rjust(32, b"\x00")
98104
INVALID_RETURN_VALUE = b""

tests/osaka/eip7951_p256verify_precompiles/test_p256verify_precompile_module.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ethereum_test_tools import Opcodes as Op
1515

1616
from .helpers import vectors_from_file
17-
from .spec import Spec, ref_spec_7951
17+
from .spec import H, R, S, Spec, X, Y, ref_spec_7951
1818

1919
REFERENCE_SPEC_GIT_PATH = ref_spec_7951.git_path
2020
REFERENCE_SPEC_VERSION = ref_spec_7951.version
@@ -30,11 +30,80 @@
3030
)
3131
@pytest.mark.parametrize("precompile_address", [Spec.P256VERIFY], ids=[""])
3232
@pytest.mark.eip_checklist("new_precompile/test/call_contexts/normal")
33+
@pytest.mark.eip_checklist("new_precompile/test/inputs/valid")
3334
def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transaction):
3435
"""Test P256Verify precompile."""
3536
state_test(env=Environment(), pre=pre, post=post, tx=tx)
3637

3738

39+
@pytest.mark.parametrize(
40+
"input_data",
41+
[
42+
pytest.param(b"", id="zero_length_input"),
43+
pytest.param(
44+
b"\x00" + Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Spec.Y0,
45+
id="input_too_long",
46+
),
47+
pytest.param(
48+
(Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Spec.Y0)[:-1],
49+
id="input_too_short",
50+
),
51+
pytest.param(
52+
H(0) + R(0) + S(0) + X(0) + Y(0),
53+
id="input_all_zeros",
54+
),
55+
pytest.param(
56+
Spec.H0 + R(0) + Spec.S0 + Spec.X0 + Spec.Y0,
57+
id="r_eq_to_zero",
58+
),
59+
pytest.param(
60+
Spec.H0 + R(Spec.N) + Spec.S0 + Spec.X0 + Spec.Y0,
61+
id="r_eq_to_n",
62+
),
63+
pytest.param(
64+
Spec.H0 + Spec.R0 + S(0) + Spec.X0 + Spec.Y0,
65+
id="s_eq_to_zero",
66+
),
67+
pytest.param(
68+
Spec.H0 + Spec.R0 + S(Spec.N) + Spec.X0 + Spec.Y0,
69+
id="s_eq_to_n",
70+
),
71+
pytest.param(
72+
Spec.H0 + Spec.R0 + Spec.S0 + X(Spec.P) + Spec.Y0,
73+
id="x_eq_to_p",
74+
),
75+
pytest.param(
76+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + Y(Spec.P),
77+
id="y_eq_to_p",
78+
),
79+
pytest.param(
80+
Spec.H0 + Spec.R0 + Spec.S0 + X(0) + Y(0),
81+
id="point_on_infinity",
82+
),
83+
pytest.param(
84+
Spec.H0 + Spec.R0 + Spec.S0 + (Spec.X0 + 1) + Spec.Y0,
85+
id="point_not_on_curve_x",
86+
),
87+
pytest.param(
88+
Spec.H0 + Spec.R0 + Spec.S0 + Spec.X0 + (Spec.Y0 + 1),
89+
id="point_not_on_curve_y",
90+
),
91+
],
92+
)
93+
@pytest.mark.parametrize("expected_output", [Spec.INVALID_RETURN_VALUE], ids=[""])
94+
@pytest.mark.parametrize("precompile_address", [Spec.P256VERIFY], ids=[""])
95+
@pytest.mark.eip_checklist("new_precompile/test/inputs/all_zeros")
96+
@pytest.mark.eip_checklist("new_precompile/test/inputs/invalid")
97+
@pytest.mark.eip_checklist("new_precompile/test/inputs/invalid/crypto")
98+
@pytest.mark.eip_checklist("new_precompile/test/inputs/invalid/corrupted")
99+
@pytest.mark.eip_checklist("new_precompile/test/input_lengths/static/correct")
100+
@pytest.mark.eip_checklist("new_precompile/test/input_lengths/static/too_short")
101+
@pytest.mark.eip_checklist("new_precompile/test/input_lengths/static/too_long")
102+
def test_invalid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transaction):
103+
"""Negative tests for the P256VERIFY precompile."""
104+
state_test(env=Environment(), pre=pre, post=post, tx=tx)
105+
106+
38107
@pytest.mark.parametrize(
39108
"input_data,expected_output,precompile_gas_modifier,call_succeeds",
40109
[

0 commit comments

Comments
 (0)