|
14 | 14 | from ethereum_test_tools import Opcodes as Op
|
15 | 15 |
|
16 | 16 | 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 |
18 | 18 |
|
19 | 19 | REFERENCE_SPEC_GIT_PATH = ref_spec_7951.git_path
|
20 | 20 | REFERENCE_SPEC_VERSION = ref_spec_7951.version
|
|
30 | 30 | )
|
31 | 31 | @pytest.mark.parametrize("precompile_address", [Spec.P256VERIFY], ids=[""])
|
32 | 32 | @pytest.mark.eip_checklist("new_precompile/test/call_contexts/normal")
|
| 33 | +@pytest.mark.eip_checklist("new_precompile/test/inputs/valid") |
33 | 34 | def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transaction):
|
34 | 35 | """Test P256Verify precompile."""
|
35 | 36 | state_test(env=Environment(), pre=pre, post=post, tx=tx)
|
36 | 37 |
|
37 | 38 |
|
| 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 | + |
38 | 107 | @pytest.mark.parametrize(
|
39 | 108 | "input_data,expected_output,precompile_gas_modifier,call_succeeds",
|
40 | 109 | [
|
|
0 commit comments