Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Precompiled contracts are special Ethereum addresses (0x01-0x13+) that execute optimized native code instead of EVM bytecode. They provide gas-efficient implementations of computationally expensive operations like cryptographic primitives, hashing, and elliptic curve operations. Voltaire provides low-level tree-shakable implementations of all standard precompiles in both TypeScript and Zig, with WASM compilation support for portable high-performance execution. For complete spec-compliant EVM implementations that use these precompiles, see evmts/guillotine and evmts/tevm-monorepo.

Complete Precompile Reference

AddressNameGas CostHardforkCategoryDescription
0x01ECRECOVER3,000FrontierCryptoRecover ECDSA signer address
0x02SHA25660 + 12/wordFrontierHashSHA-256 hash function
0x03RIPEMD160600 + 120/wordFrontierHashRIPEMD-160 hash function
0x04IDENTITY15 + 3/wordFrontierDataCopy input to output
0x05MODEXPDynamicByzantiumMathModular exponentiation
0x06BN254_ADD150ByzantiumzkSNARKsBN254 G1 point addition
0x07BN254_MUL6,000ByzantiumzkSNARKsBN254 G1 scalar multiplication
0x08BN254_PAIRING45,000 + 34,000kByzantiumzkSNARKsBN254 pairing check
0x09BLAKE2FDynamicIstanbulHashBLAKE2b compression function
0x0APOINT_EVALUATION50,000CancunBlobsKZG point evaluation (EIP-4844)
0x0BBLS12_G1_ADD500PragueETH2BLS12-381 G1 point addition
0x0CBLS12_G1_MUL12,000PragueETH2BLS12-381 G1 scalar multiplication
0x0DBLS12_G1_MSMVariablePragueETH2BLS12-381 G1 multi-scalar multiplication
0x0EBLS12_G2_ADD800PragueETH2BLS12-381 G2 point addition
0x0FBLS12_G2_MUL45,000PragueETH2BLS12-381 G2 scalar multiplication
0x10BLS12_G2_MSMVariablePragueETH2BLS12-381 G2 multi-scalar multiplication
0x11BLS12_PAIRING115,000 + 23,000kPragueETH2BLS12-381 pairing check
0x12BLS12_MAP_FP_TO_G15,500PragueETH2Map field element to G1 (hash-to-curve)
0x13BLS12_MAP_FP2_TO_G275,000PragueETH2Map Fp2 element to G2 (hash-to-curve)

Precompile Categories

Cryptography (0x01)

ECRECOVER recovers the Ethereum address from an ECDSA signature. Essential for transaction validation and signature verification.
  • Gas: 3,000 (fixed)
  • Input: 128 bytes (hash, v, r, s)
  • Output: 20-byte address
  • Use: Transaction signing, off-chain authentication

Hashing (0x02, 0x03, 0x09)

SHA256, RIPEMD160, BLAKE2F provide standard cryptographic hash functions.
  • SHA256: Bitcoin compatibility, Merkle trees
  • RIPEMD160: Bitcoin address generation
  • BLAKE2F: High-performance modern hash (Zcash)

Data Operations (0x04)

IDENTITY is a simple memcpy operation, mainly used for:
  • Gas benchmarking
  • Data copying in complex contracts
  • ABI encoding/decoding optimization

Mathematics (0x05)

MODEXP performs modular exponentiation: (base^exp) mod modulus
  • RSA signature verification
  • Zero-knowledge proof systems
  • Cryptographic protocols
  • Dynamic gas based on input sizes

zkSNARKs - BN254 Curve (0x06-0x08)

BN254 precompiles enable efficient zero-knowledge proofs:
  • ADD (150 gas): Point addition for proof verification
  • MUL (6,000 gas): Scalar multiplication
  • PAIRING (45k + 34k/pair): Bilinear pairing checks
Used by: Zcash, Tornado Cash, zkSync, StarkNet, Polygon zkEVM Security: ~100-bit (sufficient but aging)

Ethereum 2.0 - BLS12-381 Curve (0x0B-0x13)

BLS12-381 precompiles power Ethereum 2.0 consensus:

G1 Operations (128-byte points)

  • G1_ADD (500 gas): Fast point addition
  • G1_MUL (12,000 gas): Scalar multiplication
  • G1_MSM (variable): Batch operations with discounts

G2 Operations (256-byte points)

  • G2_ADD (800 gas): Extension field addition
  • G2_MUL (45,000 gas): More expensive than G1
  • G2_MSM (variable): Batch operations

Pairing & Hash-to-Curve

  • PAIRING (115k + 23k/pair): Signature verification
  • MAP_FP_TO_G1 (5,500 gas): Hash messages to G1
  • MAP_FP2_TO_G2 (75,000 gas): Hash messages to G2
Security: 128-bit (future-proof) Applications:
  • Validator signature aggregation
  • BLS multi-signatures
  • Threshold cryptography
  • Advanced zkSNARKs

Blob Data (0x0A)

POINT_EVALUATION verifies KZG commitments for EIP-4844 blob transactions:
  • Gas: 50,000 (fixed)
  • Enables proto-danksharding
  • Reduces rollup costs by 10-100x
  • Critical for Ethereum scalability

Gas Cost Patterns

Fixed Cost

