Overview
Address:0x0000000000000000000000000000000000000010
Introduced: Prague (EIP-2537)
EIP: EIP-2537
The BLS12-381 G2 MSM (multi-scalar multiplication) precompile efficiently computes the sum of multiple scalar multiplications on G2 points: scalar1*point1 + scalar2*point2 + ... + scalarN*pointN. This operation is critical for batch signature verification, proof aggregation, and efficient cryptographic protocols over extension fields.
MSM provides significant gas savings through bulk discounts when performing multiple scalar multiplications.
Gas Cost
Formula:(BASE_GAS * k * discount(k)) / 1000
Where:
- BASE_GAS: 45,000
- k: Number of point-scalar pairs
- discount(k): Discount multiplier based on batch size
Discount Table
| Pairs (k) | Discount | Example Gas |
|---|---|---|
| 1 | 1000 | 45,000 |
| 2 | 820 | 73,800 |
| 4 | 580 | 104,400 |
| 8 | 430 | 154,800 |
| 16 | 320 | 230,400 |
| 32 | 250 | 360,000 |
| 64 | 200 | 576,000 |
| 128 | 174 | 1,003,200 |
G2 vs G1 MSM
G2 MSM characteristics:- G1 base gas: 12,000
- G2 base gas: 45,000 (3.75x more expensive)
- Reason: Fp2 extension field arithmetic complexity
- Discount schedule: Same for both G1 and G2
- Point size: G2 uses 256 bytes vs G1’s 128 bytes
- Input size: 288 bytes per pair (256 point + 32 scalar) vs G1’s 160 bytes
Input Format
288 * k bytes (must be exact multiple of 288)
Each G2 point is 256 bytes (4 x 64-byte Fp2 components), followed by 32-byte scalar.
Output Format
Usage Example
TypeScript
Zig
Error Conditions
- Out of gas: gasLimit < calculated gas cost
- Invalid input length: input.len % 288 != 0 or input.len == 0
- Empty input: Must have at least one pair
- Point not on curve: Any point doesn’t satisfy G2 curve equation
- Invalid field element: Coordinate component >= field modulus
- Subgroup check failure: Points not in correct subgroup
Use Cases
- Batch signature verification: Verify multiple BLS signatures efficiently
- Proof aggregation: Combine multiple zero-knowledge proofs
- Multi-signature schemes: Aggregate signatures from multiple parties
- Threshold cryptography: Combine signature shares with coefficients
- Ethereum 2.0 consensus: Batch verify validator signatures
- Cross-chain bridges: Aggregate attestations efficiently
Implementation Details
- Zig: Uses BLST library with optimized MSM algorithms
- TypeScript: Leverages @noble/curves bls12-381 batch operations
- Algorithm: Pippenger’s algorithm for optimal batch multiplication
- Optimization: Exploits shared computation across multiplications
- Security: Constant-time execution within discount tiers
Gas Savings Analysis
Comparing MSM vs individual multiplications:- 2 pairs: 18% savings
- 4 pairs: 42% savings
- 8 pairs: 57% savings
- 16 pairs: 68% savings
- 64 pairs: 80% savings
Extension Field Complexity
G2 MSM operates over Fp2:- Each point operation requires Fp2 arithmetic
- Fp2 multiplication: ~4x cost of Fp multiplication
- Pippenger’s algorithm: Amortizes point operations
- Trade-off: More memory for precomputed tables, fewer point operations
Performance Considerations
- Batch threshold: MSM becomes beneficial at 2+ pairs
- Memory usage: Precomputation tables scale with input size
- Optimal batch size: 16-64 pairs balances cost and memory
- Point at infinity: Zero scalars handled efficiently
- Input validation: All points validated before computation
Practical Example: Signature Aggregation
Discount Calculation Details
The discount schedule follows EIP-2537:Test Vectors
Special Cases
- All zero scalars: Returns point at infinity
- Single non-zero scalar: Equivalent to G2 mul (but more expensive)
- Point at infinity in input: Contributes identity to sum
- Duplicate points: Handled correctly, scalars are summed
- Mixed identity and non-identity: Only non-identity points contribute
Security Considerations
- Subgroup validation: All points checked for correct subgroup membership
- Scalar overflow: Scalars automatically reduced modulo curve order
- Side-channel resistance: Implementation uses constant-time algorithms
- Memory bounds: Input size limited by gas and block limits
Gas Cost Justification
The 45,000 base gas reflects:- Extension field operations: Fp2 arithmetic overhead
- Pippenger’s algorithm: Precomputation and bucket operations
- Point validation: Subgroup checks for all inputs
- Security overhead: Constant-time guarantees
When to Use MSM
✅ Use MSM when:- Processing 2+ point-scalar pairs
- Batch verifying signatures
- Aggregating proofs or attestations
- Gas optimization is critical
- Single scalar multiplication (use G2 mul directly)
- Points/scalars not known upfront
- Input preparation cost exceeds savings

