From 03595278ddc4b7c75263245001e97b5feb9fe4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 19 Dec 2024 20:49:41 +0100 Subject: [PATCH 1/2] chore(tests): remove BLS MUL precompiles (MVP) This is a set of minimal changes that removes the BLS G1/G2 MUL precompiles (EIP-2537). All existing tests for MULs are redirected to MSMs because these are ABI and gas equivalent (main reason for the spec change). You can also notice that we had more tests for MULs than for MSMs meaning there were test cases missing for MSMs. I have filled these tests with modified evmone. --- .../eip2537_bls_12_381_precompiles/spec.py | 16 ++++++---------- .../test_bls12_g1mul.py | 2 +- .../test_bls12_g2mul.py | 2 +- .../test_bls12_precompiles_before_fork.py | 10 ---------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/prague/eip2537_bls_12_381_precompiles/spec.py b/tests/prague/eip2537_bls_12_381_precompiles/spec.py index 1e3bc044ba..122dfe50da 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/spec.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/spec.py @@ -116,14 +116,12 @@ class Spec: # Addresses G1ADD = 0x0B - G1MUL = 0x0C - G1MSM = 0x0D - G2ADD = 0x0E - G2MUL = 0x0F - G2MSM = 0x10 - PAIRING = 0x11 - MAP_FP_TO_G1 = 0x12 - MAP_FP2_TO_G2 = 0x13 + G1MSM = 0x0C + G2ADD = 0x0D + G2MSM = 0x0E + PAIRING = 0x0F + MAP_FP_TO_G1 = 0x10 + MAP_FP2_TO_G2 = 0x11 # Gas constants G1ADD_GAS = 375 @@ -288,10 +286,8 @@ def pairing_gas(input_length: int) -> int: GAS_CALCULATION_FUNCTION_MAP = { Spec.G1ADD: lambda _: Spec.G1ADD_GAS, - Spec.G1MUL: lambda _: Spec.G1MUL_GAS, Spec.G1MSM: msm_gas_func_gen(BLS12Group.G1, len(PointG1() + Scalar()), Spec.G1MUL_GAS), Spec.G2ADD: lambda _: Spec.G2ADD_GAS, - Spec.G2MUL: lambda _: Spec.G2MUL_GAS, Spec.G2MSM: msm_gas_func_gen(BLS12Group.G2, len(PointG2() + Scalar()), Spec.G2MUL_GAS), Spec.PAIRING: pairing_gas, Spec.MAP_FP_TO_G1: lambda _: Spec.MAP_FP_TO_G1_GAS, 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 7744137acd..b2a3277f91 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 @@ -17,7 +17,7 @@ pytestmark = [ pytest.mark.valid_from("Prague"), - pytest.mark.parametrize("precompile_address", [Spec.G1MUL], ids=[""]), + pytest.mark.parametrize("precompile_address", [Spec.G1MSM], ids=[""]), ] 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 f1ebe2873d..299d58d308 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 @@ -17,7 +17,7 @@ pytestmark = [ pytest.mark.valid_from("Prague"), - pytest.mark.parametrize("precompile_address", [Spec.G2MUL], ids=[""]), + pytest.mark.parametrize("precompile_address", [Spec.G2MSM], ids=[""]), ] diff --git a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_precompiles_before_fork.py b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_precompiles_before_fork.py index cf0d6d7662..130f0c7c70 100644 --- a/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_precompiles_before_fork.py +++ b/tests/prague/eip2537_bls_12_381_precompiles/test_bls12_precompiles_before_fork.py @@ -29,11 +29,6 @@ Spec.INF_G1 + Scalar(0), id="G1MSM", ), - pytest.param( - Spec.G1MUL, - Spec.INF_G1 + Scalar(0), - id="G1MUL", - ), pytest.param( Spec.G2ADD, Spec.INF_G2 + Spec.INF_G2, @@ -44,11 +39,6 @@ Spec.INF_G2 + Scalar(0), id="G2MSM", ), - pytest.param( - Spec.G2MUL, - Spec.INF_G2 + Scalar(0), - id="G2MUL", - ), pytest.param( Spec.PAIRING, Spec.INF_G1 + Spec.INF_G2, From 3ebe68f72ae2659f8cf890c82fd672cd9556a4c9 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Fri, 20 Dec 2024 15:41:02 +0000 Subject: [PATCH 2/2] fix(forks): Remove BLS multiplication precompiles from Prague --- src/ethereum_test_forks/forks/forks.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ethereum_test_forks/forks/forks.py b/src/ethereum_test_forks/forks/forks.py index 523983ce2c..c3c868fd8d 100644 --- a/src/ethereum_test_forks/forks/forks.py +++ b/src/ethereum_test_forks/forks/forks.py @@ -1133,16 +1133,14 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address] At Prague, pre-compile for BLS operations are added: G1ADD = 0x0B - G1MUL = 0x0C - G1MSM = 0x0D - G2ADD = 0x0E - G2MUL = 0x0F - G2MSM = 0x10 - PAIRING = 0x11 - MAP_FP_TO_G1 = 0x12 - MAP_FP2_TO_G2 = 0x13 - """ - return list(Address(i) for i in range(0xB, 0x13 + 1)) + super(Prague, cls).precompiles( + G1MSM = 0x0C + G2ADD = 0x0D + G2MSM = 0x0E + PAIRING = 0x0F + MAP_FP_TO_G1 = 0x10 + MAP_FP2_TO_G2 = 0x11 + """ + return list(Address(i) for i in range(0xB, 0x11 + 1)) + super(Prague, cls).precompiles( block_number, timestamp )