From 1e3d86561650756f38751ceff741064ac747e1dd Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 19 Dec 2024 15:09:14 -0800 Subject: [PATCH] remove MUL per https://github.com/ethereum/EIPs/pull/8945 Signed-off-by: garyschulte --- .../besu/config/GenesisReaderTest.java | 7 ++-- .../hyperledger/besu/datatypes/Address.java | 18 ++++------ .../BLS12G1MulPrecompiledContract.java | 35 ------------------- .../BLS12G2MulPrecompiledContract.java | 35 ------------------- .../MainnetPrecompiledContracts.java | 2 -- .../BLS12G1MulPrecompiledContractTest.java | 8 +++-- .../BLS12G2MulPrecompiledContractTest.java | 8 +++-- .../besu/evm/precompile/Benchmarks.java | 33 ----------------- 8 files changed, 22 insertions(+), 124 deletions(-) delete mode 100644 evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContract.java delete mode 100644 evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContract.java diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java index eab6dfac734..d49c9f6d338 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisReaderTest.java @@ -41,7 +41,7 @@ public void readGenesisFromObjectNode() { final var configNode = mapper.createObjectNode(); configNode.put("londonBlock", 1); final var allocNode = mapper.createObjectNode(); - allocNode.put(Address.BLS12_G2MUL.toUnprefixedHexString(), generateAllocation(Wei.ONE)); + allocNode.put(Address.BLS12_G2MULTIEXP.toUnprefixedHexString(), generateAllocation(Wei.ONE)); final var rootNode = mapper.createObjectNode(); rootNode.put("chainId", 12); rootNode.put(CONFIG_FIELD, configNode); @@ -52,7 +52,8 @@ public void readGenesisFromObjectNode() { assertThat(genesisReader.getRoot().has(ALLOCATION_FIELD)).isFalse(); assertThat(genesisReader.getConfig().get("londonblock").asInt()).isEqualTo(1); assertThat(genesisReader.streamAllocations()) - .containsExactly(new GenesisAccount(Address.BLS12_G2MUL, 0, Wei.ONE, null, Map.of(), null)); + .containsExactly( + new GenesisAccount(Address.BLS12_G2MULTIEXP, 0, Wei.ONE, null, Map.of(), null)); } @Test @@ -60,7 +61,7 @@ public void readGenesisFromObjectDoesNotModifyObjectNodeArg() { final var configNode = mapper.createObjectNode(); configNode.put("londonBlock", 1); final var allocNode = mapper.createObjectNode(); - allocNode.put(Address.BLS12_G2MUL.toUnprefixedHexString(), generateAllocation(Wei.ONE)); + allocNode.put(Address.BLS12_G2MULTIEXP.toUnprefixedHexString(), generateAllocation(Wei.ONE)); final var rootNode = mapper.createObjectNode(); rootNode.put("chainId", 12); rootNode.put(CONFIG_FIELD, configNode); diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java index 1f21dd2fd85..e6a80b2f6b2 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java @@ -72,29 +72,23 @@ public class Address extends DelegatingBytes { /** The constant BLS12_G1ADD. */ public static final Address BLS12_G1ADD = Address.precompiled(0xB); - /** The constant BLS12_G1MUL. */ - public static final Address BLS12_G1MUL = Address.precompiled(0xC); - /** The constant BLS12_G1MULTIEXP. */ - public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xD); + public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xC); /** The constant BLS12_G2ADD. */ - public static final Address BLS12_G2ADD = Address.precompiled(0xE); - - /** The constant BLS12_G2MUL. */ - public static final Address BLS12_G2MUL = Address.precompiled(0xF); + public static final Address BLS12_G2ADD = Address.precompiled(0xD); /** The constant BLS12_G2MULTIEXP. */ - public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x10); + public static final Address BLS12_G2MULTIEXP = Address.precompiled(0xE); /** The constant BLS12_PAIRING. */ - public static final Address BLS12_PAIRING = Address.precompiled(0x11); + public static final Address BLS12_PAIRING = Address.precompiled(0xF); /** The constant BLS12_MAP_FP_TO_G1. */ - public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x12); + public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x10); /** The constant BLS12_MAP_FP2_TO_G2. */ - public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x13); + public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x11); /** The constant ZERO. */ public static final Address ZERO = Address.fromHexString("0x0"); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContract.java b/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContract.java deleted file mode 100644 index 8c76571e1c0..00000000000 --- a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContract.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.evm.precompile; - -import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP2537; - -import org.apache.tuweni.bytes.Bytes; - -/** The BLS12G1 Mul precompiled contract. */ -public class BLS12G1MulPrecompiledContract extends AbstractBLS12PrecompiledContract { - - private static final int PARAMETER_LENGTH = 160; - - /** Instantiates a new BLS12G1 Mul precompiled contract. */ - public BLS12G1MulPrecompiledContract() { - super("BLS12_G1MUL", LibGnarkEIP2537.BLS12_G1MUL_OPERATION_SHIM_VALUE, PARAMETER_LENGTH); - } - - @Override - public long gasRequirement(final Bytes input) { - return 12_000L; - } -} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContract.java b/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContract.java deleted file mode 100644 index c5e84b6df3b..00000000000 --- a/evm/src/main/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContract.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.evm.precompile; - -import org.hyperledger.besu.nativelib.gnark.LibGnarkEIP2537; - -import org.apache.tuweni.bytes.Bytes; - -/** The BLS12_G2Mul precompiled contract. */ -public class BLS12G2MulPrecompiledContract extends AbstractBLS12PrecompiledContract { - - private static final int PARAMETER_LENGTH = 288; - - /** Instantiates a new BLS12_G2Mul precompiled contract. */ - public BLS12G2MulPrecompiledContract() { - super("BLS12_G2MUL", LibGnarkEIP2537.BLS12_G2MUL_OPERATION_SHIM_VALUE, PARAMETER_LENGTH); - } - - @Override - public long gasRequirement(final Bytes input) { - return 22_500L; - } -} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/precompile/MainnetPrecompiledContracts.java b/evm/src/main/java/org/hyperledger/besu/evm/precompile/MainnetPrecompiledContracts.java index 624dc66a9ba..8dcdac4c651 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/precompile/MainnetPrecompiledContracts.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/precompile/MainnetPrecompiledContracts.java @@ -163,10 +163,8 @@ static void populateForPrague( // EIP-2537 - BLS12-381 curve operations registry.put(Address.BLS12_G1ADD, new BLS12G1AddPrecompiledContract()); - registry.put(Address.BLS12_G1MUL, new BLS12G1MulPrecompiledContract()); registry.put(Address.BLS12_G1MULTIEXP, new BLS12G1MultiExpPrecompiledContract()); registry.put(Address.BLS12_G2ADD, new BLS12G2AddPrecompiledContract()); - registry.put(Address.BLS12_G2MUL, new BLS12G2MulPrecompiledContract()); registry.put(Address.BLS12_G2MULTIEXP, new BLS12G2MultiExpPrecompiledContract()); registry.put(Address.BLS12_PAIRING, new BLS12PairingPrecompiledContract()); registry.put(Address.BLS12_MAP_FP_TO_G1, new BLS12MapFpToG1PrecompiledContract()); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContractTest.java b/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContractTest.java index bf0f8a14818..8c95e07d0c0 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContractTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G1MulPrecompiledContractTest.java @@ -34,9 +34,13 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; +/** + * G1 MUL was removed from EIP-2537 in favor of single point/scalar MSM. This test is being + * repurposed to test single point/pairs. + */ class BLS12G1MulPrecompiledContractTest { - final BLS12G1MulPrecompiledContract contract = new BLS12G1MulPrecompiledContract(); + final BLS12G1MultiExpPrecompiledContract contract = new BLS12G1MultiExpPrecompiledContract(); private final MessageFrame messageFrame = mock(MessageFrame.class); @@ -44,7 +48,7 @@ static Iterable parameters() throws IOException { return CharStreams.readLines( new InputStreamReader( Objects.requireNonNull( - BLS12G1MulPrecompiledContractTest.class.getResourceAsStream("g1_mul.csv")), + BLS12G1MultiExpPrecompiledContract.class.getResourceAsStream("g1_mul.csv")), UTF_8)) .stream() .map(line -> Arguments.of((Object[]) line.split(",", 4))) diff --git a/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContractTest.java b/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContractTest.java index 32af4677477..30004c25e38 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContractTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/precompile/BLS12G2MulPrecompiledContractTest.java @@ -34,9 +34,13 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; +/** + * G2 MUL was removed from EIP-2537 in favor of single point/scalar MSM. This test is being + * repurposed to test single point/pairs. + */ class BLS12G2MulPrecompiledContractTest { - final BLS12G2MulPrecompiledContract contract = new BLS12G2MulPrecompiledContract(); + final BLS12G2MultiExpPrecompiledContract contract = new BLS12G2MultiExpPrecompiledContract(); private final MessageFrame messageFrame = mock(MessageFrame.class); @@ -44,7 +48,7 @@ static Iterable parameters() throws IOException { return CharStreams.readLines( new InputStreamReader( Objects.requireNonNull( - BLS12G2MulPrecompiledContractTest.class.getResourceAsStream("g2_mul.csv")), + BLS12G2MultiExpPrecompiledContract.class.getResourceAsStream("g2_mul.csv")), UTF_8)) .stream() .map(line -> Arguments.of((Object[]) line.split(",", 4))) diff --git a/evm/src/test/java/org/hyperledger/besu/evm/precompile/Benchmarks.java b/evm/src/test/java/org/hyperledger/besu/evm/precompile/Benchmarks.java index 458f0c95587..2dd22764cd7 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/precompile/Benchmarks.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/precompile/Benchmarks.java @@ -411,22 +411,6 @@ public static void benchBLS12G1Add() { "G1ADD for %,d gas. Charging %,d gas.%n", (int) gasSpent, contract.gasRequirement(arg)); } - private static void benchBLS12G1Mul() { - final Bytes arg = - Bytes.fromHexString( - "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb" - + "0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1" - + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - - final BLS12G1MulPrecompiledContract contract = new BLS12G1MulPrecompiledContract(); - contract.computePrecompile(arg, fakeFrame); - - final double gasSpent = runBenchmark(arg, contract); - - System.out.printf( - "G1MUL for %,d gas. Charging %,d gas.%n", (int) gasSpent, contract.gasRequirement(arg)); - } - private static void benchBLS12G1MultiExp() { final Bytes[] args = { Bytes.fromHexString( @@ -493,21 +477,6 @@ public static void benchBLS12G2Add() { "G2ADD for %,d gas. Charging %,d gas.%n", (int) gasSpent, contract.gasRequirement(arg)); } - private static void benchBLS12G2Mul() { - final Bytes arg = - Bytes.fromHexString( - "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e" - + "000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be" - + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - - final BLS12G2MulPrecompiledContract contract = new BLS12G2MulPrecompiledContract(); - - final double gasSpent = runBenchmark(arg, contract); - - System.out.printf( - "G2MUL for %,d gas. Charging %,d gas.%n", (int) gasSpent, contract.gasRequirement(arg)); - } - private static void benchBLS12G2MultiExp() { final Bytes[] args = { Bytes.fromHexString( @@ -655,10 +624,8 @@ public static void main(final String[] args) { benchBNPairing(); benchModExp(); benchBLS12G1Add(); - benchBLS12G1Mul(); benchBLS12G1MultiExp(); benchBLS12G2Add(); - benchBLS12G2Mul(); benchBLS12G2MultiExp(); benchBLS12Pair(); benchBLS12MapFPTOG1();