Try it Live
Run Hardfork examples in the interactive playground
WASM Implementation
WebAssembly acceleration status for Hardfork operations.Status: Not Implemented
WASM is NOT implemented for Hardfork operations and is NOT planned.Why No WASM?
Operations Are Already Optimal
Hardfork provides:- Ethereum protocol version enum (constants)
- Simple comparison operations (array index comparisons)
- String parsing (hash table lookups)
- Feature detection (version comparisons)
- Already optimal in TypeScript
- Pure O(1) lookups and numeric comparisons
- No heavy computation or data processing
- Execution time less than 100ns per operation
Performance Characteristics
Pure TypeScript implementation benchmarks:
WASM call overhead alone is 1000-2000ns - operations would be 10-100x slower.
When to Use WASM
WASM is beneficial for:- Heavy computation (greater than 10μs)
- Cryptographic operations (hashing, signatures)
- Large data processing (RLP encoding, ABI encoding)
- Batch operations (processing many items)
- CPU-intensive algorithms (complex math, parsing)
WASM Cost-Benefit
Good WASM Candidates
These primitives DO use WASM:- Keccak256: ~50μs → ~5μs (10x speedup)
- secp256k1: ~100μs → ~10μs (10x speedup)
- RLP encoding: ~10μs → ~1μs (10x speedup)
- ABI encoding: ~20μs → ~2μs (10x speedup)
API Reference
isWasmHardforkAvailable
Check if WASM implementation is available.false
Example:
getHardforkImplementationStatus
Get detailed implementation status.Import Behavior
hardfork.wasm.js
Performance Comparison
TypeScript vs WASM (Hypothetical)
Assuming WASM implemented same logic:Real-World Impact
Architecture Decision
Why This Matters
Hardfork is a hot path primitive:- Called frequently in transaction processing
- Used in every EVM opcode execution gate
- Critical for gas calculation
- Needed for every smart contract call
- Must be less than 100ns per call
- No allocations
- Minimal branching
- Cache-friendly
Design Philosophy
Use the right tool:- Simple operations → TypeScript
- Heavy computation → WASM
- Critical path → TypeScript (no overhead)
- Batch processing → WASM (amortize overhead)
Benchmarking
Running Benchmarks
Typical Results
- All operations less than 100ns
- WASM overhead greater than 1000ns
- WASM would be 10-100x slower
Alternative Optimizations
Instead of WASM, we optimize through:1. Constant Folding
2. Hash Table Lookups
3. Inline Comparisons
4. Monomorphic Code
Related Primitives with WASM
These primitives DO benefit from WASM:Address
- Keccak256 hashing for checksums (~10x speedup)
- Public key derivation (~10x speedup)
Hash
- Keccak256 implementation (~10x speedup)
- SHA256 implementation (~8x speedup)
RLP
- Encoding/decoding large structures (~5-10x speedup)
ABI
- Encoding/decoding complex types (~5-10x speedup)
secp256k1
- Signature operations (~10x speedup)
- Public key recovery (~10x speedup)
Best Practices
1. Import from Main Module
2. Don’t Check for WASM
3. Trust the Implementation
Future Considerations
When Would WASM Be Added?
WASM might be considered if:- Hardfork operations become greater than 10μs per call
- Batch operations on 1000+ hardforks become common
- Heavy computation is added (unlikely for enum operations)
Maintaining Zero Overhead
Current design maintains zero overhead:- No WASM loading
- No WASM compilation
- No WASM call overhead
- No fallback logic
- Simpler codebase
Related
- index.mdx - Main documentation
- utilities.mdx - All operations are pure TypeScript
- comparisons.mdx - O(1) comparison operations
- features.mdx - O(1) feature detection

