Browse Source

checkpoint

main
Uma Roy 2 years ago
parent
commit
b173b28649
8 changed files with 57 additions and 119 deletions
  1. +2
    -1
      challenger/challenger.go
  2. +4
    -3
      fri/fri.go
  3. +0
    -0
      plonk/gates/types.go
  4. +20
    -0
      types/types.go
  5. +3
    -2
      variables/circuit.go
  6. +0
    -19
      variables/fri.go
  7. +28
    -27
      verifier/deserialize.go
  8. +0
    -67
      verifier/verifier.go

+ 2
- 1
challenger/challenger.go

@ -7,6 +7,7 @@ import (
"github.com/succinctlabs/gnark-plonky2-verifier/fri" "github.com/succinctlabs/gnark-plonky2-verifier/fri"
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
"github.com/succinctlabs/gnark-plonky2-verifier/types"
"github.com/succinctlabs/gnark-plonky2-verifier/variables" "github.com/succinctlabs/gnark-plonky2-verifier/variables"
) )
@ -117,7 +118,7 @@ func (c *Chip) GetFriChallenges(
finalPoly variables.PolynomialCoeffs, finalPoly variables.PolynomialCoeffs,
powWitness gl.Variable, powWitness gl.Variable,
degreeBits uint64, degreeBits uint64,
config variables.FriConfig,
config types.FriConfig,
) variables.FriChallenges { ) variables.FriChallenges {
numFriQueries := config.NumQueryRounds numFriQueries := config.NumQueryRounds
friAlpha := c.GetExtensionChallenge() friAlpha := c.GetExtensionChallenge()

+ 4
- 3
fri/fri.go

@ -10,6 +10,7 @@ import (
"github.com/consensys/gnark/frontend" "github.com/consensys/gnark/frontend"
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
"github.com/succinctlabs/gnark-plonky2-verifier/types"
"github.com/succinctlabs/gnark-plonky2-verifier/variables" "github.com/succinctlabs/gnark-plonky2-verifier/variables"
) )
@ -17,12 +18,12 @@ type Chip struct {
api frontend.API `gnark:"-"` api frontend.API `gnark:"-"`
gl gl.Chip `gnark:"-"` gl gl.Chip `gnark:"-"`
poseidonBN254Chip *poseidon.BN254Chip poseidonBN254Chip *poseidon.BN254Chip
friParams *variables.FriParams `gnark:"-"`
friParams *types.FriParams `gnark:"-"`
} }
func NewChip( func NewChip(
api frontend.API, api frontend.API,
friParams *variables.FriParams,
friParams *types.FriParams,
) *Chip { ) *Chip {
poseidonBN254Chip := poseidon.NewBN254Chip(api) poseidonBN254Chip := poseidon.NewBN254Chip(api)
return &Chip{ 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. // 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 // Note that this is assuming that the Goldilocks field is being used. Specfically that the
// field is 64 bits long // field is 64 bits long

plonk/gates/selectors.go → plonk/gates/types.go


+ 20
- 0
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
}

+ 3
- 2
variables/circuit.go

@ -4,6 +4,7 @@ import (
gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks" gl "github.com/succinctlabs/gnark-plonky2-verifier/goldilocks"
"github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates" "github.com/succinctlabs/gnark-plonky2-verifier/plonk/gates"
"github.com/succinctlabs/gnark-plonky2-verifier/poseidon" "github.com/succinctlabs/gnark-plonky2-verifier/poseidon"
"github.com/succinctlabs/gnark-plonky2-verifier/types"
) )
type Proof struct { type Proof struct {
@ -33,12 +34,12 @@ type CircuitConfig struct {
NumChallenges uint64 NumChallenges uint64
ZeroKnowledge bool ZeroKnowledge bool
MaxQuotientDegreeFactor uint64 MaxQuotientDegreeFactor uint64
FriConfig FriConfig
FriConfig types.FriConfig
} }
type CommonCircuitData struct { type CommonCircuitData struct {
Config CircuitConfig Config CircuitConfig
FriParams FriParams
FriParams types.FriParams
Gates []gates.Gate Gates []gates.Gate
SelectorsInfo gates.SelectorsInfo SelectorsInfo gates.SelectorsInfo
DegreeBits uint64 DegreeBits uint64

+ 0
- 19
variables/fri.go

@ -13,25 +13,6 @@ func NewPolynomialCoeffs(numCoeffs uint64) PolynomialCoeffs {
return PolynomialCoeffs{Coeffs: make([]gl.QuadraticExtensionVariable, numCoeffs)} 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 type FriMerkleCap = []poseidon.BN254HashOut
func NewFriMerkleCap(capHeight uint64) FriMerkleCap { func NewFriMerkleCap(capHeight uint64) FriMerkleCap {

+ 28
- 27
verifier/deserialize.go

@ -297,33 +297,34 @@ func DeserializeProofWithPublicInputs(path string) variables.ProofWithPublicInpu
return proofWithPis 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( func ReductionArityBits(
arityBits uint64, arityBits uint64,

+ 0
- 67
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) { 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. // Need to verify the plonky2 proof's openings, openings proof (other than the sibling elements), fri's final poly, pow witness.

Loading…
Cancel
Save