From ae22ee0dcb3a0e0421db8e59898810ab11d24b7c Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Tue, 16 Apr 2024 14:20:05 +0000 Subject: [PATCH] new(tests): eip2537: incorrect subgroup tests --- .../eip2537_bls_12_381_precompiles/spec.py | 23 ++++++++++ .../test_bls12_g1add.py | 6 +-- .../test_bls12_g1msm.py | 4 +- .../test_bls12_g1mul.py | 18 ++++---- .../test_bls12_g2add.py | 26 +---------- .../test_bls12_g2msm.py | 17 +------ .../test_bls12_g2mul.py | 46 ++----------------- .../test_bls12_pairing.py | 8 ++++ 8 files changed, 54 insertions(+), 94 deletions(-) diff --git a/tests/prague/eip2537_bls_12_381_precompiles/spec.py b/tests/prague/eip2537_bls_12_381_precompiles/spec.py index e6c6313f003..c3cb45d07f0 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/spec.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/spec.py @@ -312,6 +312,29 @@ class Spec: # point at infinity in G2 INF_G2 = PointG2((0, 0), (0, 0)) + # Other test constants + # point not in subgroup in curve Fp + P1_NOT_IN_SUBGROUP = PointG1(0, 2) + P1_NOT_IN_SUBGROUP_TIMES_2 = PointG1(0, P - 2) + # point not in subgroup in curve Fp2 + P2_NOT_IN_SUBGROUP = PointG2( + (1, 1), + ( + 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 + 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 + ), + ) + P2_NOT_IN_SUBGROUP_TIMES_2 = PointG2( + ( + 0x919F97860ECC3E933E3477FCAC0E2E4FCC35A6E886E935C97511685232456263DEF6665F143CCCCB44C733333331553, # noqa: E501 + 0x18B4376B50398178FA8D78ED2654B0FFD2A487BE4DBE6B69086E61B283F4E9D58389CCCB8EDC99995718A66666661555, # noqa: E501 + ), + ( + 0x26898F699C4B07A405AB4183A10B47F923D1C0FDA1018682DD2CCC88968C1B90D44534D6B9270CF57F8DC6D4891678A, # noqa: E501 + 0x3270414330EAD5EC92219A03A24DFA059DBCBE610868BE1851CC13DAC447F60B40D41113FD007D3307B19ADD4B0F061, # noqa: E501 + ), + ) + # Pairing precompile results PAIRING_TRUE = int.to_bytes(1, length=32, byteorder="big") PAIRING_FALSE = int.to_bytes(0, length=32, byteorder="big") diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py index a650c34993a..4f4e8b62f10 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1add.py @@ -31,12 +31,12 @@ id="inf_plus_inf", ), pytest.param( - PointG1(0, 2) + PointG1(0, 2), - PointG1(0, Spec.P - 2), + Spec.P1_NOT_IN_SUBGROUP + Spec.P1_NOT_IN_SUBGROUP, + Spec.P1_NOT_IN_SUBGROUP_TIMES_2, id="not_in_subgroup_1", ), pytest.param( - PointG1(0, 2) + PointG1(0, Spec.P - 2), + Spec.P1_NOT_IN_SUBGROUP + Spec.P1_NOT_IN_SUBGROUP_TIMES_2, Spec.INF_G1, id="not_in_subgroup_2", ), diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py index cd6582a43dc..18aa9676b0f 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1msm.py @@ -36,12 +36,12 @@ id="max_discount_plus_1", ), pytest.param( - PointG1(0, 2) + Scalar(Spec.Q), + Spec.P1_NOT_IN_SUBGROUP + Scalar(Spec.Q), Spec.INF_G1, id="not_in_subgroup_1", ), pytest.param( - PointG1(0, Spec.P - 2) + Scalar(Spec.Q), + Spec.P1_NOT_IN_SUBGROUP_TIMES_2 + Scalar(Spec.Q), Spec.INF_G1, id="not_in_subgroup_2", ), diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1mul.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1mul.py index 1be2908330e..0fdbf22ada7 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1mul.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g1mul.py @@ -69,23 +69,23 @@ id="bls_g1mul_(Nq*P1)", ), pytest.param( - PointG1(0, 2) + Scalar(1), - PointG1(0, 2), + Spec.P1_NOT_IN_SUBGROUP + Scalar(1), + Spec.P1_NOT_IN_SUBGROUP, id="bls_g1mul_not_in_subgroup_1", ), pytest.param( - PointG1(0, Spec.P - 2) + Scalar(1), - PointG1(0, Spec.P - 2), + Spec.P1_NOT_IN_SUBGROUP_TIMES_2 + Scalar(1), + Spec.P1_NOT_IN_SUBGROUP_TIMES_2, id="bls_g1mul_not_in_subgroup_2", ), pytest.param( - PointG1(0, Spec.P - 2) + Scalar(Spec.Q), - PointG1(0, 2), + Spec.P1_NOT_IN_SUBGROUP_TIMES_2 + Scalar(Spec.Q), + Spec.P1_NOT_IN_SUBGROUP, id="bls_g1mul_not_in_subgroup_times_q", ), pytest.param( - PointG1(0, 2) + Scalar(Spec.Q), - PointG1(0, Spec.P - 2), + Spec.P1_NOT_IN_SUBGROUP + Scalar(Spec.Q), + Spec.P1_NOT_IN_SUBGROUP_TIMES_2, id="bls_g1mul_not_in_subgroup_times_q_2", ), ], @@ -228,4 +228,4 @@ def test_call_types( pre=pre, tx=tx, post=post, - ) \ No newline at end of file + ) diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py index 71062effab1..02eae0735fd 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2add.py @@ -26,30 +26,8 @@ vectors_from_file("add_G2_bls.json") + [ pytest.param( - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ) - + PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ), - PointG2( - ( - 0x919F97860ECC3E933E3477FCAC0E2E4FCC35A6E886E935C97511685232456263DEF6665F143CCCCB44C733333331553, # noqa: E501 - 0x18B4376B50398178FA8D78ED2654B0FFD2A487BE4DBE6B69086E61B283F4E9D58389CCCB8EDC99995718A66666661555, # noqa: E501 - ), - ( - 0x26898F699C4B07A405AB4183A10B47F923D1C0FDA1018682DD2CCC88968C1B90D44534D6B9270CF57F8DC6D4891678A, # noqa: E501 - 0x3270414330EAD5EC92219A03A24DFA059DBCBE610868BE1851CC13DAC447F60B40D41113FD007D3307B19ADD4B0F061, # noqa: E501 - ), - ), + Spec.P2_NOT_IN_SUBGROUP + Spec.P2_NOT_IN_SUBGROUP, + Spec.P2_NOT_IN_SUBGROUP_TIMES_2, id="not_in_subgroup", ), ], diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py index 6734118bd91..7445c06f3d3 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2msm.py @@ -26,21 +26,8 @@ vectors_from_file("multiexp_G2_bls.json") + [ pytest.param( - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ) - + Scalar(1), - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ), + Spec.P2_NOT_IN_SUBGROUP + Scalar(1), + Spec.P2_NOT_IN_SUBGROUP, id="bls_g2mul_not_in_subgroup", ), ], diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2mul.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2mul.py index de57ae6bbf7..a596ad3f5bf 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2mul.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_g2mul.py @@ -80,53 +80,17 @@ id="bls_g2mul_(Nq*P2)", ), pytest.param( - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ) - + Scalar(1), - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ), + Spec.P2_NOT_IN_SUBGROUP + Scalar(1), + Spec.P2_NOT_IN_SUBGROUP, id="bls_g2mul_not_in_subgroup", ), pytest.param( - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ) - + Scalar(2), - PointG2( - ( - 0x919F97860ECC3E933E3477FCAC0E2E4FCC35A6E886E935C97511685232456263DEF6665F143CCCCB44C733333331553, # noqa: E501 - 0x18B4376B50398178FA8D78ED2654B0FFD2A487BE4DBE6B69086E61B283F4E9D58389CCCB8EDC99995718A66666661555, # noqa: E501 - ), - ( - 0x26898F699C4B07A405AB4183A10B47F923D1C0FDA1018682DD2CCC88968C1B90D44534D6B9270CF57F8DC6D4891678A, # noqa: E501 - 0x3270414330EAD5EC92219A03A24DFA059DBCBE610868BE1851CC13DAC447F60B40D41113FD007D3307B19ADD4B0F061, # noqa: E501 - ), - ), + Spec.P2_NOT_IN_SUBGROUP + Scalar(2), + Spec.P2_NOT_IN_SUBGROUP_TIMES_2, id="bls_g2mul_not_in_subgroup_times_2", ), pytest.param( - PointG2( - (1, 1), - ( - 0x17FAA6201231304F270B858DAD9462089F2A5B83388E4B10773ABC1EEF6D193B9FCE4E8EA2D9D28E3C3A315AA7DE14CA, # noqa: E501 - 0xCC12449BE6AC4E7F367E7242250427C4FB4C39325D3164AD397C1837A90F0EA1A534757DF374DD6569345EB41ED76E, # noqa: E501 - ), - ) - + Scalar(Spec.Q), + Spec.P2_NOT_IN_SUBGROUP + Scalar(Spec.Q), PointG2( ( 0x1C3ABBB8255E4DE6225C5A5710816BB5767D9B3188472867BB5D09144DFACC2E192C24E58C70BDBAC987BE8F61F15F8, # noqa: E501 diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py index 50a3682c941..413843ada86 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py @@ -93,6 +93,14 @@ def test_valid( (Spec.INF_G1 + Spec.INF_G2) * 1000 + PointG1(Spec.P, 0) + Spec.INF_G2, id="multi_inf_plus_g1_P_g2_inf_1", ), + pytest.param( + Spec.P1_NOT_IN_SUBGROUP + Spec.INF_G2, + id="P1_not_in_subgroup", + ), + pytest.param( + Spec.INF_G1 + Spec.P2_NOT_IN_SUBGROUP, + id="P2_not_in_subgroup", + ), # Input length tests can be found in ./test_bls12_variable_length_input_contracts.py ], )