Files
crypto/ipa/common/common.go
T
Hanzo AI 22b99bca01 banderwagon: extract canonical home, ipa imports from here
The Banderwagon prime-order group used by Verkle / IPA had been vendored
internally under lux/crypto/ipa/banderwagon. Extract it to
lux/crypto/banderwagon as the canonical Lux public surface; rewrite all
internal ipa callers (prover, verifier, config, multiproof, common,
transcript, test_helper, tests) to import from the canonical home.

- Provenance comment on every file: github.com/crate-crypto/go-ipa
  (Apache-2.0 / MIT dual). Adds LICENSE-GO-IPA-APACHE2 and
  LICENSE-GO-IPA-MIT alongside the package.
- Element / Generator / Identity / Fr / MSMPrecomp / PrecompPoint /
  CompressedSize / UncompressedSize / SetBytes / SetBytesUncompressed /
  ElementsToBytes / BatchToBytesUncompressed / BatchNormalize /
  MapToScalarField / BatchMapToScalarField / Add / Sub / Double / Neg /
  ScalarMul / MultiExp now have one and only one home: lux/crypto/banderwagon.
- Verkle (parallel branch) will switch its banderwagon import to this
  canonical surface.
- KAT vectors from the upstream go-ipa Verkle reference suite preserved
  (TestEncodingFixedVectors, TestPointAtInfinityComponent) plus all
  precomp MSM-vs-gnark random-round tests (1000 * NumCPU rounds).

Tests: go test ./banderwagon/... ./ipa/... — all PASS (banderwagon 27s,
ipa 16s, ipa/bandersnatch 24s, fp/fr 4s+2s, common 3s).
2025-12-28 06:21:30 -08:00

52 lines
1.4 KiB
Go

package common
import (
"fmt"
"io"
"github.com/luxfi/crypto/banderwagon"
"github.com/luxfi/crypto/ipa/bandersnatch/fr"
)
// VectorLength is the number of elements in the vector. This value is fixed.
// Note that this means that the degree of the polynomial is one less than this value.
const VectorLength = 256
// PowersOf returns powers of x from 0 to degree-1: <1, x, x^2, ..., x^(degree-1)>.
// Used for polynomial evaluation and computing challenge powers in IPA proofs.
func PowersOf(x fr.Element, degree int) []fr.Element {
result := make([]fr.Element, degree)
result[0] = fr.One()
for i := 1; i < degree; i++ {
result[i].Mul(&result[i-1], &x)
}
return result
}
func ReadPoint(r io.Reader) (*banderwagon.Element, error) {
var x = make([]byte, 32)
if _, err := io.ReadAtLeast(r, x, 32); err != nil {
return nil, fmt.Errorf("reading x coordinate: %w", err)
}
var p = &banderwagon.Element{}
if err := p.SetBytes(x); err != nil {
return nil, fmt.Errorf("deserializing point: %w", err)
}
return p, nil
}
func ReadScalar(r io.Reader) (*fr.Element, error) {
var x = make([]byte, 32)
if _, err := io.ReadAtLeast(r, x, 32); err != nil {
return nil, fmt.Errorf("reading scalar: %w", err)
}
var scalar = &fr.Element{}
if _, err := scalar.SetBytesLECanonical(x); err != nil {
return nil, fmt.Errorf("deserializing scalar: %s", err)
}
return scalar, nil
}