Expand description
BN254 scalar-field batch-inverse reference implementation
(SIMD-XXXX-alt-bn128-fr-batch-inverse).
Computes (s₁⁻¹, …, sₙ⁻¹) in the BN254 scalar field Fr using
Montgomery’s batch-inverse trick. Cost: 1 modular inverse + 3·(n−1)
multiplications, regardless of n. Same surface as halo2curves’s
Field::batch_invert and arkworks’s batch_inversion — re-implemented
here as a no_std reference for the agave native syscall to mirror.
§Algorithm
Given s = (s₀, s₁, …, s_{n-1}):
- Forward pass: compute prefix products
p[i] = s₀ · s₁ · … · sᵢ. - One inverse:
inv_total = (s₀ · … · s_{n-1})⁻¹. - Backward pass: at step
i(from n-1 down to 1):sᵢ⁻¹ = inv_total · p[i-1]inv_total *= sᵢ(soinv_totalbecomes(s₀ · … · sᵢ₋₁)⁻¹)
- At step 0:
s₀⁻¹ = inv_total.
Output is the inverses (s₀⁻¹, …, s_{n-1}⁻¹) in input order.
Enums§
Functions§
- batch_
inverse - Compute the inverses of
scalarsin batch via Montgomery’s trick. Returns inverses in the same order as the input.