EEVM.Precompiles (eevm v0.1.0)

Copy Markdown View Source

Dispatcher for EVM precompiled contracts.

Precompiled contracts are built-in functions at fixed addresses that provide cryptographic and utility operations too expensive to implement in EVM bytecode. When a CALL targets one of these addresses, execution is routed here instead of interpreting bytecode.

Supported Precompiles

AddressNameFrom
0x01ECRECOVER — elliptic curve signature recoveryFrontier
0x02SHA256 — SHA-256 hashFrontier
0x03RIPEMD160 — RIPEMD-160 hashFrontier
0x04IDENTITY — data copy (no-op)Frontier
0x05MODEXP — big integer modular exponentiationByzantium (EIP-198)
0x06BN256 ADD — elliptic curve point addition on alt_bn128Byzantium (EIP-196)
0x07BN256 MUL — elliptic curve scalar multiplication on alt_bn128Byzantium (EIP-196)
0x08BN256 PAIRING — bilinear pairing check on alt_bn128Byzantium (EIP-197)
0x09BLAKE2F — BLAKE2b compression functionIstanbul (EIP-152)
0x0AKZG Point Evaluation — verify KZG commitmentCancun (EIP-4844)
0x0BBLS12 G1ADD — add two BLS12-381 G1 pointsPrague (EIP-2537)
0x0CBLS12 G1MSM — multiscalar multiplication over BLS12-381 G1Prague (EIP-2537)
0x0DBLS12 G2ADD — add two BLS12-381 G2 pointsPrague (EIP-2537)
0x0EBLS12 G2MSM — multiscalar multiplication over BLS12-381 G2Prague (EIP-2537)
0x0FBLS12 PAIRING — pairing check over BLS12-381Prague (EIP-2537)
0x10BLS12 MAP_FP_TO_G1 — map Fp element into BLS12-381 G1Prague (EIP-2537)
0x11BLS12 MAP_FP2_TO_G2 — map Fp2 element into BLS12-381 G2Prague (EIP-2537)
0x100P256VERIFY — secp256r1 ECDSA signature verificationOsaka (EIP-7951)

An address is a precompile only from the fork that introduced it. ModExp and the BN256 precompiles also receive the hardfork, because their prices changed later: ModExp follows EIP-198, then EIP-2565 (Berlin), then EIP-7883 with the EIP-7823 input bounds (Osaka); BN256 follows EIP-196/197, then EIP-1108 (Istanbul).

The registry for each fork is built at compile time. Custom precompiles registered through EEVM.Config.register_precompile/3 implement EEVM.Precompile and override built-ins at the same address.

Summary

Types

How a precompile runs: apply(module, function, [input, gas_limit | extra_args]).

Functions

Returns the precompiles active under config: the fork's built-ins merged with the custom precompiles registered on config.

Types

entry()

@type entry() :: {module(), atom(), list()}

How a precompile runs: apply(module, function, [input, gas_limit | extra_args]).

Functions

execute(address, input, gas_limit)

@spec execute(non_neg_integer(), binary(), non_neg_integer()) ::
  {:ok, binary(), non_neg_integer()} | {:error, atom()}

execute(address, input, gas_limit, config)

@spec execute(non_neg_integer(), binary(), non_neg_integer(), EEVM.Config.t()) ::
  {:ok, binary(), non_neg_integer()} | {:error, atom()}

precompile?(address)

@spec precompile?(non_neg_integer()) :: boolean()

precompile?(address, config)

@spec precompile?(non_neg_integer(), EEVM.Config.t()) :: boolean()

precompile_addresses(config)

@spec precompile_addresses(EEVM.Config.t()) :: [non_neg_integer()]

registry(config)

@spec registry(EEVM.Config.t()) :: %{optional(non_neg_integer()) => entry()}

Returns the precompiles active under config: the fork's built-ins merged with the custom precompiles registered on config.