Documentation
¶
Overview ¶
Package zk provides GPU-accelerated zero-knowledge proof operations.
Supports NTT, MSM, polynomial arithmetic, Poseidon2 hashing, FRI folding, and commitment schemes. All operations use unified accel backend selection with automatic fallback to CPU implementations.
Index ¶
- Variables
- func BatchCommitPoly(params CommitParams, coeffsList [][][]byte, srs [][]byte) ([][]byte, error)
- func BatchINTT(params NTTParams, polys [][]uint64) ([][]uint64, error)
- func BatchNTT(params NTTParams, polys [][]uint64) ([][]uint64, error)
- func BatchPoseidon2Hash(params Poseidon2Params, lefts, rights []uint64) ([]uint64, error)
- func CommitPoly(params CommitParams, coeffs [][]byte, srs [][]byte) ([]byte, error)
- func FRIFold(params FRIParams, evals []uint64, alpha uint64) ([]uint64, error)
- func FRIQueryPhase(params FRIParams, evals []uint64, indices []uint32) ([][]uint64, error)
- func FieldAdd(params FieldParams, a, b []uint64) ([]uint64, error)
- func FieldExp(params FieldParams, a []uint64, exp uint64) ([]uint64, error)
- func FieldInv(params FieldParams, a []uint64) ([]uint64, error)
- func FieldMul(params FieldParams, a, b []uint64) ([]uint64, error)
- func INTT(params NTTParams, evals []uint64) ([]uint64, error)
- func MSM(curve CurveType, scalars, points [][]byte) ([]byte, error)
- func MSMBatch(curve CurveType, scalars, points [][][]byte) ([][]byte, error)
- func NTT(params NTTParams, coeffs []uint64) ([]uint64, error)
- func PolyAdd(params FieldParams, a, b []uint64) ([]uint64, error)
- func PolyEval(params FieldParams, coeffs, points []uint64) ([]uint64, error)
- func PolyInterpolate(params FieldParams, xs, ys []uint64) ([]uint64, error)
- func PolyMul(params NTTParams, a, b []uint64) ([]uint64, error)
- func PolyMulPointwise(params FieldParams, a, b []uint64) ([]uint64, error)
- func PolySub(params FieldParams, a, b []uint64) ([]uint64, error)
- func Poseidon2(params Poseidon2Params, inputs []uint64) (uint64, error)
- func Poseidon2Hash(params Poseidon2Params, left, right uint64) (uint64, error)
- type CommitParams
- type CurveType
- type FRIParams
- type FieldParams
- type NTTParams
- type Poseidon2Params
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidInput = errors.New("zk: invalid input") ErrInvalidDegree = errors.New("zk: invalid polynomial degree") ErrInvalidModulus = errors.New("zk: invalid modulus") ErrDimensionMismatch = errors.New("zk: dimension mismatch") ErrEmptyBatch = errors.New("zk: empty batch") )
Errors
Functions ¶
func BatchCommitPoly ¶
func BatchCommitPoly(params CommitParams, coeffsList [][][]byte, srs [][]byte) ([][]byte, error)
BatchCommitPoly computes multiple polynomial commitments in parallel.
func BatchPoseidon2Hash ¶
func BatchPoseidon2Hash(params Poseidon2Params, lefts, rights []uint64) ([]uint64, error)
BatchPoseidon2Hash computes multiple Poseidon2 hashes in parallel. Used for building Merkle trees efficiently.
func CommitPoly ¶
func CommitPoly(params CommitParams, coeffs [][]byte, srs [][]byte) ([]byte, error)
CommitPoly computes a polynomial commitment (KZG). coeffs: polynomial coefficients srs: structured reference string (powers of tau) Returns commitment point in compressed form.
func FRIFold ¶
FRIFold performs FRI folding step. evals: polynomial evaluations at rate-2 LDE alpha: random folding challenge Returns folded polynomial evaluations.
func FRIQueryPhase ¶
FRIQueryPhase computes query responses for FRI protocol. evals: committed polynomial evaluations indices: query indices Returns query response data.
func FieldAdd ¶
func FieldAdd(params FieldParams, a, b []uint64) ([]uint64, error)
FieldAdd adds field elements.
func FieldExp ¶
func FieldExp(params FieldParams, a []uint64, exp uint64) ([]uint64, error)
FieldExp computes a^exp mod modulus for each element.
func FieldInv ¶
func FieldInv(params FieldParams, a []uint64) ([]uint64, error)
FieldInv computes modular inverse of field elements.
func FieldMul ¶
func FieldMul(params FieldParams, a, b []uint64) ([]uint64, error)
FieldMul multiplies field elements.
func INTT ¶
INTT performs inverse Number Theoretic Transform. Transforms polynomial from evaluation to coefficient form.
func NTT ¶
NTT performs forward Number Theoretic Transform. Transforms polynomial from coefficient to evaluation form.
func PolyAdd ¶
func PolyAdd(params FieldParams, a, b []uint64) ([]uint64, error)
PolyAdd adds two polynomials coefficient-wise.
func PolyEval ¶
func PolyEval(params FieldParams, coeffs, points []uint64) ([]uint64, error)
PolyEval evaluates polynomial at given points. coeffs: [degree+1] coefficients, points: evaluation points Returns values[i] = poly(points[i])
func PolyInterpolate ¶
func PolyInterpolate(params FieldParams, xs, ys []uint64) ([]uint64, error)
PolyInterpolate computes polynomial from points using Lagrange interpolation. xs, ys: evaluation points and values Returns polynomial coefficients.
func PolyMul ¶
PolyMul multiplies two polynomials using NTT. Result is in coefficient form with degree len(a) + len(b) - 1.
func PolyMulPointwise ¶
func PolyMulPointwise(params FieldParams, a, b []uint64) ([]uint64, error)
PolyMulPointwise multiplies polynomials in NTT domain (pointwise).
func PolySub ¶
func PolySub(params FieldParams, a, b []uint64) ([]uint64, error)
PolySub subtracts two polynomials coefficient-wise.
func Poseidon2 ¶
func Poseidon2(params Poseidon2Params, inputs []uint64) (uint64, error)
Poseidon2 computes Poseidon2 hash of inputs. Returns field element as uint64 (for fields <= 64 bits) or []byte.
func Poseidon2Hash ¶
func Poseidon2Hash(params Poseidon2Params, left, right uint64) (uint64, error)
Poseidon2Hash computes Poseidon2 hash for Merkle trees. left and right are field elements to hash together.
Types ¶
type CommitParams ¶
type CommitParams struct {
Curve CurveType // Curve for commitment
Degree uint32 // Maximum polynomial degree
}
CommitParams contains parameters for polynomial commitments.
type FRIParams ¶
type FRIParams struct {
Modulus uint64 // Field modulus
FoldFactor uint32 // Folding factor (typically 2 or 4)
BlowupFactor uint32 // Reed-Solomon blowup factor
}
FRIParams contains parameters for FRI folding.
type FieldParams ¶
type FieldParams struct {
Modulus uint64 // Prime modulus
}
FieldParams contains parameters for finite field operations.
type NTTParams ¶
type NTTParams struct {
N uint32 // Polynomial degree (power of 2)
Modulus uint64 // Prime modulus
Root uint64 // Primitive N-th root of unity mod Modulus
}
NTTParams contains parameters for Number Theoretic Transform.
type Poseidon2Params ¶
type Poseidon2Params struct {
T uint32 // State width (t)
D uint32 // S-box degree (typically 5 or 7)
RoundsF uint32 // Full rounds
RoundsP uint32 // Partial rounds
Modulus uint64 // Field modulus
RoundConst []uint64 // Round constants
MDS []uint64 // MDS matrix (t x t)
}
Poseidon2Params contains parameters for Poseidon2 hash.