Simple operations with predictable computation:
  • ECRECOVER: 3,000
  • BLS12_G1_ADD: 500
  • POINT_EVALUATION: 50,000

Linear Cost

Scales with input size:
  • SHA256: 60 + 12 per word
  • IDENTITY: 15 + 3 per word

Dynamic Cost

Complex calculation based on inputs:
  • MODEXP: Based on base/exp/mod sizes
  • BLS12_MSM: Batch discounts

Multi-Element Cost

Per-item pricing:
  • BN254_PAIRING: 45,000 + 34,000 per pair
  • BLS12_PAIRING: 115,000 + 23,000 per pair

Performance Comparison

Elliptic Curve Operations

OperationBN254BLS12-381SecurityUse Case
Point Add150500 (G1) / 800 (G2)100-bit / 128-bitzkSNARKs / ETH2
Scalar Mul6,00012,000 (G1) / 45,000 (G2)100-bit / 128-bitProofs / Signatures
Pairing45k+34k/pair115k+23k/pair100-bit / 128-bitVerification

Hashing Performance

FunctionGas/KBSpeedUse Case
SHA256~380FastBitcoin compat
RIPEMD160~3,750SlowerLegacy
BLAKE2FVariableFastestModern
Keccak256~1,000FastNative EVM

Usage Statistics

Most frequently used precompiles by gas consumption:
  1. ECRECOVER (0x01) - Every transaction signature
  2. BLS12_PAIRING (0x11) - ETH2 consensus (thousands per block)
  3. POINT_EVALUATION (0x0A) - Blob transactions
  4. BN254_PAIRING (0x08) - zkRollup proofs
  5. SHA256 (0x02) - Bridge verifications
Least used:
  • RIPEMD160 (0x03) - Legacy Bitcoin compatibility
  • IDENTITY (0x04) - Specialized optimization

Implementation Guide

TypeScript

import { execute, PrecompileAddress } from '@tevm/voltaire/precompiles';
import { Hardfork } from '@tevm/voltaire/primitives/Hardfork';

// Execute any precompile
const result = execute(
  PrecompileAddress.ECRECOVER,
  input,        // Uint8Array
  gasLimit,     // bigint
  Hardfork.CANCUN
);

if (result.success) {
  console.log('Output:', result.output);
  console.log('Gas used:', result.gasUsed);
} else {
  console.error('Error:', result.error);
}

Zig

const std = @import("std");
const precompiles = @import("precompiles");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Execute precompile
    const result = try precompiles.ecrecover.execute(
        allocator,
        input,      // []const u8
        gas_limit,  // u64
    );
    defer result.deinit(allocator);

    if (result.success) {
        std.debug.print("Output: {any}\n", .{result.output});
    }
}

WASM

All precompiles available via WASM. Import and use like the TypeScript implementation.

Security Considerations

Input Validation

All precompiles validate:
  • Input length (exact or range)
  • Field element bounds (curve operations)
  • Point validity (on curve, in subgroup)
  • Gas sufficiency (before computation)
Invalid inputs return error, not false results.

Constant-Time Execution

Cryptographic precompiles use constant-time algorithms:
  • ECRECOVER: Prevents timing attacks on signatures
  • BN254/BLS12-381: Side-channel resistant scalar multiplication
  • MODEXP: Protects secret exponents

Gas DoS Protection

Dynamic gas prevents abuse:
  • MODEXP: Exponential cost for large inputs
  • MSM operations: Bounded by block gas limit
  • Pairing: Linear cost per pair

Curve Security

CurveSecurityStatusNotes
secp256k1128-bitMatureBitcoin/Ethereum standard
BN254~100-bitAgingSufficient for current zkSNARKs
BLS12-381128-bitFuture-proofETH2, modern protocols

Hardfork Availability

import { Hardfork } from '@tevm/voltaire/primitives/Hardfork';

// Check precompile availability
const precompiles = {
  [Hardfork.FRONTIER]: [0x01, 0x02, 0x03, 0x04],
  [Hardfork.BYZANTIUM]: [0x05, 0x06, 0x07, 0x08],
  [Hardfork.ISTANBUL]: [0x09],
  [Hardfork.CANCUN]: [0x0A],
  [Hardfork.PRAGUE]: [0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13],
};
Always check hardfork before calling newer precompiles.

Implementation Status

Zig: Complete

All precompiles fully implemented with native C library integration:
  • secp256k1: libsecp256k1
  • BN254: arkworks (Rust FFI)
  • BLS12-381: blst
  • KZG: c-kzg-4844
  • Hashes: libwally-core

TypeScript: Functional

  • Production-ready: ECRECOVER, SHA256, RIPEMD160, IDENTITY, BLAKE2F
  • Stubs (use WASM): BLS12-381 operations (return correct size, calculate gas, no crypto)
  • Working: BN254 via @noble/curves, MODEXP, POINT_EVALUATION via c-kzg
For security-critical operations, always use Zig/WASM implementations.

Curve Documentation

Cryptography

Primitives

References

Contributing

Precompile implementations require:
  • Exact adherence to EIP specifications
  • Comprehensive test vectors
  • Gas cost validation
  • Security audits for crypto operations
  • Cross-language parity (TypeScript ↔ Zig)
See CONTRIBUTING.md