diff --git a/challenger/challenger.go b/challenger/challenger.go index 91e656d..b61f2a5 100644 --- a/challenger/challenger.go +++ b/challenger/challenger.go @@ -7,6 +7,7 @@ import ( "github.com/succinctlabs/gnark-plonky2-verifier/fri" gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon" + "github.com/succinctlabs/gnark-plonky2-verifier/types" "github.com/succinctlabs/gnark-plonky2-verifier/variables" ) @@ -117,7 +118,7 @@ func (c *Chip) GetFriChallenges( finalPoly variables.PolynomialCoeffs, powWitness gl.Variable, degreeBits uint64, - config variables.FriConfig, + config types.FriConfig, ) variables.FriChallenges { numFriQueries := config.NumQueryRounds friAlpha := c.GetExtensionChallenge() diff --git a/fri/fri.go b/fri/fri.go index 86aedfa..9483ace 100644 --- a/fri/fri.go +++ b/fri/fri.go @@ -10,6 +10,7 @@ import ( "github.com/consensys/gnark/frontend" gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon" + "github.com/succinctlabs/gnark-plonky2-verifier/types" "github.com/succinctlabs/gnark-plonky2-verifier/variables" ) @@ -17,12 +18,12 @@ type Chip struct { api frontend.API `gnark:"-"` gl gl.Chip `gnark:"-"` poseidonBN254Chip *poseidon.BN254Chip - friParams *variables.FriParams `gnark:"-"` + friParams *types.FriParams `gnark:"-"` } func NewChip( api frontend.API, - friParams *variables.FriParams, + friParams *types.FriParams, ) *Chip { poseidonBN254Chip := poseidon.NewBN254Chip(api) return &Chip{ @@ -33,7 +34,7 @@ func NewChip( } } -func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig variables.FriConfig) { +func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) { // Asserts that powWitness'es big-endian bit representation has at least `leading_zeros` leading zeros. // Note that this is assuming that the Goldilocks field is being used. Specfically that the // field is 64 bits long diff --git a/plonk/gates/selectors.go b/plonk/gates/types.go similarity index 100% rename from plonk/gates/selectors.go rename to plonk/gates/types.go diff --git a/types/types.go b/types/types.go new file mode 100644 index 0000000..c9b744f --- /dev/null +++ b/types/types.go @@ -0,0 +1,20 @@ +package types + +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 +} diff --git a/variables/circuit.go b/variables/circuit.go index 81ee9bd..fe73b22 100644 --- a/variables/circuit.go +++ b/variables/circuit.go @@ -4,6 +4,7 @@ import ( gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" "github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon" + "github.com/succinctlabs/gnark-plonky2-verifier/types" ) type Proof struct { @@ -33,12 +34,12 @@ type CircuitConfig struct { NumChallenges uint64 ZeroKnowledge bool MaxQuotientDegreeFactor uint64 - FriConfig FriConfig + FriConfig types.FriConfig } type CommonCircuitData struct { Config CircuitConfig - FriParams FriParams + FriParams types.FriParams Gates []gates.Gate SelectorsInfo gates.SelectorsInfo DegreeBits uint64 diff --git a/variables/fri.go b/variables/fri.go index fdcecfc..3042a87 100644 --- a/variables/fri.go +++ b/variables/fri.go @@ -13,25 +13,6 @@ 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 { diff --git a/verifier/deserialize.go b/verifier/deserialize.go index 3498ad5..7bdd8d2 100644 --- a/verifier/deserialize.go +++ b/verifier/deserialize.go @@ -297,33 +297,34 @@ func DeserializeProofWithPublicInputs(path string) variables.ProofWithPublicInpu return proofWithPis } -func DeserializeProofChallenges(path string) variables.ProofChallenges { - jsonFile, err := os.Open(path) - if err != nil { - panic(err) - } - - defer jsonFile.Close() - rawBytes, _ := io.ReadAll(jsonFile) - - var raw ProofChallengesRaw - err = json.Unmarshal(rawBytes, &raw) - if err != nil { - panic(err) - } - - var proofChallenges variables.ProofChallenges - proofChallenges.PlonkBetas = gl.Uint64ArrayToVariableArray(raw.PlonkBetas) - proofChallenges.PlonkGammas = gl.Uint64ArrayToVariableArray(raw.PlonkGammas) - proofChallenges.PlonkAlphas = gl.Uint64ArrayToVariableArray(raw.PlonkAlphas) - proofChallenges.PlonkZeta = gl.Uint64ArrayToQuadraticExtension(raw.PlonkZeta) - proofChallenges.FriChallenges.FriAlpha = gl.Uint64ArrayToQuadraticExtension(raw.FriChallenges.FriAlpha) - proofChallenges.FriChallenges.FriBetas = gl.Uint64ArrayToQuadraticExtensionArray(raw.FriChallenges.FriBetas) - proofChallenges.FriChallenges.FriPowResponse = gl.NewVariable(raw.FriChallenges.FriPowResponse) - proofChallenges.FriChallenges.FriQueryIndices = gl.Uint64ArrayToVariableArray(raw.FriChallenges.FriQueryIndices) - - return proofChallenges -} +// TODO: this seemed unused? +// func DeserializeProofChallenges(path string) variables.ProofChallenges { +// jsonFile, err := os.Open(path) +// if err != nil { +// panic(err) +// } + +// defer jsonFile.Close() +// rawBytes, _ := io.ReadAll(jsonFile) + +// var raw ProofChallengesRaw +// err = json.Unmarshal(rawBytes, &raw) +// if err != nil { +// panic(err) +// } + +// var proofChallenges variables.ProofChallenges +// proofChallenges.PlonkBetas = gl.Uint64ArrayToVariableArray(raw.PlonkBetas) +// proofChallenges.PlonkGammas = gl.Uint64ArrayToVariableArray(raw.PlonkGammas) +// proofChallenges.PlonkAlphas = gl.Uint64ArrayToVariableArray(raw.PlonkAlphas) +// proofChallenges.PlonkZeta = gl.Uint64ArrayToQuadraticExtension(raw.PlonkZeta) +// proofChallenges.FriChallenges.FriAlpha = gl.Uint64ArrayToQuadraticExtension(raw.FriChallenges.FriAlpha) +// proofChallenges.FriChallenges.FriBetas = gl.Uint64ArrayToQuadraticExtensionArray(raw.FriChallenges.FriBetas) +// proofChallenges.FriChallenges.FriPowResponse = gl.NewVariable(raw.FriChallenges.FriPowResponse) +// proofChallenges.FriChallenges.FriQueryIndices = gl.Uint64ArrayToVariableArray(raw.FriChallenges.FriQueryIndices) + +// return proofChallenges +// } func ReductionArityBits( arityBits uint64, diff --git a/verifier/verifier.go b/verifier/verifier.go index bfa69d9..0ff36ba 100644 --- a/verifier/verifier.go +++ b/verifier/verifier.go @@ -80,73 +80,6 @@ func (c *VerifierChip) GetChallenges( } } -/* -func (c *VerifierChip) generateProofInput(commonData common.CommonCircuitData) common.ProofWithPublicInputs { - // Generate the parts of the witness that is for the plonky2 proof input - - capHeight := commonData.Config.FriConfig.CapHeight - - friCommitPhaseMerkleCaps := []common.MerkleCap{} - for i := 0; i < len(commonData.FriParams.ReductionArityBits); i++ { - friCommitPhaseMerkleCaps = append(friCommitPhaseMerkleCaps, common.NewMerkleCap(capHeight)) - } - - salt := commonData.SaltSize() - numLeavesPerOracle := []uint{ - commonData.NumPreprocessedPolys(), - commonData.Config.NumWires + salt, - commonData.NumZsPartialProductsPolys() + salt, - commonData.NumQuotientPolys() + salt, - } - friQueryRoundProofs := []common.FriQueryRound{} - for i := uint64(0); i < commonData.FriParams.Config.NumQueryRounds; i++ { - evalProofs := []common.EvalProof{} - merkleProofLen := commonData.FriParams.LDEBits() - capHeight - for _, numLeaves := range numLeavesPerOracle { - leaves := make([]field.F, numLeaves) - merkleProof := common.NewMerkleProof(merkleProofLen) - evalProofs = append(evalProofs, common.NewEvalProof(leaves, merkleProof)) - } - - initialTreesProof := common.NewFriInitialTreeProof(evalProofs) - steps := []common.FriQueryStep{} - for _, arityBit := range commonData.FriParams.ReductionArityBits { - if merkleProofLen < arityBit { - panic("merkleProofLen < arityBits") - } - - steps = append(steps, common.NewFriQueryStep(arityBit, merkleProofLen)) - } - - friQueryRoundProofs = append(friQueryRoundProofs, common.NewFriQueryRound(steps, initialTreesProof)) - } - - proofInput := common.ProofWithPublicInputs{ - Proof: common.Proof{ - WiresCap: common.NewMerkleCap(capHeight), - PlonkZsPartialProductsCap: common.NewMerkleCap(capHeight), - QuotientPolysCap: common.NewMerkleCap(capHeight), - Openings: common.NewOpeningSet( - commonData.Config.NumConstants, - commonData.Config.NumRoutedWires, - commonData.Config.NumWires, - commonData.Config.NumChallenges, - commonData.NumPartialProducts, - commonData.QuotientDegreeFactor, - ), - OpeningProof: common.FriProof{ - CommitPhaseMerkleCaps: friCommitPhaseMerkleCaps, - QueryRoundProofs: friQueryRoundProofs, - FinalPoly: common.NewPolynomialCoeffs(commonData.FriParams.FinalPolyLen()), - }, - }, - PublicInputs: make([]field.F, commonData.NumPublicInputs), - } - - return proofInput -} -*/ - func (c *VerifierChip) rangeCheckProof(proof variables.Proof) { // Need to verify the plonky2 proof's openings, openings proof (other than the sibling elements), fri's final poly, pow witness.