@ -1,20 +0,0 @@ |
|||
package goldilocks |
|||
|
|||
import ( |
|||
"github.com/consensys/gnark/frontend" |
|||
"github.com/consensys/gnark/std/math/emulated" |
|||
) |
|||
|
|||
type GoldilocksElement = emulated.Element[emulated.Goldilocks] |
|||
|
|||
func NewGoldilocksElement(x uint64) GoldilocksElement { |
|||
return GoldilocksElement(emulated.NewElement[emulated.Goldilocks](x)) |
|||
} |
|||
|
|||
func NewGoldilocksAPI(api frontend.API) frontend.API { |
|||
goldilocks, err := emulated.NewField[emulated.Goldilocks](api) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
return goldilocks |
|||
} |
@ -0,0 +1,111 @@ |
|||
package plonky2_verifier |
|||
|
|||
import ( |
|||
. "gnark-ed25519/field" |
|||
) |
|||
|
|||
type QuadraticExtension = [2]F |
|||
|
|||
type MerkleCap = []Hash |
|||
|
|||
type MerkleProof struct { |
|||
Siblings []Hash |
|||
} |
|||
|
|||
type EvalProof struct { |
|||
Elements []F |
|||
MerkleProof MerkleProof |
|||
} |
|||
|
|||
type FriInitialTreeProof struct { |
|||
EvalsProofs []EvalProof |
|||
} |
|||
|
|||
type FriQueryStep struct { |
|||
Evals []QuadraticExtension |
|||
MerkleProof MerkleProof |
|||
} |
|||
|
|||
type FriQueryRound struct { |
|||
InitialTreesProof FriInitialTreeProof |
|||
Steps []FriQueryStep |
|||
} |
|||
|
|||
type PolynomialCoeffs struct { |
|||
Coeffs []F |
|||
} |
|||
|
|||
type FriProof struct { |
|||
CommitPhaseMerkleCaps []MerkleCap |
|||
QueryRoundProofs FriQueryRound |
|||
FinalPoly PolynomialCoeffs |
|||
PowWitness F |
|||
} |
|||
|
|||
type OpeningSet struct { |
|||
Constants []QuadraticExtension |
|||
PlonkSigmas []QuadraticExtension |
|||
Wires []QuadraticExtension |
|||
PlonkZs []QuadraticExtension |
|||
PlonkZsNext []QuadraticExtension |
|||
PartialProducts []QuadraticExtension |
|||
QuotientPolys []QuadraticExtension |
|||
} |
|||
|
|||
type Proof struct { |
|||
WiresCap MerkleCap |
|||
PlonkZsPartialProductsCap MerkleCap |
|||
QuotientPolysCap MerkleCap |
|||
Openings OpeningSet |
|||
OpeningProof FriProof |
|||
} |
|||
|
|||
type ProofWithPublicInputs struct { |
|||
Proof Proof |
|||
PublicInputs []F |
|||
} |
|||
|
|||
type VerifierOnlyCircuitData struct { |
|||
ConstantSigmasCap MerkleCap |
|||
} |
|||
|
|||
type FriConfig struct { |
|||
RateBits uint64 |
|||
CapHeight uint64 |
|||
ProofOfWorkBits uint64 |
|||
NumQueryRounds uint64 |
|||
// TODO: add FriReductionStrategy
|
|||
} |
|||
|
|||
type FriParams struct { |
|||
Config FriConfig |
|||
Hiding bool |
|||
DegreeBits uint64 |
|||
ReductionArityBits []uint64 |
|||
} |
|||
|
|||
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 |
|||
DegreeBits uint64 |
|||
QuotientDegreeFactor uint64 |
|||
NumGateConstraints uint64 |
|||
NumConstants uint64 |
|||
NumPublicInputs uint64 |
|||
KIs []F |
|||
NumPartialProducts uint64 |
|||
CircuitDigest Hash |
|||
// TODO: add SelectorsInfo and Gates
|
|||
} |
@ -1,162 +0,0 @@ |
|||
package plonky2_verifier |
|||
|
|||
import ( |
|||
. "gnark-ed25519/goldilocks" |
|||
) |
|||
|
|||
type Hash = [4]GoldilocksElement |
|||
type QuadraticExtension = [2]GoldilocksElement |
|||
type MerkleCap = []Hash |
|||
|
|||
type MerkleProof struct { |
|||
Siblings []Hash |
|||
} |
|||
|
|||
type EvalProof struct { |
|||
Elements []GoldilocksElement |
|||
MerkleProof MerkleProof |
|||
} |
|||
|
|||
type FriInitialTreeProof struct { |
|||
EvalsProofs []EvalProof |
|||
} |
|||
|
|||
type FriQueryStep struct { |
|||
Evals []QuadraticExtension |
|||
MerkleProof MerkleProof |
|||
} |
|||
|
|||
type FriQueryRound struct { |
|||
InitialTreesProof FriInitialTreeProof |
|||
Steps []FriQueryStep |
|||
} |
|||
|
|||
type PolynomialCoeffs struct { |
|||
Coeffs []GoldilocksElement |
|||
} |
|||
|
|||
type FriProof struct { |
|||
CommitPhaseMerkleCaps []MerkleCap |
|||
QueryRoundProofs FriQueryRound |
|||
FinalPoly PolynomialCoeffs |
|||
PowWitness GoldilocksElement |
|||
} |
|||
|
|||
type OpeningSet struct { |
|||
Constants []QuadraticExtension |
|||
PlonkSigmas []QuadraticExtension |
|||
Wires []QuadraticExtension |
|||
PlonkZs []QuadraticExtension |
|||
PlonkZsNext []QuadraticExtension |
|||
PartialProducts []QuadraticExtension |
|||
QuotientPolys []QuadraticExtension |
|||
} |
|||
|
|||
type Proof struct { |
|||
WiresCap MerkleCap |
|||
PlonkZsPartialProductsCap MerkleCap |
|||
QuotientPolysCap MerkleCap |
|||
Openings OpeningSet |
|||
OpeningProof FriProof |
|||
} |
|||
|
|||
type ProofWithPublicInputs struct { |
|||
Proof Proof |
|||
PublicInputs []GoldilocksElement |
|||
} |
|||
|
|||
type ProofWithPublicInputsRaw struct { |
|||
Proof struct { |
|||
WiresCap []struct { |
|||
Elements []uint64 `json:"elements"` |
|||
} `json:"wires_cap"` |
|||
PlonkZsPartialProductsCap []struct { |
|||
Elements []uint64 `json:"elements"` |
|||
} `json:"plonk_zs_partial_products_cap"` |
|||
QuotientPolysCap []struct { |
|||
Elements []uint64 `json:"elements"` |
|||
} `json:"quotient_polys_cap"` |
|||
Openings struct { |
|||
Constants [][]uint64 `json:"constants"` |
|||
PlonkSigmas [][]uint64 `json:"plonk_sigmas"` |
|||
Wires [][]uint64 `json:"wires"` |
|||
PlonkZs [][]uint64 `json:"plonk_zs"` |
|||
PlonkZsNext [][]uint64 `json:"plonk_zs_next"` |
|||
PartialProducts [][]uint64 `json:"partial_products"` |
|||
QuotientPolys [][]uint64 `json:"quotient_polys"` |
|||
} `json:"openings"` |
|||
OpeningProof struct { |
|||
CommitPhaseMerkleCaps []interface{} `json:"commit_phase_merkle_caps"` |
|||
QueryRoundProofs []struct { |
|||
InitialTreesProof struct { |
|||
EvalsProofs [][]interface{} `json:"evals_proofs"` |
|||
} `json:"initial_trees_proof"` |
|||
Steps []interface{} `json:"steps"` |
|||
} `json:"query_round_proofs"` |
|||
FinalPoly struct { |
|||
Coeffs [][]uint64 `json:"coeffs"` |
|||
} `json:"final_poly"` |
|||
PowWitness uint64 `json:"pow_witness"` |
|||
} `json:"opening_proof"` |
|||
} `json:"proof"` |
|||
PublicInputs []uint64 `json:"public_inputs"` |
|||
} |
|||
|
|||
type CommonCircuitData struct { |
|||
Config struct { |
|||
NumWires uint64 `json:"num_wires"` |
|||
NumRoutedWires uint64 `json:"num_routed_wires"` |
|||
NumConstants uint64 `json:"num_constants"` |
|||
UseBaseArithmeticGate bool `json:"use_base_arithmetic_gate"` |
|||
SecurityBits uint64 `json:"security_bits"` |
|||
NumChallenges uint64 `json:"num_challenges"` |
|||
ZeroKnowledge bool `json:"zero_knowledge"` |
|||
MaxQuotientDegreeFactor uint64 `json:"max_quotient_degree_factor"` |
|||
FriConfig struct { |
|||
RateBits uint64 `json:"rate_bits"` |
|||
CapHeight uint64 `json:"cap_height"` |
|||
ProofOfWorkBits uint64 `json:"proof_of_work_bits"` |
|||
ReductionStrategy struct { |
|||
ConstantArityBits []uint64 `json:"ConstantArityBits"` |
|||
} `json:"reduction_strategy"` |
|||
NumQueryRounds uint64 `json:"num_query_rounds"` |
|||
} `json:"fri_config"` |
|||
} `json:"config"` |
|||
FriParams struct { |
|||
Config struct { |
|||
RateBits uint64 `json:"rate_bits"` |
|||
CapHeight uint64 `json:"cap_height"` |
|||
ProofOfWorkBits uint64 `json:"proof_of_work_bits"` |
|||
ReductionStrategy struct { |
|||
ConstantArityBits []uint64 `json:"ConstantArityBits"` |
|||
} `json:"reduction_strategy"` |
|||
NumQueryRounds uint64 `json:"num_query_rounds"` |
|||
} `json:"config"` |
|||
Hiding bool `json:"hiding"` |
|||
DegreeBits uint64 `json:"degree_bits"` |
|||
ReductionArityBits []interface{} `json:"reduction_arity_bits"` |
|||
} `json:"fri_params"` |
|||
DegreeBits uint64 `json:"degree_bits"` |
|||
SelectorsInfo struct { |
|||
SelectorIndices []uint64 `json:"selector_indices"` |
|||
Groups []struct { |
|||
Start uint64 `json:"start"` |
|||
End uint64 `json:"end"` |
|||
} `json:"groups"` |
|||
} `json:"selectors_info"` |
|||
QuotientDegreeFactor uint64 `json:"quotient_degree_factor"` |
|||
NumGateConstraints uint64 `json:"num_gate_constraints"` |
|||
NumConstants uint64 `json:"num_constants"` |
|||
NumPublicInputs uint64 `json:"num_public_inputs"` |
|||
KIs []interface{} `json:"k_is"` |
|||
NumPartialProducts uint64 `json:"num_partial_products"` |
|||
CircuitDigest struct { |
|||
Elements []uint64 `json:"elements"` |
|||
} `json:"circuit_digest"` |
|||
} |
|||
|
|||
type VerifierOnlyCircuitData struct { |
|||
ConstantsSigmasCap []struct { |
|||
Elements []uint64 `json:"elements"` |
|||
} `json:"constants_sigmas_cap"` |
|||
} |
@ -1,47 +1,43 @@ |
|||
package plonky2_verifier |
|||
|
|||
import ( |
|||
. "gnark-ed25519/goldilocks" |
|||
"gnark-ed25519/poseidon" |
|||
"gnark-ed25519/utils" |
|||
|
|||
"github.com/consensys/gnark/frontend" |
|||
) |
|||
|
|||
type VerifierChip struct { |
|||
api frontend.API |
|||
field frontend.API |
|||
poseidonChip poseidon.PoseidonChip |
|||
} |
|||
|
|||
func (c *VerifierChip) GetPublicInputsHash(publicInputs []GoldilocksElement) poseidon.HashOutput { |
|||
return c.poseidonChip.HashNoPad(publicInputs) |
|||
} |
|||
|
|||
func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicInputsHash Hash, commonData CommonCircuitData) { |
|||
config := commonData.Config |
|||
numChallenges := int(config.NumChallenges) |
|||
challenger := NewChallengerChip(c.api, c.field, c.poseidonChip) |
|||
|
|||
var circuitDigest Hash |
|||
copy(circuitDigest[:], utils.Uint64ArrayToGoldilocksElementArray(commonData.CircuitDigest.Elements)) |
|||
|
|||
challenger.ObserveHash(circuitDigest) |
|||
challenger.ObserveHash(publicInputsHash) |
|||
challenger.ObserveCap(proofWithPis.Proof.WiresCap) |
|||
plonkBetas := challenger.GetNChallenges(numChallenges) |
|||
plonkGammas := challenger.GetNChallenges(numChallenges) |
|||
|
|||
challenger.ObserveCap(proofWithPis.Proof.PlonkZsPartialProductsCap) |
|||
plonkAlphas := challenger.GetNChallenges(numChallenges) |
|||
|
|||
challenger.ObserveCap(proofWithPis.Proof.QuotientPolysCap) |
|||
plonkZeta := challenger.GetNChallenges(numChallenges) |
|||
|
|||
challenger.ObserveOpenings(proofWithPis.Proof.Openings) |
|||
} |
|||
|
|||
func (c *VerifierChip) Verify(proofWithPis ProofWithPublicInputs, verifierData VerifierOnlyCircuitData, commonData CommonCircuitData) { |
|||
publicInputsHash := c.GetPublicInputsHash(proofWithPis.PublicInputs) |
|||
challenges := c.GetChallenges(proofWithPis, publicInputsHash, commonData) |
|||
} |
|||
// import (
|
|||
// . "gnark-ed25519/field"
|
|||
// "gnark-ed25519/poseidon"
|
|||
|
|||
// "github.com/consensys/gnark/frontend"
|
|||
// )
|
|||
|
|||
// type VerifierChip struct {
|
|||
// api frontend.API
|
|||
// field frontend.API
|
|||
// poseidonChip poseidon.PoseidonChip
|
|||
// }
|
|||
|
|||
// func (c *VerifierChip) GetPublicInputsHash(publicInputs []F) poseidon.HashOutput {
|
|||
// return c.poseidonChip.HashNoPad(publicInputs)
|
|||
// }
|
|||
|
|||
// func (c *VerifierChip) GetChallenges(proofWithPis ProofWithPublicInputs, publicInputsHash Hash, commonData CommonCircuitData) {
|
|||
// config := commonData.Config
|
|||
// numChallenges := int(config.NumChallenges)
|
|||
// challenger := NewChallengerChip(c.api, c.field, c.poseidonChip)
|
|||
|
|||
// challenger.ObserveHash(commonData.CircuitDigest)
|
|||
// challenger.ObserveHash(publicInputsHash)
|
|||
// challenger.ObserveCap(proofWithPis.Proof.WiresCap)
|
|||
// plonkBetas := challenger.GetNChallenges(numChallenges)
|
|||
// plonkGammas := challenger.GetNChallenges(numChallenges)
|
|||
|
|||
// challenger.ObserveCap(proofWithPis.Proof.PlonkZsPartialProductsCap)
|
|||
// plonkAlphas := challenger.GetNChallenges(numChallenges)
|
|||
|
|||
// challenger.ObserveCap(proofWithPis.Proof.QuotientPolysCap)
|
|||
// plonkZeta := challenger.GetNChallenges(numChallenges)
|
|||
|
|||
// challenger.ObserveOpenings(proofWithPis.Proof.Openings)
|
|||
// }
|
|||
|
|||
// func (c *VerifierChip) Verify(proofWithPis ProofWithPublicInputs, verifierData VerifierOnlyCircuitData, commonData CommonCircuitData) {
|
|||
// publicInputsHash := c.GetPublicInputsHash(proofWithPis.PublicInputs)
|
|||
// challenges := c.GetChallenges(proofWithPis, publicInputsHash, commonData)
|
|||
// }
|