Add EIP-2537 (BLS12-381 curve precompiles) to Cancun (#5017)

Add the BLS curve precompiles into the registry for cancun.  All of the
curve precompiles have been here since berlin, so this is just wiring
them in.

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5042/head
Danno Ferrin 2 years ago committed by GitHub
parent 33ea29316d
commit ca12eaebab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetPrecompiledContractRegistries.java
  2. 35
      evm/src/main/java/org/hyperledger/besu/evm/precompile/MainnetPrecompiledContracts.java

@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.mainnet;
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_PRIVACY;
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY;
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.PLUGIN_PRIVACY;
import static org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts.populateForBLS12;
import static org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts.populateForByzantium;
import static org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts.populateForCancun;
import static org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts.populateForFrontier;
@ -29,39 +28,30 @@ import org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPrecompi
import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry;
/** Provides the various precompiled contracts used on mainnet hard forks. */
public abstract class MainnetPrecompiledContractRegistries {
public interface MainnetPrecompiledContractRegistries {
private MainnetPrecompiledContractRegistries() {}
public static PrecompileContractRegistry frontier(
static PrecompileContractRegistry frontier(
final PrecompiledContractConfiguration precompiledContractConfiguration) {
final PrecompileContractRegistry registry = new PrecompileContractRegistry();
populateForFrontier(registry, precompiledContractConfiguration.getGasCalculator());
return registry;
}
public static PrecompileContractRegistry byzantium(
static PrecompileContractRegistry byzantium(
final PrecompiledContractConfiguration precompiledContractConfiguration) {
final PrecompileContractRegistry registry = new PrecompileContractRegistry();
populateForByzantium(registry, precompiledContractConfiguration.getGasCalculator());
return registry;
}
public static PrecompileContractRegistry istanbul(
static PrecompileContractRegistry istanbul(
final PrecompiledContractConfiguration precompiledContractConfiguration) {
final PrecompileContractRegistry registry = new PrecompileContractRegistry();
populateForIstanbul(registry, precompiledContractConfiguration.getGasCalculator());
return registry;
}
public static PrecompileContractRegistry bls12(
final PrecompiledContractConfiguration precompiledContractConfiguration) {
final PrecompileContractRegistry registry = new PrecompileContractRegistry();
populateForBLS12(registry, precompiledContractConfiguration.getGasCalculator());
return registry;
}
public static PrecompileContractRegistry cancun(
static PrecompileContractRegistry cancun(
final PrecompiledContractConfiguration precompiledContractConfiguration) {
final PrecompileContractRegistry registry = new PrecompileContractRegistry();
populateForCancun(registry, precompiledContractConfiguration.getGasCalculator());

@ -18,9 +18,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
/** Provides the various precompiled contracts used on mainnet hard forks. */
public abstract class MainnetPrecompiledContracts {
private MainnetPrecompiledContracts() {}
public interface MainnetPrecompiledContracts {
/**
* Frontier precompile contract registry.
@ -28,7 +26,7 @@ public abstract class MainnetPrecompiledContracts {
* @param gasCalculator the gas calculator
* @return the precompile contract registry
*/
public static PrecompileContractRegistry frontier(final GasCalculator gasCalculator) {
static PrecompileContractRegistry frontier(final GasCalculator gasCalculator) {
PrecompileContractRegistry precompileContractRegistry = new PrecompileContractRegistry();
populateForFrontier(precompileContractRegistry, gasCalculator);
return precompileContractRegistry;
@ -40,7 +38,7 @@ public abstract class MainnetPrecompiledContracts {
* @param registry the registry
* @param gasCalculator the gas calculator
*/
public static void populateForFrontier(
static void populateForFrontier(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
registry.put(Address.ECREC, new ECRECPrecompiledContract(gasCalculator));
registry.put(Address.SHA256, new SHA256PrecompiledContract(gasCalculator));
@ -54,7 +52,7 @@ public abstract class MainnetPrecompiledContracts {
* @param gasCalculator the gas calculator
* @return the precompile contract registry
*/
public static PrecompileContractRegistry homestead(final GasCalculator gasCalculator) {
static PrecompileContractRegistry homestead(final GasCalculator gasCalculator) {
return frontier(gasCalculator);
}
@ -64,7 +62,7 @@ public abstract class MainnetPrecompiledContracts {
* @param gasCalculator the gas calculator
* @return the precompile contract registry
*/
public static PrecompileContractRegistry byzantium(final GasCalculator gasCalculator) {
static PrecompileContractRegistry byzantium(final GasCalculator gasCalculator) {
PrecompileContractRegistry precompileContractRegistry = new PrecompileContractRegistry();
populateForByzantium(precompileContractRegistry, gasCalculator);
return precompileContractRegistry;
@ -76,7 +74,7 @@ public abstract class MainnetPrecompiledContracts {
* @param registry the registry
* @param gasCalculator the gas calculator
*/
public static void populateForByzantium(
static void populateForByzantium(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForFrontier(registry, gasCalculator);
registry.put(
@ -93,7 +91,7 @@ public abstract class MainnetPrecompiledContracts {
* @param gasCalculator the gas calculator
* @return the precompile contract registry
*/
public static PrecompileContractRegistry istanbul(final GasCalculator gasCalculator) {
static PrecompileContractRegistry istanbul(final GasCalculator gasCalculator) {
PrecompileContractRegistry precompileContractRegistry = new PrecompileContractRegistry();
populateForIstanbul(precompileContractRegistry, gasCalculator);
return precompileContractRegistry;
@ -105,7 +103,7 @@ public abstract class MainnetPrecompiledContracts {
* @param registry the registry
* @param gasCalculator the gas calculator
*/
public static void populateForIstanbul(
static void populateForIstanbul(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForByzantium(registry, gasCalculator);
registry.put(Address.ALTBN128_ADD, AltBN128AddPrecompiledContract.istanbul(gasCalculator));
@ -116,14 +114,16 @@ public abstract class MainnetPrecompiledContracts {
}
/**
* Populate registry for bls12.
* Populate registry for Cancun.
*
* @param registry the registry
* @param gasCalculator the gas calculator
*/
public static void populateForBLS12(
static void populateForCancun(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForIstanbul(registry, gasCalculator);
// 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());
@ -133,17 +133,8 @@ public abstract class MainnetPrecompiledContracts {
registry.put(Address.BLS12_PAIRING, new BLS12PairingPrecompiledContract());
registry.put(Address.BLS12_MAP_FP_TO_G1, new BLS12MapFpToG1PrecompiledContract());
registry.put(Address.BLS12_MAP_FP2_TO_G2, new BLS12MapFp2ToG2PrecompiledContract());
}
/**
* Populate registry for Cancun.
*
* @param registry the registry
* @param gasCalculator the gas calculator
*/
public static void populateForCancun(
final PrecompileContractRegistry registry, final GasCalculator gasCalculator) {
populateForIstanbul(registry, gasCalculator);
// EIP-4844 - shard blob transactions
// TODO: allow override to be configured?
registry.put(Address.KZG_POINT_EVAL, new KZGPointEvalPrecompiledContract());
}

Loading…
Cancel
Save