Skip to content

Commit

Permalink
Add EIP-2537 (BLS12-381 curve precompiles) to Cancun (#5017)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and gfukushima committed Feb 2, 2023
1 parent 7b10e9f commit 7554285
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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;
Expand All @@ -29,39 +28,30 @@
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
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.
*
* @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;
Expand All @@ -40,7 +38,7 @@ public static PrecompileContractRegistry frontier(final GasCalculator gasCalcula
* @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));
Expand All @@ -54,7 +52,7 @@ public static void populateForFrontier(
* @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);
}

Expand All @@ -64,7 +62,7 @@ public static PrecompileContractRegistry homestead(final GasCalculator gasCalcul
* @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;
Expand All @@ -76,7 +74,7 @@ public static PrecompileContractRegistry byzantium(final GasCalculator gasCalcul
* @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(
Expand All @@ -93,7 +91,7 @@ public static void populateForByzantium(
* @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;
Expand All @@ -105,7 +103,7 @@ public static PrecompileContractRegistry istanbul(final GasCalculator gasCalcula
* @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));
Expand All @@ -116,14 +114,16 @@ public static void populateForIstanbul(
}

/**
* 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());
Expand All @@ -133,17 +133,8 @@ public static void populateForBLS12(
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());
}
Expand Down

0 comments on commit 7554285

Please sign in to comment.