mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 17:11:31 +01:00
Use optimized goldilocks in codebase (#26)
* gl * stage 1 optimizations * working optimized poseidon * Fix posedion tests * in progress gate type refactor * working gates * working e2e * hm' * hm2 * debug saga continues * more debugging cry * more debug * it finally works * optimizations * more optimizations * new changes * more optimizations * more cleanup * some refactoring * new files * flattening of packages * working commit * more refactor * more flattening * more flattening * more more refactor * more optimizations * more optimizations * more optimizations * plonk benchmark * plonk * fix r1cs * resolve kevin's comments * Update goldilocks/base.go Co-authored-by: Kevin Jue <kjue235@gmail.com> * Update goldilocks/base.go Co-authored-by: Kevin Jue <kjue235@gmail.com> * Update goldilocks/base.go Co-authored-by: Kevin Jue <kjue235@gmail.com> * Update goldilocks/quadratic_extension.go Co-authored-by: Kevin Jue <kjue235@gmail.com> * fix: resolve kevin's confusion --------- Co-authored-by: Kevin Jue <kjue235@gmail.com>
This commit is contained in:
51
types/circuit.go
Normal file
51
types/circuit.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
)
|
||||
|
||||
type Proof struct {
|
||||
WiresCap FriMerkleCap // length = 2^CircuitConfig.FriConfig.CapHeight
|
||||
PlonkZsPartialProductsCap FriMerkleCap // length = 2^CircuitConfig.FriConfig.CapHeight
|
||||
QuotientPolysCap FriMerkleCap // length = 2^CircuitConfig.FriConfig.CapHeight
|
||||
Openings OpeningSet
|
||||
OpeningProof FriProof
|
||||
}
|
||||
|
||||
type ProofWithPublicInputs struct {
|
||||
Proof Proof
|
||||
PublicInputs []gl.Variable // Length = CommonCircuitData.NumPublicInputs
|
||||
}
|
||||
|
||||
type VerifierOnlyCircuitData struct {
|
||||
ConstantSigmasCap FriMerkleCap
|
||||
CircuitDigest poseidon.BN254HashOut
|
||||
}
|
||||
|
||||
type CircuitConfig struct {
|
||||
NumWires uint64
|
||||
NumRoutedWires uint64
|
||||
NumConstants uint64
|
||||
UseBaseArithmeticGate bool
|
||||
SecurityBits uint64
|
||||
NumChallenges uint64
|
||||
ZeroKnowledge bool
|
||||
MaxQuotientDegreeFactor uint64
|
||||
FriConfig FriConfig
|
||||
}
|
||||
|
||||
type CommonCircuitData struct {
|
||||
Config CircuitConfig
|
||||
FriParams FriParams
|
||||
Gates []gates.Gate
|
||||
SelectorsInfo gates.SelectorsInfo
|
||||
DegreeBits uint64
|
||||
QuotientDegreeFactor uint64
|
||||
NumGateConstraints uint64
|
||||
NumConstants uint64
|
||||
NumPublicInputs uint64
|
||||
KIs []gl.Variable
|
||||
NumPartialProducts uint64
|
||||
}
|
||||
99
types/fri.go
Normal file
99
types/fri.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
|
||||
)
|
||||
|
||||
type PolynomialCoeffs struct {
|
||||
Coeffs []gl.QuadraticExtensionVariable
|
||||
}
|
||||
|
||||
func NewPolynomialCoeffs(numCoeffs uint64) PolynomialCoeffs {
|
||||
return PolynomialCoeffs{Coeffs: make([]gl.QuadraticExtensionVariable, numCoeffs)}
|
||||
}
|
||||
|
||||
type FriConfig struct {
|
||||
RateBits uint64
|
||||
CapHeight uint64
|
||||
ProofOfWorkBits uint64
|
||||
NumQueryRounds uint64
|
||||
// TODO: add FriReductionStrategy
|
||||
}
|
||||
|
||||
func (fc *FriConfig) Rate() float64 {
|
||||
return 1.0 / float64((uint64(1) << fc.RateBits))
|
||||
}
|
||||
|
||||
type FriParams struct {
|
||||
Config FriConfig
|
||||
Hiding bool
|
||||
DegreeBits uint64
|
||||
ReductionArityBits []uint64
|
||||
}
|
||||
|
||||
type FriMerkleCap = []poseidon.BN254HashOut
|
||||
|
||||
func NewFriMerkleCap(capHeight uint64) FriMerkleCap {
|
||||
return make([]poseidon.BN254HashOut, 1<<capHeight)
|
||||
}
|
||||
|
||||
type FriMerkleProof struct {
|
||||
Siblings []poseidon.BN254HashOut // Length = CircuitConfig.FriConfig.DegreeBits + CircuitConfig.FriConfig.RateBits - CircuitConfig.FriConfig.CapHeight
|
||||
}
|
||||
|
||||
func NewFriMerkleProof(merkleProofLen uint64) FriMerkleProof {
|
||||
return FriMerkleProof{Siblings: make([]poseidon.BN254HashOut, merkleProofLen)}
|
||||
}
|
||||
|
||||
type FriEvalProof struct {
|
||||
Elements []gl.Variable // Length = [CommonCircuitData.Constants + CommonCircuitData.NumRoutedWires, CommonCircuitData.NumWires + CommonCircuitData.FriParams.Hiding ? 4 : 0, CommonCircuitData.NumChallenges * (1 + CommonCircuitData.NumPartialProducts) + salt, CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor + salt]
|
||||
MerkleProof FriMerkleProof
|
||||
}
|
||||
|
||||
func NewFriEvalProof(elements []gl.Variable, merkleProof FriMerkleProof) FriEvalProof {
|
||||
return FriEvalProof{Elements: elements, MerkleProof: merkleProof}
|
||||
}
|
||||
|
||||
type FriInitialTreeProof struct {
|
||||
EvalsProofs []FriEvalProof // Length = 4
|
||||
}
|
||||
|
||||
func NewFriInitialTreeProof(evalsProofs []FriEvalProof) FriInitialTreeProof {
|
||||
return FriInitialTreeProof{EvalsProofs: evalsProofs}
|
||||
}
|
||||
|
||||
type FriQueryStep struct {
|
||||
Evals []gl.QuadraticExtensionVariable // Length = [2^arityBit for arityBit in CommonCircuitData.FriParams.ReductionArityBits]
|
||||
MerkleProof FriMerkleProof // Length = [regularSize - arityBit for arityBit in CommonCircuitData.FriParams.ReductionArityBits]
|
||||
}
|
||||
|
||||
func NewFriQueryStep(arityBit uint64, merkleProofLen uint64) FriQueryStep {
|
||||
return FriQueryStep{
|
||||
Evals: make([]gl.QuadraticExtensionVariable, 1<<arityBit),
|
||||
MerkleProof: NewFriMerkleProof(merkleProofLen),
|
||||
}
|
||||
}
|
||||
|
||||
type FriQueryRound struct {
|
||||
InitialTreesProof FriInitialTreeProof
|
||||
Steps []FriQueryStep // Length = Len(CommonCircuitData.FriParams.ReductionArityBits)
|
||||
}
|
||||
|
||||
func NewFriQueryRound(steps []FriQueryStep, initialTreesProof FriInitialTreeProof) FriQueryRound {
|
||||
return FriQueryRound{InitialTreesProof: initialTreesProof, Steps: steps}
|
||||
}
|
||||
|
||||
type FriProof struct {
|
||||
CommitPhaseMerkleCaps []FriMerkleCap // Length = Len(CommonCircuitData.FriParams.ReductionArityBits)
|
||||
QueryRoundProofs []FriQueryRound // Length = CommonCircuitData.FriConfig.FriParams.NumQueryRounds
|
||||
FinalPoly PolynomialCoeffs
|
||||
PowWitness gl.Variable
|
||||
}
|
||||
|
||||
type FriChallenges struct {
|
||||
FriAlpha gl.QuadraticExtensionVariable
|
||||
FriBetas []gl.QuadraticExtensionVariable
|
||||
FriPowResponse gl.Variable
|
||||
FriQueryIndices []gl.Variable
|
||||
}
|
||||
33
types/plonk.go
Normal file
33
types/plonk.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package types
|
||||
|
||||
import gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
|
||||
|
||||
type OpeningSet struct {
|
||||
Constants []gl.QuadraticExtensionVariable // Length = CommonCircuitData.Constants
|
||||
PlonkSigmas []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumRoutedWires
|
||||
Wires []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumWires
|
||||
PlonkZs []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumChallenges
|
||||
PlonkZsNext []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumChallenges
|
||||
PartialProducts []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumChallenges * CommonCircuitData.NumPartialProducts
|
||||
QuotientPolys []gl.QuadraticExtensionVariable // Length = CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor
|
||||
}
|
||||
|
||||
func NewOpeningSet(numConstants uint64, numRoutedWires uint64, numWires uint64, numChallenges uint64, numPartialProducts uint64, quotientDegreeFactor uint64) OpeningSet {
|
||||
return OpeningSet{
|
||||
Constants: make([]gl.QuadraticExtensionVariable, numConstants),
|
||||
PlonkSigmas: make([]gl.QuadraticExtensionVariable, numRoutedWires),
|
||||
Wires: make([]gl.QuadraticExtensionVariable, numWires),
|
||||
PlonkZs: make([]gl.QuadraticExtensionVariable, numChallenges),
|
||||
PlonkZsNext: make([]gl.QuadraticExtensionVariable, numChallenges),
|
||||
PartialProducts: make([]gl.QuadraticExtensionVariable, numChallenges*numPartialProducts),
|
||||
QuotientPolys: make([]gl.QuadraticExtensionVariable, numChallenges*quotientDegreeFactor),
|
||||
}
|
||||
}
|
||||
|
||||
type ProofChallenges struct {
|
||||
PlonkBetas []gl.Variable
|
||||
PlonkGammas []gl.Variable
|
||||
PlonkAlphas []gl.Variable
|
||||
PlonkZeta gl.QuadraticExtensionVariable
|
||||
FriChallenges FriChallenges
|
||||
}
|
||||
Reference in New Issue
Block a user