Skip to main content

Nethereum.EVM.Precompiles.Bls

NuGet: Nethereum.EVM.Precompiles.Bls | Source: src/Nethereum.EVM.Precompiles.Bls/

Nethereum.EVM.Precompiles.Bls

EIP-2537 BLS12-381 precompile handlers for Nethereum.EVM.Core. Activated at the Prague hardfork.

Overview​

EIP-2537 adds seven BLS12-381 precompiles at addresses 0x0b…0x11:

AddressPrecompile
0x0bG1 addition
0x0cG1 multi-scalar multiplication
0x0dG2 addition
0x0eG2 multi-scalar multiplication
0x0fPairing check
0x10map_fp_to_g1
0x11map_fp2_to_g2

This package plugs those handlers into a Nethereum.EVM.Core.HardforkConfig by extension method, calling into a pluggable IBls12381Operations implementation (managed, native, or zkVM-backed).

Installation​

dotnet add package Nethereum.EVM.Precompiles.Bls

Dependencies​

  • Nethereum.EVM — HardforkConfig, PrecompileRegistry.
  • Nethereum.Signer.Bls — the IBls12381Operations contract.

A concrete backend is a separate package. Nethereum.Signer.Bls.Herumi provides Bls12381Operations, a native (Herumi MCL) implementation — add it to supply the backend at runtime:

dotnet add package Nethereum.Signer.Bls.Herumi

Usage​

HardforkConfig.WithBlsBackend(IBls12381Operations)​

using Nethereum.EVM;
using Nethereum.EVM.Precompiles; // DefaultHardforkConfigs
using Nethereum.Signer.Bls; // IBls12381Operations
using Nethereum.Signer.Bls.Herumi; // Bls12381Operations (native Herumi MCL backend)

IBls12381Operations blsOps = new Bls12381Operations();
HardforkConfig prague = DefaultHardforkConfigs.Prague
.WithBlsBackend(blsOps);

The extension wraps prague.Precompiles with BLS handlers, returning a new HardforkConfig instance. The original is unchanged.

PrecompileRegistry.WithBlsBackend(...)​

Compose BLS on top of any PrecompileRegistry returned from PrecompileRegistries.PragueBase(...) or a custom composition:

using Nethereum.EVM.Execution.Precompiles;
using Nethereum.EVM.Precompiles.Bls; // PrecompileRegistry.WithBlsBackend

var baseRegistry = PrecompileRegistries.PragueBase(/* backends... */);
var withBls = baseRegistry.WithBlsBackend(blsOps);

Requirement Note​

WithBlsBackend throws InvalidOperationException when called against a HardforkConfig whose Precompiles registry is null — BLS handlers must layer on top of a base registry (e.g. Prague's). Obtain the HardforkConfig through MainnetHardforkRegistry.Build(backends).Get(HardforkName.Prague) or DefaultHardforkConfigs.Prague before calling the extension.

See Also​