mirror of
https://github.com/logos-storage/gnark-plonky2-verifier.git
synced 2026-01-03 21:53:10 +00:00
checkpoint
This commit is contained in:
parent
5d53737841
commit
b173b28649
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
20
types/types.go
Normal file
20
types/types.go
Normal file
@ -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
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
// 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)
|
||||
// defer jsonFile.Close()
|
||||
// rawBytes, _ := io.ReadAll(jsonFile)
|
||||
|
||||
var raw ProofChallengesRaw
|
||||
err = json.Unmarshal(rawBytes, &raw)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// 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)
|
||||
// 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
|
||||
}
|
||||
// return proofChallenges
|
||||
// }
|
||||
|
||||
func ReductionArityBits(
|
||||
arityBits uint64,
|
||||
|
||||
@ -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.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user