Skip to content

Commit 80f272b

Browse files
authored
feat(tests): add test cases for P256 for r,s above N (#2230)
Add new test cases for the `p256verify` precompile where the input elements `r` or `s`are out of range by being greater than `N`. Moreover, the equivalent signatures taking `r % N` or `s % N` are valid. These have chance to detect implementations which don't perform proper range checks and pass `r` or `s` to Montgomery form.
1 parent a001e87 commit 80f272b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
232232
Spec.H0 + R(Spec.N) + Spec.S0 + Spec.X0 + Spec.Y0,
233233
id="r_eq_to_n",
234234
),
235+
pytest.param(
236+
Spec.H1 + R(Spec.R1.value + Spec.N) + Spec.S1 + Spec.X1 + Spec.Y1,
237+
id="r_above_n",
238+
),
235239
pytest.param(
236240
Spec.H0 + R(2**256 - 1) + Spec.S0 + Spec.X0 + Spec.Y0,
237241
id="r_max",
@@ -286,6 +290,18 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
286290
Spec.H0 + R(Spec.Gx) + S((2**256 - 1) % Spec.N) + X(Spec.Gx) + Y(Spec.Gy),
287291
id="s_max_mod_N",
288292
),
293+
pytest.param(
294+
H(Spec.N + 1 - Spec.Gx) + R(Spec.Gx) + S(Spec.N + 1) + X(Spec.Gx) + Y(Spec.Gy),
295+
id="s_N_plus_1",
296+
),
297+
pytest.param(
298+
H(((2**256 - 1) % Spec.N) - Spec.Gx + Spec.N)
299+
+ R(Spec.Gx)
300+
+ S(2**256 - 1)
301+
+ X(Spec.Gx)
302+
+ Y(Spec.Gy),
303+
id="s_max",
304+
),
289305
pytest.param(
290306
Spec.H0 + Spec.R0 + Spec.S0 + X(Spec.P) + Spec.Y0,
291307
id="x_eq_to_p",

0 commit comments

Comments
 (0)