Skip to main content

Crate fr_batch_inv_ref

Crate fr_batch_inv_ref 

Source
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}):

  1. Forward pass: compute prefix products p[i] = s₀ · s₁ · … · sᵢ.
  2. One inverse: inv_total = (s₀ · … · s_{n-1})⁻¹.
  3. Backward pass: at step i (from n-1 down to 1):
    • sᵢ⁻¹ = inv_total · p[i-1]
    • inv_total *= sᵢ (so inv_total becomes (s₀ · … · sᵢ₋₁)⁻¹)
  4. At step 0: s₀⁻¹ = inv_total.

Output is the inverses (s₀⁻¹, …, s_{n-1}⁻¹) in input order.

Enums§

Error

Functions§

batch_inverse
Compute the inverses of scalars in batch via Montgomery’s trick. Returns inverses in the same order as the input.