Crypto Reference
All crypto modules insrc/crypto/. Implementations use Zig core with Rust/C for complex curves.
Hash Functions
Keccak256
Primary Ethereum hash function. Used for addresses, transaction hashes, storage keys.Keccak256/index.ts- TypeScript APIkeccak256.wasm.ts- WASM variantkeccak256_accel.zig- Hardware-accelerated implementationkeccak_asm.zig- Assembly-optimizedkeccak_wrapper.rs- Rust keccak-asm wrapper
SHA256
SHA-256 for EVM precompile and general use.SHA256/index.ts- TypeScript APIsha256.wasm.ts- WASM variantsha256_accel.zig- Hardware-accelerated (SHA-NI)
Blake2
Blake2b hashing (EVM precompile 0x09).Blake2/index.ts- TypeScript APIblake2.zig- Zig implementationblake2_c.zig- C bindings (optional)blake2.fuzz.zig- Fuzz tests
Ripemd160
RIPEMD-160 for Bitcoin compatibility (EVM precompile 0x03).Ripemd160/index.ts- TypeScript APIripemd160.zig- Zig implementationripemd160_c.zig- C bindings
Digital Signatures
Secp256k1
Bitcoin/Ethereum ECDSA curve. Core signing primitive.sign(hash, privateKey)- ECDSA signverify(signature, hash, publicKey)- Verify signaturerecover(signature, hash, v)- Recover public keygetPublicKey(privateKey)- Derive public keycompressPublicKey(pubkey)- Compress to 33 bytesdecompressPublicKey(pubkey)- Decompress to 65 bytesisValidPrivateKey(key)- Validate private keyisValidPublicKey(key)- Validate public key
Secp256k1/index.ts- TypeScript APIsecp256k1.zig- Zig implementationsecp256k1.wasm.ts- WASM variantsecp256k1.bench.zig- Benchmarkssecp256k1.fuzz.zig- Fuzz tests
Ed25519
EdDSA signatures. Used by some L2s and alt chains.Ed25519/index.ts- TypeScript APIed25519.zig- Zig implementationed25519.wasm.ts- WASM variant
P256
NIST P-256 (secp256r1). Used by hardware wallets and WebAuthn.P256/index.ts- TypeScript APIp256.zig- Zig implementationp256.wasm.ts- WASM variant
Elliptic Curves & Pairings
BN254
BN254 (alt_bn128) curve for zkSNARKs. Used by EVM precompiles 0x06-0x08.bn254.zig- Pure Zig implementationbn254_arkworks.zig- Rust arkworks wrapper (higher performance)bn254_ark_c.zig- C interface to Rustbn254_wrapper.rs- Rust arkworks bindings
bn254.ts- TypeScript API (auto-selects best impl)bn254.wasm.ts- WASM variantbn254.ark.ts- arkworks-specific exports
BLS12-381
BLS12-381 curve for beacon chain consensus. EVM precompiles 0x0B-0x13 (Prague). Usesblst C library for production performance.
| Address | Operation |
|---|---|
| 0x0B | G1 Add |
| 0x0C | G1 Mul |
| 0x0D | G1 MSM (multi-scalar multiplication) |
| 0x0E | G2 Add |
| 0x0F | G2 Mul |
| 0x10 | G2 MSM |
| 0x11 | Pairing |
| 0x12 | Map Fp to G1 |
| 0x13 | Map Fp2 to G2 |
src/evm/precompiles/):
bls12_g1_add.zig,bls12_g1_mul.zig,bls12_g1_msm.zigbls12_g2_add.zig,bls12_g2_mul.zig,bls12_g2_msm.zigbls12_pairing.zigbls12_map_fp_to_g1.zig,bls12_map_fp2_to_g2.zig
KZG Commitments
KZG
Kate-Zaverucha-Goldberg polynomial commitments for EIP-4844 blob transactions.c-kzg-4844- C library (lib/c-kzg-4844)- Trusted setup:
kzg_trusted_setup.zig
KZG/index.ts- TypeScript APIc_kzg.zig- C bindingskzg_setup.zig- Setup loadingkzg_trusted_setup.zig- Embedded trusted setup
Typed Data (EIP-712)
EIP712
Typed structured data hashing and signing.EIP712/index.ts- TypeScript API (placeholder/WIP)eip712.zig- Zig implementationeip712.wasm.ts- WASM variant
Symmetric Encryption
AesGcm
AES-256-GCM authenticated encryption.AesGcm/index.ts- TypeScript APIaes_gcm.zig- Zig implementation
X25519
Elliptic curve Diffie-Hellman key exchange.X25519/index.ts- TypeScript APIx25519.zig- Zig implementationx25519.wasm.ts- WASM variant
Wallet Derivation
Bip39
Mnemonic seed phrase generation and validation.Bip39/index.ts- TypeScript API (uses @scure/bip39)bip39.test.ts- Tests
HDWallet
Hierarchical Deterministic wallet derivation (BIP-32).HDWallet/index.ts- TypeScript API (uses @scure/bip32)hdwallet.test.ts- Testssigners/- Hardware wallet signers (Ledger, Trezor)
Hardware Acceleration
CPU Feature Detection
Detects available CPU features for optimal implementation selection.Accelerated Implementations
| Algorithm | Acceleration | Speedup |
|---|---|---|
| Keccak256 | Assembly (keccak-asm) | 3-5x |
| SHA256 | SHA-NI instructions | 4-6x |
| AES-GCM | AES-NI instructions | 5-10x |
cpu_features.zig- Feature detectionkeccak256_accel.zig- Accelerated Keccaksha256_accel.zig- Accelerated SHA256keccak_asm.zig- Assembly Keccak
Modular Exponentiation
ModExp
Modular exponentiation for MODEXP precompile (0x05).modexp.zig- Zig implementation
Module Summary
| Module | Purpose | Native | WASM |
|---|---|---|---|
| Keccak256 | Ethereum hash | ✅ | ✅ |
| SHA256 | SHA-2 hash | ✅ | ✅ |
| Blake2 | Blake2b hash | ✅ | ✅ |
| Ripemd160 | Legacy hash | ✅ | ✅ |
| Secp256k1 | ECDSA signing | ✅ | ✅ |
| Ed25519 | EdDSA signing | ✅ | ✅ |
| P256 | NIST curve | ✅ | ✅ |
| BN254 | zkSNARK curve | ✅ | ✅ |
| BLS12-381 | Consensus curve | ✅ | ❌ |
| KZG | Blob commitments | ✅ | ❌ |
| EIP712 | Typed data | ✅ | ✅ |
| AesGcm | Encryption | ✅ | ✅ |
| X25519 | Key exchange | ✅ | ✅ |
| Bip39 | Mnemonics | ✅ | ✅ |
| HDWallet | Key derivation | ✅ | ✅ |
- BLS12-381: Requires blst C library
- KZG: Requires trusted setup file and c-kzg library

