What You’ll Learn
- BLS12-381 curve operations
- Pairing verification in zkVM
- Differences between BN254 and BLS12-381
- Modern pairing-based cryptography
Overview
BLS12-381 is a pairing-friendly elliptic curve offering approximately 128-bit security, making it suitable for long-term cryptographic applications. It’s used by:- Ethereum 2.0: Validator signatures
- Zcash: Sapling and Orchard protocols
- Filecoin: Proof-of-Replication
- Chia: BLS signatures
BLS12-381 offers significantly better security than BN254 and is recommended for new systems.
How It Works
#![no_main]
risc0_zkvm::guest::entry!(main);
// Test pairing result against reference implementation
fn test_pairing_result_against_relic() {
let a = bls12_381::G1Affine::generator();
let b = bls12_381::G2Affine::generator();
let res = bls12_381::pairing(&a, &b);
// Verify against known constant
assert_eq!(
res.all_raw(),
[
[
0xa843_05aa_ca17_89b6,
0xb6d1_94f6_0839_c508,
0x3dd8_e90c_e98d_b3e7,
0x272d_441b_efa1_5c50,
0xa7b2_d831_68d0_d727,
0x1250_ebd8_71fc_0a92,
],
// ... remaining 11 elements
]
);
}
fn main() {
test_pairing_result_against_relic();
}
use bls12_381_methods::{BLS12_381_VERIFY_ELF, BLS12_381_VERIFY_ID};
use risc0_zkvm::{ExecutorEnv, default_prover};
fn main() {
let env = ExecutorEnv::builder()
.build()
.unwrap();
let receipt = default_prover()
.prove(env, BLS12_381_VERIFY_ELF)
.unwrap()
.receipt;
receipt.verify(BLS12_381_VERIFY_ID).unwrap();
println!("Successfully verified BLS12-381 pairing operation");
}
Running the Example
What Gets Proven?
The receipt proves:- Correct Implementation: BLS12-381 pairing computed correctly
- Deterministic Result: Matches known test vectors
- zkVM Compatibility: The curve works properly in the zkVM environment
BLS12-381 Curve Details
Parameters
- Field characteristic: 381-bit prime
- Embedding degree: 12
- Subgroup size: 255-bit prime
- Security level: ~128 bits
Groups
- G1: Points on
E(Fq)whereE: y² = x³ + 4 - G2: Points on
E'(Fq²)whereE': y² = x³ + 4(1 + i) - GT: Elements in
Fq¹²
Compressed Point Sizes
- G1: 48 bytes (compressed), 96 bytes (uncompressed)
- G2: 96 bytes (compressed), 192 bytes (uncompressed)
- GT: 576 bytes
BLS Signatures
BLS12-381 is designed for BLS (Boneh-Lynn-Shacham) signatures:Signature Scheme
Signature Aggregation
Multiple signatures can be aggregated:- Constant Size: Aggregated signature same size as single signature
- Batch Verification: Verify multiple signatures efficiently
- Non-Interactive: No coordination needed for aggregation
Ethereum 2.0 Usage
Ethereum 2.0 uses BLS12-381 for validator signatures:Why BLS12-381?
- Security: 128-bit security level
- Aggregation: Combine thousands of signatures
- Efficiency: Fast verification for aggregate signatures
- Standardization: Widely reviewed and adopted
Validator Workflow
Performance
| Operation | Cycles (approx) | Time (local) |
|---|---|---|
| G1 scalar mul | ~1M | ~1ms |
| G2 scalar mul | ~3M | ~3ms |
| Single pairing | ~20M | ~20ms |
| Hash to G1 | ~5M | ~5ms |
BLS12-381 operations are about 2x slower than BN254 but offer significantly better security.
Use Cases in zkVM
Signature Verification
Verify BLS signatures inside the zkVM:Aggregate Signature Validation
Verify aggregate signatures from multiple signers:Threshold Signatures
Implement threshold signature schemes:Cross-Chain Bridges
Verify signatures from other chains:BLS12-381 Crate
This example uses thebls12_381 crate:
Comparison: BN254 vs BLS12-381
| Feature | BN254 | BLS12-381 |
|---|---|---|
| Security | ~100 bits | ~128 bits |
| Field size | 254 bits | 381 bits |
| G1 compressed | 32 bytes | 48 bytes |
| G2 compressed | 64 bytes | 96 bytes |
| Pairing speed | Faster | Slower (~2x) |
| Hash-to-curve | Complex | Standardized |
| Ethereum | EVM precompile | ETH2 standard |
| Adoption | Legacy | Modern |
| Recommendation | Legacy only | New systems |
Security Considerations
Why 128-bit Security?
BLS12-381 provides:- Resistance to known attacks
- Safety margin for future advances
- Long-term security (20+ years)
Subgroup Checks
Always verify points are in correct subgroups:Constant-Time Operations
Thebls12_381 crate provides constant-time operations for secret values:
Standards and Specifications
Next Steps
- Implement BLS signature verification
- Explore BN254 pairing
- Study Ethereum 2.0 specifications
- Build aggregate signature schemes