Skip to content

Commit

Permalink
remove MUL per ethereum/EIPs#8945
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Dec 19, 2024
1 parent 5e8db81 commit 1e3d865
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -52,15 +52,16 @@ 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
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
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);

static Iterable<Arguments> 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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
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);

static Iterable<Arguments> 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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -655,10 +624,8 @@ public static void main(final String[] args) {
benchBNPairing();
benchModExp();
benchBLS12G1Add();
benchBLS12G1Mul();
benchBLS12G1MultiExp();
benchBLS12G2Add();
benchBLS12G2Mul();
benchBLS12G2MultiExp();
benchBLS12Pair();
benchBLS12MapFPTOG1();
Expand Down

0 comments on commit 1e3d865

Please sign in to comment.