-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/plonk generic #250
Merged
Merged
Feat/plonk generic #250
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6dddcbf
feat(plonk): addition of skeleton prover with non homomorphic PCS
ThomasPiellard 7549473
style: removed printing functions
ThomasPiellard 25381e1
feat: addition of missing commitments and openings in vk and pk
ThomasPiellard 6978abc
fix(plonk): fixed generic verifier
ThomasPiellard 68b2c94
feat: added verifier (forgot to commit it)
ThomasPiellard 12d1d3a
style: uncomment verify.go in generic plonk
ThomasPiellard 2307a25
fix: removed unused debug function
ThomasPiellard 8a03b06
Merge branch 'develop' into feat/plonk_generic
ThomasPiellard b23e9cf
fix: fixed vanilla plonk fri
ThomasPiellard 8d76551
feat: addition of proximity tests
ThomasPiellard b5403bb
feat: addition of proofs for s1,s2,s3 and ccircuit coefficients
ThomasPiellard 1f8c964
fix: fixed opening Merkle path
ThomasPiellard fed8295
fix: fixed size Iop (error due to the blinding)
ThomasPiellard 68e21f3
feat: verification of Z, Zshifted
ThomasPiellard 67b2873
fix: fixed position of the shifted opening
ThomasPiellard 89f2dd1
feat: removed mock commitment scheme
ThomasPiellard 86b9c23
feat: removed dead code + old commented code
ThomasPiellard 5e487cf
style: removed dead debug printings
ThomasPiellard b6407bb
feat: re activated blinding
ThomasPiellard 138aaa4
feat: Fiat Shamir done
ThomasPiellard b4eda7e
feat: addition of templates
ThomasPiellard c8a818e
feat: code gen
ThomasPiellard a979beb
refactor: VerifyFri -> Verify
ThomasPiellard 83e1e9b
feat: addition of plonkfri in test package
ThomasPiellard 732afcd
feat: only mul is tested for plonk fri
ThomasPiellard 10f4bd2
feat: uncomment integration tests
ThomasPiellard 0f2664b
feat: merge develop
ThomasPiellard 91ef255
fix: ignore plonk_fri in internal/stats for now
gbotrel 1b1c39f
Merge branch 'develop' into feat/plonk_generic
gbotrel 86c67fe
style: remove dead code
ThomasPiellard 1860dfc
style: factored code in integration_test
ThomasPiellard 0307a0b
style: removed dead comments
ThomasPiellard ea42f2f
fix: fixed comments
ThomasPiellard 6e3b087
feat: size of fiat shamir data is harcoded
ThomasPiellard 0ec8ae2
style: removed dead code
ThomasPiellard 08764fc
Merge branch 'develop' into feat/plonk_generic
gbotrel f271acc
Merge branch 'develop' into feat/plonk_generic
gbotrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
// Copyright 2020 ConsenSys AG | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package plonkfri implements PLONK Zero Knowledge Proof system, with FRI as commitment scheme. | ||
|
||
package plonkfri | ||
|
||
import ( | ||
"github.com/consensys/gnark/backend" | ||
"github.com/consensys/gnark/frontend" | ||
|
||
"github.com/consensys/gnark/backend/witness" | ||
cs_bls12377 "github.com/consensys/gnark/internal/backend/bls12-377/cs" | ||
cs_bls12381 "github.com/consensys/gnark/internal/backend/bls12-381/cs" | ||
cs_bls24315 "github.com/consensys/gnark/internal/backend/bls24-315/cs" | ||
cs_bn254 "github.com/consensys/gnark/internal/backend/bn254/cs" | ||
cs_bw6633 "github.com/consensys/gnark/internal/backend/bw6-633/cs" | ||
cs_bw6761 "github.com/consensys/gnark/internal/backend/bw6-761/cs" | ||
|
||
plonk_bls12377 "github.com/consensys/gnark/internal/backend/bls12-377/plonkfri" | ||
plonk_bls12381 "github.com/consensys/gnark/internal/backend/bls12-381/plonkfri" | ||
plonk_bls24315 "github.com/consensys/gnark/internal/backend/bls24-315/plonkfri" | ||
plonk_bn254 "github.com/consensys/gnark/internal/backend/bn254/plonkfri" | ||
plonk_bw6633 "github.com/consensys/gnark/internal/backend/bw6-633/plonkfri" | ||
plonk_bw6761 "github.com/consensys/gnark/internal/backend/bw6-761/plonkfri" | ||
|
||
witness_bls12377 "github.com/consensys/gnark/internal/backend/bls12-377/witness" | ||
witness_bls12381 "github.com/consensys/gnark/internal/backend/bls12-381/witness" | ||
witness_bls24315 "github.com/consensys/gnark/internal/backend/bls24-315/witness" | ||
witness_bn254 "github.com/consensys/gnark/internal/backend/bn254/witness" | ||
witness_bw6633 "github.com/consensys/gnark/internal/backend/bw6-633/witness" | ||
witness_bw6761 "github.com/consensys/gnark/internal/backend/bw6-761/witness" | ||
) | ||
|
||
// Proof represents a Plonk proof generated by plonk.Prove | ||
// | ||
// it's underlying implementation is curve specific (see gnark/internal/backend) | ||
type Proof interface { | ||
// io.WriterTo | ||
// io.ReaderFrom | ||
} | ||
|
||
// ProvingKey represents a plonk ProvingKey | ||
// | ||
// it's underlying implementation is strongly typed with the curve (see gnark/internal/backend) | ||
type ProvingKey interface { | ||
// io.WriterTo | ||
// io.ReaderFrom | ||
VerifyingKey() interface{} | ||
} | ||
|
||
// VerifyingKey represents a plonk VerifyingKey | ||
// | ||
// it's underlying implementation is strongly typed with the curve (see gnark/internal/backend) | ||
type VerifyingKey interface { | ||
// io.WriterTo | ||
// io.ReaderFrom | ||
// InitKZG(srs kzg.SRS) error | ||
NbPublicWitness() int // number of elements expected in the public witness | ||
} | ||
|
||
// Setup prepares the public data associated to a circuit + public inputs. | ||
func Setup(ccs frontend.CompiledConstraintSystem) (ProvingKey, VerifyingKey, error) { | ||
|
||
switch tccs := ccs.(type) { | ||
case *cs_bn254.SparseR1CS: | ||
return plonk_bn254.Setup(tccs) | ||
case *cs_bls12381.SparseR1CS: | ||
return plonk_bls12381.Setup(tccs) | ||
case *cs_bls12377.SparseR1CS: | ||
return plonk_bls12377.Setup(tccs) | ||
case *cs_bw6761.SparseR1CS: | ||
return plonk_bw6761.Setup(tccs) | ||
case *cs_bls24315.SparseR1CS: | ||
return plonk_bls24315.Setup(tccs) | ||
case *cs_bw6633.SparseR1CS: | ||
return plonk_bw6633.Setup(tccs) | ||
default: | ||
panic("unrecognized SparseR1CS curve type") | ||
} | ||
|
||
} | ||
|
||
// Prove generates PLONK proof from a circuit, associated preprocessed public data, and the witness | ||
// if the force flag is set: | ||
// will executes all the prover computations, even if the witness is invalid | ||
// will produce an invalid proof | ||
// internally, the solution vector to the SparseR1CS will be filled with random values which may impact benchmarking | ||
func Prove(ccs frontend.CompiledConstraintSystem, pk ProvingKey, fullWitness *witness.Witness, opts ...backend.ProverOption) (Proof, error) { | ||
|
||
// apply options | ||
opt, err := backend.NewProverConfig(opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch tccs := ccs.(type) { | ||
case *cs_bn254.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bn254.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bn254.Prove(tccs, pk.(*plonk_bn254.ProvingKey), *w, opt) | ||
|
||
case *cs_bls12381.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bls12381.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bls12381.Prove(tccs, pk.(*plonk_bls12381.ProvingKey), *w, opt) | ||
|
||
case *cs_bls12377.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bls12377.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bls12377.Prove(tccs, pk.(*plonk_bls12377.ProvingKey), *w, opt) | ||
|
||
case *cs_bw6761.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bw6761.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bw6761.Prove(tccs, pk.(*plonk_bw6761.ProvingKey), *w, opt) | ||
|
||
case *cs_bw6633.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bw6633.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bw6633.Prove(tccs, pk.(*plonk_bw6633.ProvingKey), *w, opt) | ||
|
||
case *cs_bls24315.SparseR1CS: | ||
w, ok := fullWitness.Vector.(*witness_bls24315.Witness) | ||
if !ok { | ||
return nil, witness.ErrInvalidWitness | ||
} | ||
return plonk_bls24315.Prove(tccs, pk.(*plonk_bls24315.ProvingKey), *w, opt) | ||
|
||
default: | ||
panic("unrecognized SparseR1CS curve type") | ||
} | ||
} | ||
|
||
// Verify verifies a PLONK proof, from the proof, preprocessed public data, and public witness. | ||
func Verify(proof Proof, vk VerifyingKey, publicWitness *witness.Witness) error { | ||
|
||
switch _proof := proof.(type) { | ||
|
||
case *plonk_bn254.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bn254.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bn254.Verify(_proof, vk.(*plonk_bn254.VerifyingKey), *w) | ||
|
||
case *plonk_bls12381.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bls12381.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bls12381.Verify(_proof, vk.(*plonk_bls12381.VerifyingKey), *w) | ||
|
||
case *plonk_bls12377.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bls12377.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bls12377.Verify(_proof, vk.(*plonk_bls12377.VerifyingKey), *w) | ||
|
||
case *plonk_bw6761.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bw6761.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bw6761.Verify(_proof, vk.(*plonk_bw6761.VerifyingKey), *w) | ||
|
||
case *plonk_bw6633.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bw6633.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bw6633.Verify(_proof, vk.(*plonk_bw6633.VerifyingKey), *w) | ||
|
||
case *plonk_bls24315.Proof: | ||
w, ok := publicWitness.Vector.(*witness_bls24315.Witness) | ||
if !ok { | ||
return witness.ErrInvalidWitness | ||
} | ||
return plonk_bls24315.Verify(_proof, vk.(*plonk_bls24315.VerifyingKey), *w) | ||
|
||
default: | ||
panic("unrecognized proof type") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serialization is not implemented for proof / pk / vk