Skip to content

Commit 4d73839

Browse files
authored
feat(tests): add test cases for P256 with zero h, r, s (#2216)
Add better test inputs for the `p256verify` precompile where at least `r` or `s` is `0 mod N`. There test cases represent invalid inputs but in some category of incorrect implementations have chance to be positively verified.
1 parent 45ba0a8 commit 4d73839

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,44 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
221221
Spec.H0 + Spec.R0 + S(Spec.N) + Spec.X0 + Spec.Y0,
222222
id="s_eq_to_n",
223223
),
224+
# If checks for r, s, and point-at-infinity are missing, the s=0 zeros
225+
# both u1 and u2, so the computed R is the point at infinity,
226+
# and the signature may be considered valid in such implementation.
227+
pytest.param(
228+
Spec.H0 + R(0) + S(0) + X(Spec.Gx) + Y(Spec.Gy),
229+
id="r_0_s_0",
230+
),
231+
pytest.param(
232+
Spec.H0 + R(0) + S(Spec.N) + X(Spec.Gx) + Y(Spec.Gy),
233+
id="r_0_s_N",
234+
),
235+
pytest.param(
236+
Spec.H0 + R(Spec.N) + S(0) + X(Spec.Gx) + Y(Spec.Gy),
237+
id="r_N_s_0",
238+
),
239+
pytest.param(
240+
Spec.H0 + R(Spec.N) + S(Spec.N) + X(Spec.Gx) + Y(Spec.Gy),
241+
id="r_N_s_N",
242+
),
243+
# If checks for r and point-at-infinity are missing, the h=0 and r=0
244+
# zero both u1 and u2, so the computed R is the point at infinity,
245+
# and the signature may be considered valid in such implementation.
246+
pytest.param(
247+
H(0) + R(0) + Spec.S0 + X(Spec.Gx) + Y(Spec.Gy),
248+
id="hash_0_r_0",
249+
),
250+
pytest.param(
251+
H(0) + R(Spec.N) + Spec.S0 + X(Spec.Gx) + Y(Spec.Gy),
252+
id="hash_0_r_N",
253+
),
254+
pytest.param(
255+
H(Spec.N) + R(0) + Spec.S0 + X(Spec.Gx) + Y(Spec.Gy),
256+
id="hash_N_r_0",
257+
),
258+
pytest.param(
259+
H(Spec.N) + R(Spec.N) + Spec.S0 + X(Spec.Gx) + Y(Spec.Gy),
260+
id="hash_N_r_N",
261+
),
224262
pytest.param(
225263
Spec.H0 + R(Spec.Gx) + S((2**256 - 1) % Spec.N) + X(Spec.Gx) + Y(Spec.Gy),
226264
id="s_max_mod_N",

0 commit comments

Comments
 (0)