Crypto module, including support for elliptic curve operations on BLS12-381 and BN254 curves.
Accessing Crypto Functions
Access cryptographic functions through the environment:Hash Functions
SHA-256
Compute SHA-256 hash of data:Keccak-256
Compute Keccak-256 hash (used in Ethereum):Digital Signatures
ED25519
Verify ED25519 signatures:ECDSA secp256k1
Recover public key from signature:ECDSA secp256r1
Verify secp256r1 signatures:BLS12-381 Curve Operations
The BLS12-381 curve is used for pairing-based cryptography and BLS signatures.Accessing BLS12-381
Field Elements
G1 Point Operations
G2 Point Operations
Hash to Curve
Map arbitrary data to curve points:Pairing Operations
Perform pairing checks for signature verification:Scalar Field Arithmetic
BN254 Curve Operations
BN254 (alt_bn128) is Ethereum-compatible and commonly used in zkSNARKs.Accessing BN254
G1 Operations
Pairing Check (Ethereum-compatible)
Best Practices
Use Checked Operations for Subgroup Safety
When aggregating multiple points, use checked operations on the final result:Hash Type Safety
TheHash<N> type ensures values come from cryptographic hash functions:
Hazmat Crypto
Low-level operations are available but should be used with caution:Performance Considerations
- MSM operations are optimized for multiple scalar multiplications
- Subgroup checks are expensive; minimize their use in loops
- Pairing operations are the most expensive; batch verifications when possible
- BLS12-381 operations are generally slower but more secure than BN254
- BN254 operations are faster and Ethereum-compatible