lp: 4084 title: Combined-Pair Miller Loop description: A fused k-pair Miller loop for BLS12-381 batch pairing that interleaves all pairs through one 64-step ate loop, eliminating k-1 full Fp12 multiplications and reducing k+1 dispatches to one author: Lux Core Team (@luxfi) discussions-to: https://github.com/luxfi/lps/discussions status: Final implementation-rust: none implementation-cpp: partial implementation-go: shipped type: Standards Track category: Core tags: [pairing, bls12-381, miller-loop, arithmetic, gpu, batch-verify]
- lp-4110
- lp-4040
Abstract
A fused k-pair Miller loop for BLS12-381 batch pairing verification.
It replaces k independent Miller-loop dispatches plus a separate Fp12
product with a single kernel that interleaves all k pairs through one
shared 64-step ate loop, accumulating f_k = ∏ f_i line by line.
Two costs disappear at once: k − 1 full Fp12 multiplications, and the
dispatch count drops from k + 1 round trips to 1. Measured on Apple
M1 Max at k = 1024 (batched bridge pairing verification): 9.5×.
Specification
Algorithm
The BLS12-381 ate Miller loop runs over the binary expansion of
|x| = 0xD201000000010000, NAF length 64. For a single pair (P, Q):
f = 1
T = Q
for i in 62..0:
f = f^2 * line(T, T, P)
T = 2T
if x_i == 1:
f = f * line(T, Q, P)
T = T + Q
For k pairs, interleave the k line evaluations per Miller bit and
fold them into one accumulator:
f = 1
T_0..T_{k-1} = Q_0..Q_{k-1}
for i in 62..0:
f = f^2
for j in 0..k-1:
f = f * line(T_j, T_j, P_j)
T_j = 2 * T_j
if x_i == 1:
for j in 0..k-1:
f = f * line(T_j, Q_j, P_j)
T_j = T_j + Q_j
The k line evaluations within a bit are independent — no cross-pair
dependency — and parallelize cleanly. The f updates are serial within
a bit, but they are the same Fp12 chain the unfused version would run
at the end anyway. That is where the saving comes from: k − 1
Fp12-by-Fp12 multiplications are replaced by k Fp12-by-sparse-line
multiplications, each roughly 6× cheaper.
Determinism
Line accumulation order is fixed: j = 0 first, ascending. Squaring is
the same per-bit canonical squaring as the single-pair loop. Final
exponentiation runs once, on the combined f. CPU, Metal, CUDA and WGSL
produce byte-equal Fp12 output; the equality test runs k ∈ {1, 2, 4,
8, 16, 64, 256, 1024} × 100 random (P, Q) batches.
Performance
k | Per-pair Miller + product | Fused | Ratio |
|---|---|---|---|
| 1024 | 99,040 ms | 10,425 ms | 9.50× |
That row is the only one backed by a measurement on this host. Smaller
k rows are deliberately omitted: the algorithmic transform is
identical at every k, but the wall-clock ratio is
dispatch-overhead-bounded at small k and therefore device-specific.
Publishing an interpolated row would be publishing a guess.
Implementation
CPU canonical
luxcpp/crypto/bls/cpp/bls_combined_miller.{hpp,cpp}, templated over a
compile-time pair_count with a dynamic runtime fallback above the
template ceiling. It calls the existing Fp12 operations in
bls_pairing.cpp — only the loop-and-accumulate skeleton is new.
GPU kernels
bls_combined_miller.{metal,cu,wgsl} plus host drivers. Metal is the
canonical reference; CUDA and WGSL are ports of it.
C-ABI
// k-pair fused Miller + final exponentiation
int bls12_381_pairing_check_batch(const uint8_t *P_pairs, // k * 96 bytes G1 affine
const uint8_t *Q_pairs, // k * 192 bytes G2 affine
uint32_t k,
uint8_t *verdict); // 0/1 byte
// k-pair fused Miller WITHOUT final exp (caller wants raw Fp12 product)
int bls12_381_combined_miller(const uint8_t *P_pairs,
const uint8_t *Q_pairs,
uint32_t k,
uint8_t *fp12_out); // 576 bytes
Determinism harness
bls_combined_miller_test.{cpp,mm,cu} — k ∈ {1, 2, 4, 8, 16, 64,
256, 1024}, 100 random pair batches per k, byte-equal across all
backends. Cross-oracles: blst blst_miller_loop_n and arkworks
Bls12_381::multi_pairing, both test-only.
Security Considerations
- Pairs are public inputs on the verification path, so variable-time line evaluation is acceptable. This is not a constant-time primitive and MUST NOT be used to pair secret-key inputs.
- The
T_jupdates are independent acrossj, so a malformedQ_jcannot influence the line evaluation for a different pair. Subgroup checks on everyQ_iare still required up front. - Why one final exponentiation is sound. Final exponentiation runs
once on the combined
f. This preserves the security argument becausee(P, Q) = f^{(p^12 − 1)/r}is multiplicative:final_exp(∏ f_i) = ∏ final_exp(f_i), modulo the easy/hard split. The fused loop is not an approximation ofkpairings — it is exactly their product.
Crossover
k* = 2. Below k = 2 there is nothing to fuse and the dispatcher
routes to the single-pair loop. Template specializations cover
k ∈ {2, 4, 8, 16} with a dynamic fallback above.
References
- Vercauteren, "Optimal Pairings" (IEEE Trans. Inf. Theory, 2010)
- Costello, Lange, Naehrig, "Faster Pairing Computations on Curves with High-Degree Twists" (2010)
- Beuchat et al., "High-Speed Software Implementation of the Optimal Ate Pairing over Barreto-Naehrig Curves" (2010) — the combined-pair pattern
Copyright
Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
Licensed under the MIT License.