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
Address: 0x0000000000000000000000000000000000000002
Introduced: Frontier
The SHA256 precompile implements the SHA-256 cryptographic hash function, producing a 32-byte hash of arbitrary input data. SHA-256 is part of the SHA-2 family standardized by NIST and is widely used in Bitcoin and other systems.
This precompile enables Ethereum contracts to verify Bitcoin SPV proofs, validate SHA-256 based signatures, and interact with systems that use SHA-256 hashing.
Gas Cost
Formula: 60 + 12 * ceil(input_length / 32)
- Base cost:
60 gas
- Per-word cost:
12 gas per 32-byte word
- Partial words round up
Examples:
- 0 bytes: 60 gas
- 32 bytes: 72 gas (60 + 12*1)
- 33 bytes: 84 gas (60 + 12*2)
- 64 bytes: 84 gas (60 + 12*2)
Accepts arbitrary-length byte array. No restrictions on input size.
Total output length: 32 bytes (256 bits)
Usage Example
Error Conditions
- Out of gas (insufficient for 60 + 12 * ceil(len/32))
Use Cases
- Bitcoin SPV proofs: Verify Bitcoin block headers and transactions in Ethereum contracts
- Cross-chain bridges: Validate proofs from SHA-256 based blockchains
- Legacy system integration: Interface with systems using SHA-256 hashing
- Document verification: Hash and verify document integrity
- Merkle trees: Build SHA-256 based Merkle trees for data verification
Implementation Details
- Zig: Uses hardware-accelerated SHA-256 implementation from crypto module
- TypeScript: Wraps SHA256.hash from crypto module
- Integration: Standalone, no dependencies on other primitives
- Performance: Optimized for throughput with SIMD instructions where available
Test Vectors
Bitcoin Integration
Bitcoin uses double SHA-256 for block hashes. To verify Bitcoin blocks in Ethereum:
SHA-256 is more expensive than Keccak256 on Ethereum (60 vs 30 base gas). Use Keccak256 for Ethereum-native hashing when possible.
Gas costs favor larger batches:
- Per-byte cost: ~0.375 gas/byte
- Prefer hashing larger inputs over multiple small ones
References
Specifications