Skip to content

Commit

Permalink
chore(tests): EIP-2537: remove BLS MUL precompiles (MVP) (#1039)
Browse files Browse the repository at this point in the history
* 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.

* fix(forks): Remove BLS multiplication precompiles from Prague

---------

Co-authored-by: Mario Vega <[email protected]>
  • Loading branch information
chfast and marioevz authored Dec 20, 2024
1 parent 7bb9588 commit 49c766f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
18 changes: 8 additions & 10 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
16 changes: 6 additions & 10 deletions tests/prague/eip2537_bls_12_381_precompiles/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[""]),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=[""]),
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 49c766f

Please sign in to comment.