Overview
Address:0x0000000000000000000000000000000000000009
Introduced: Istanbul (EIP-152)
EIP: EIP-152
The Blake2f precompile implements the Blake2b compression function F, the core building block of the Blake2b cryptographic hash function. Unlike other hash precompiles that compute complete hashes, Blake2f exposes the low-level compression step, giving smart contracts fine-grained control over Blake2b hashing. This enables efficient verification of Zcash Equihash proofs and cross-chain bridges to Blake2-based blockchains.
Blake2 is a modern cryptographic hash function that’s faster than MD5, SHA-1, SHA-2, and SHA-3 while maintaining strong security guarantees. It’s widely used in Zcash, Monero, IPFS, and Wireguard. The “b” variant (Blake2b) operates on 64-bit words and produces up to 512-bit (64-byte) hashes.
By exposing the compression function directly, this precompile allows contracts to implement custom Blake2b variants (different initialization vectors, personalization strings, or tree hashing) without requiring new precompiles for each variant.
Gas Cost
Formula:rounds (1 gas per round)
The number of rounds is specified in the input (first 4 bytes). Common values:
- Blake2b standard: 12 rounds
- Reduced round versions: 1-12 rounds
- Maximum: 2^32 - 1 rounds (4,294,967,295 gas)
- 0 rounds: 0 gas
- 12 rounds: 12 gas
- 1000 rounds: 1000 gas
Input Format
Exactly 213 bytes required:Output Format
Usage Example
Error Conditions
- Input length ≠ 213 bytes (exact length required)
- Out of gas (gasLimit < rounds)
- Invalid final flag (not 0x00 or 0x01)
Use Cases
Production Applications:- Zcash Bridge: Verify Zcash Equihash proofs on Ethereum to enable trustless ZEC/ETH swaps. Equihash is a memory-hard proof-of-work algorithm based on Blake2b. The bridge contract uses Blake2f to verify Zcash block headers.
-
Cross-chain Bridges: Validate headers from blockchains using Blake2b:
- Filecoin: Uses Blake2b for hashing (bridge to Ethereum)
- Sia/Siacoin: Blake2b-based storage network
- Decred: Uses Blake256 (related to Blake2)
-
Efficient Hashing in Contracts: Blake2b is ~10x cheaper than SHA256 per byte:
- Large data structure hashing (Merkle trees)
- Content-addressed storage systems
- Efficient MACs and authenticated encryption
-
Custom Blake2 Variants:
- Personalized hashing: Domain separation for different protocols
- Tree hashing: BLAKE2bp parallel variant
- Keyed hashing: HMAC-like authentication
Implementation Details
- Zig: Uses Blake2 crypto module implementing RFC 7693
- TypeScript: Wrapper around Blake2 compression function
- Integration: Standalone Blake2b F function
- Algorithm: Blake2b compression as specified in RFC 7693
- Rounds: Configurable (standard Blake2b uses 12)
Blake2b Algorithm Overview
What is Blake2b? Blake2b is a cryptographic hash function designed to be faster than MD5, SHA-1, SHA-2, and SHA-3 while maintaining strong security. It’s the 64-bit variant of Blake2 (Blake2s is the 32-bit variant). Key Features:- Performance: Up to 2x faster than SHA-3, comparable to MD5
- Security: No known cryptographic weaknesses (finalist in SHA-3 competition)
- Flexibility: Configurable output length, keyed hashing, salting, personalization
- Simplicity: Simpler than SHA-3, easier to implement and audit
- Rounds: 12 rounds per 128-byte block (can be reduced for performance/security tradeoff)
- Output: Up to 512 bits (64 bytes), configurable
- Block size: 128 bytes (1024 bits)
- Word size: 64-bit (unlike Blake2s which uses 32-bit)
- State: 8 x 64-bit words (512 bits total)
- Current state
h(8 x 64-bit words) - Message block
m(16 x 64-bit words = 128 bytes) - Offset counters
t(2 x 64-bit words, tracks bytes processed) - Final block flag
f(1 byte, marks last block)
h' by mixing the message into the state over multiple rounds.
Complete Blake2b Hashing
To hash a message completely using Blake2f:- Initialize state h with Blake2b IV
- Process each 128-byte block:
- Call Blake2f with current state
- Update offset counter t
- Final block: set f=0x01
- State h is the hash output
Gas Cost Efficiency
Blake2f is extremely gas-efficient:- 12 rounds = 12 gas
- Processes 128 bytes per compression
- ~0.09 gas/byte (cheaper than all other hash functions)
- Blake2f: ~12 gas
- SHA256: ~108 gas (60 + 12*4)
- Keccak256: ~66 gas (30 + 6*4)

