LPsLux Proposals
Q-Chain
LP-4082

lp-4082-multi-curve-pippenger-msm


lp: 4082 title: Multi-Curve Pippenger MSM description: One parameterized Pippenger multi-scalar-multiplication kernel instantiated for every curve in the corpus through curve_traits, replacing four near-identical hand-written kernels author: Lux Core Team (@luxfi) discussions-to: https://github.com/luxfi/lps/discussions status: Final implementation-rust: none implementation-cpp: shipped implementation-go: partial type: Standards Track category: Core tags: [msm, pippenger, arithmetic, gpu, secp256k1, bn254, bls12-381, banderwagon]

  • lp-4080
  • lp-4040

Abstract

A single parameterized Pippenger multi-scalar multiplication kernel, instantiated for secp256k1, BN254, BLS12-381 G1/G2 and Banderwagon through curve_traits<C>.

The headline is consolidation, not speed: four near-identical hand-written MSM kernels (≈3,200 lines) become one templated body (≈600 lines) plus about 150 lines of traits per curve. The shared kernel is a dispatch point, not a re-implementation — each curve's traits delegate to that curve's own proven library.

Cost is O(λ·n / log n) point additions for λ-bit scalars and n points, with window size c = ⌊log₂ n⌋ − 2.

Specification

Algorithm

Pippenger's bucket method:

# Inputs: points P_0..P_{n-1}, scalars k_0..k_{n-1} in [0, 2^lambda)
# Window size c, number of windows W = ceil(lambda / c)

# 1. Per-window bucket fill (parallel over points)
for w in 0..W-1:
    for i in 0..n-1:
        b = (k_i >> (w * c)) & ((1 << c) - 1)
        if b != 0:
            buckets[w][b] += P_i           # affine mixed add via batch_inv

# 2. Per-window bucket reduce (parallel over windows)
for w in 0..W-1:
    acc = 0; running = 0
    for b in (1 << c) - 1 .. 1:
        running += buckets[w][b]
        acc += running
    window_sum[w] = acc

# 3. Window combine (serial, log-depth shift-and-add)
result = window_sum[W-1]
for w in W-2 .. 0:
    result = (result << c) + window_sum[w]
return result

Step 1 uses batched Montgomery inversion (LP-4080) to amortize the affine mixed-add denominators. Step 2 is the bucket running sum — parallel across windows, serial within one. Step 3 is the canonical fold of LP-4040.

curve_traits<C>

template<typename C>
struct curve_traits {
    using point_affine    = ...;
    using point_jacobian  = ...;
    using scalar          = ...;
    static constexpr uint32_t scalar_bits;       // lambda
    static constexpr uint32_t bucket_max_bits;   // c upper bound
    static point_jacobian add (point_jacobian, point_jacobian);
    static point_jacobian add_mixed (point_jacobian, point_affine);
    static point_jacobian dbl (point_jacobian);
    static point_affine   to_affine_batch (...);  // calls gpukit_batch_inv
};

Specializations live at gpukit/gpu/curve_traits/{secp256k1,bn254,bls12_381,banderwagon}.{metal,cu,wgsl}.

Implementation status

PARTIAL:

CurveCPU canonicalDeterminism harness
secp256k1wiredKAT pass
BN254 G1wiredKAT pass
Banderwagonwired (delegates to the signed-digit multiexp body)KAT pass
BLS12-381 G1dispatcher wired, body returns GPUKIT_ERR_NOTIMPLpending

Status is Draft rather than Final until BLS12-381 G1 lands a body. The dispatcher returns GPUKIT_ERR_NOTIMPL for that curve rather than a wrong answer, and multi_pippenger_test::test_bls_notimpl asserts on exactly that contract — an honest error is part of the spec, not an omission from it.

Implementation

CPU canonical

gpukit/cpp/cpu_reference/pippenger_msm.{hpp,cpp}, templated over curve_traits<C>. The per-curve CPU MSMs become five-line forwarding wrappers.

GPU kernels

gpukit/gpu/{metal,cuda,wgsl}/pippenger_msm.* plus curve specializations under gpu/curve_traits/, with host drivers alongside.

C-ABI

int gpukit_pippenger_msm(uint8_t curve_id,
                         const uint8_t *points,    // n * point_bytes (affine)
                         const uint8_t *scalars,   // n * scalar_bytes
                         uint8_t       *out,       // 1 * point_bytes (Jacobian)
                         uint32_t       n,
                         uint32_t       window_c); // 0 = auto-pick

Per-curve wrappers are re-exported under each curve's C-ABI (secp256k1_msm, bn254_msm, bls12_381_g1_msm, bls12_381_g2_msm, banderwagon_msm). Secret scalars go through gpukit_pippenger_msm_blinded.

Determinism harness

gpukit/test/pippenger_msm_test.{cpp,mm,cu} — per curve, N ∈ {16, 64, 256, 1024, 4096}, 50 random (points, scalars) batches, byte-equal across CPU, Metal, CUDA and WGSL. Cross-oracles: gnark-crypto MultiExp, arkworks VariableBaseMSM, and secp256k1_ecmult_multi_var.

Security Considerations

  1. Bucket fill is variable-time on the bucket index b = (k_i >> w·c) & mask. For verifier-side public scalars that is fine. For prover-side secret scalars it is a direct scalar leak, and the caller MUST use gpukit_pippenger_msm_blinded — multiplicative scalar randomization before the MSM, unblind after.
  2. Subgroup membership is the caller's responsibility. Pippenger does not reject off-curve or wrong-subgroup inputs and cannot: it never looks at the curve equation. Validators subgroup-check public keys before calling.
  3. The shared batch-inversion path (LP-4080) is variable-time in its single Fermat step. That is benign here because its inputs are bucket sums, which are public.

Crossover

N* at which Pippenger beats naive serial scalar multiplication:

CurveCPUMetalCUDA
secp256k13264128
BN254 G1244896
BLS12-381 G13296192
Banderwagon163264

Below N* the dispatcher routes to per-point scalar multiplication on the curve's own precompile.

References

  • Pippenger, "On the Evaluation of Powers and Monomials" (1980)
  • Bernstein, Doumen, Lange, Oosterwijk, "Faster Batch Forgery Identification" (2012)

Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.

Licensed under the MIT License.