From 1243f3c4a9a7d30a8f23fa35938d7850aff319aa Mon Sep 17 00:00:00 2001 From: Arya Tabaie Date: Tue, 27 Jun 2023 14:09:19 -0500 Subject: [PATCH] chore: make staticcheck happy --- constraint/bls12-377/gkr.go | 10 +++++----- constraint/bls12-381/gkr.go | 10 +++++----- constraint/bls24-315/gkr.go | 10 +++++----- constraint/bls24-317/gkr.go | 10 +++++----- constraint/blueprint.go | 6 +++--- constraint/bn254/gkr.go | 10 +++++----- constraint/bn254/system.go | 4 ++++ constraint/bw6-633/gkr.go | 10 +++++----- constraint/bw6-761/gkr.go | 10 +++++----- constraint/core.go | 10 ++++++++++ constraint/system.go | 3 ++- constraint/term.go | 2 +- frontend/builder.go | 4 +++- frontend/cs/r1cs/api.go | 4 ++++ frontend/cs/scs/api.go | 4 ++++ .../backend/template/representations/gkr.go.tmpl | 10 +++++----- std/gkr/api.go | 4 ++-- std/gkr/api_test.go | 6 +++--- std/gkr/compile.go | 8 ++++---- std/hash/hash.go | 2 +- 20 files changed, 81 insertions(+), 56 deletions(-) diff --git a/constraint/bls12-377/gkr.go b/constraint/bls12-377/gkr.go index d1b0a840b8..1e1becb91b 100644 --- a/constraint/bls12-377/gkr.go +++ b/constraint/bls12-377/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bls12-377/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/bls12-381/gkr.go b/constraint/bls12-381/gkr.go index 838df92eb5..ffff99484d 100644 --- a/constraint/bls12-381/gkr.go +++ b/constraint/bls12-381/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bls12-381/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/bls24-315/gkr.go b/constraint/bls24-315/gkr.go index 4e66b4da8a..bca5ee8c0c 100644 --- a/constraint/bls24-315/gkr.go +++ b/constraint/bls24-315/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bls24-315/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/bls24-317/gkr.go b/constraint/bls24-317/gkr.go index cc8a6bac62..5707c20c54 100644 --- a/constraint/bls24-317/gkr.go +++ b/constraint/bls24-317/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bls24-317/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/blueprint.go b/constraint/blueprint.go index 1471d9d3e9..2949f0665f 100644 --- a/constraint/blueprint.go +++ b/constraint/blueprint.go @@ -2,7 +2,7 @@ package constraint type BlueprintID uint32 -// Blueprint enable representing heterogenous constraints or instructions in a constraint system +// Blueprint enable representing heterogeneous constraints or instructions in a constraint system // in a memory efficient way. Blueprints essentially help the frontend/ to "compress" // constraints or instructions, and specify for the solving (or zksnark setup) part how to // "decompress" and optionally "solve" the associated wires. @@ -66,8 +66,8 @@ type BlueprintHint interface { DecompressHint(h *HintMapping, instruction Instruction) } -// Compressable represent an object that knows how to encode itself as a []uint32. -type Compressable interface { +// Compressible represent an object that knows how to encode itself as a []uint32. +type Compressible interface { // Compress interprets the objects as a LinearExpression and encodes it as a []uint32. Compress(to *[]uint32) } diff --git a/constraint/bn254/gkr.go b/constraint/bn254/gkr.go index 6b00893e0f..f47207613a 100644 --- a/constraint/bn254/gkr.go +++ b/constraint/bn254/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bn254/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/bn254/system.go b/constraint/bn254/system.go index 949e532dbe..a96fe5d5a2 100644 --- a/constraint/bn254/system.go +++ b/constraint/bn254/system.go @@ -372,3 +372,7 @@ func getTagSet() cbor.TagSet { return ts } + +func (s *system) AddGkr(gkr constraint.GkrInfo) error { + return s.System.AddGkr(gkr) +} diff --git a/constraint/bw6-633/gkr.go b/constraint/bw6-633/gkr.go index 5a5de0b7fd..de49f3e8a4 100644 --- a/constraint/bw6-633/gkr.go +++ b/constraint/bw6-633/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bw6-633/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/bw6-761/gkr.go b/constraint/bw6-761/gkr.go index fe85e72dd1..12958a20f4 100644 --- a/constraint/bw6-761/gkr.go +++ b/constraint/bw6-761/gkr.go @@ -22,8 +22,8 @@ import ( "github.com/consensys/gnark-crypto/ecc/bw6-761/fr/polynomial" fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -83,7 +83,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -147,7 +147,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -183,8 +183,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/constraint/core.go b/constraint/core.go index e54fab3149..12aac144cb 100644 --- a/constraint/core.go +++ b/constraint/core.go @@ -125,6 +125,7 @@ type System struct { lbOutputs []uint32 `cbor:"-"` // wire outputs for current constraint. CommitmentInfo Commitments + GkrInfo GkrInfo genericHint BlueprintID } @@ -457,3 +458,12 @@ func putBuffer(buf *[]uint32) { } bufPool.Put(buf) } + +func (system *System) AddGkr(gkr GkrInfo) error { + if system.GkrInfo.Is() { + return fmt.Errorf("currently only one GKR sub-circuit per SNARK is supported") + } + + system.GkrInfo = gkr + return nil +} diff --git a/constraint/system.go b/constraint/system.go index 19f8167f32..e03586af4e 100644 --- a/constraint/system.go +++ b/constraint/system.go @@ -20,7 +20,7 @@ type ConstraintSystem interface { // Deprecated: use _, err := Solve(...) instead IsSolved(witness witness.Witness, opts ...solver.Option) error - // Solve attempts to solves the constraint system using provided witness. + // Solve attempts to solve the constraint system using provided witness. // Returns an error if the witness does not allow all the constraints to be satisfied. // Returns a typed solution (R1CSSolution or SparseR1CSSolution) and nil otherwise. Solve(witness witness.Witness, opts ...solver.Option) (any, error) @@ -52,6 +52,7 @@ type ConstraintSystem interface { AddCommitment(c Commitment) error GetCommitments() Commitments + AddGkr(gkr GkrInfo) error AddLog(l LogEntry) diff --git a/constraint/term.go b/constraint/term.go index 857edd0da0..799fb4f7a3 100644 --- a/constraint/term.go +++ b/constraint/term.go @@ -54,7 +54,7 @@ func (t Term) String(r Resolver) string { return sbb.String() } -// implements constraint.Compressable +// implements constraint.Compressible // Compress compresses the term into a slice of uint32 words. // For compatibility with test engine and LinearExpression, the term is encoded as: diff --git a/frontend/builder.go b/frontend/builder.go index 680a789b7a..717dbfca7a 100644 --- a/frontend/builder.go +++ b/frontend/builder.go @@ -64,6 +64,8 @@ type Compiler interface { // ToCanonicalVariable converts a frontend.Variable to a constraint system specific Variable // ! Experimental: use in conjunction with constraint.CustomizableSystem ToCanonicalVariable(Variable) CanonicalVariable + + SetGkrInfo(constraint.GkrInfo) error } // Builder represents a constraint system builder @@ -104,5 +106,5 @@ type Rangechecker interface { // a PLONK builder --> constraint.Term // and the test/Engine --> ~*big.Int. type CanonicalVariable interface { - constraint.Compressable + constraint.Compressible } diff --git a/frontend/cs/r1cs/api.go b/frontend/cs/r1cs/api.go index 7bb01fa76c..797bba0854 100644 --- a/frontend/cs/r1cs/api.go +++ b/frontend/cs/r1cs/api.go @@ -815,3 +815,7 @@ func (builder *builder) wireIDsToVars(wireIDs ...[]int) []frontend.Variable { } return res } + +func (builder *builder) SetGkrInfo(info constraint.GkrInfo) error { + return builder.cs.AddGkr(info) +} diff --git a/frontend/cs/scs/api.go b/frontend/cs/scs/api.go index 12eff1e730..75764878d3 100644 --- a/frontend/cs/scs/api.go +++ b/frontend/cs/scs/api.go @@ -619,3 +619,7 @@ func filterConstants(v []frontend.Variable) []frontend.Variable { func (*builder) FrontendType() frontendtype.Type { return frontendtype.SCS } + +func (builder *builder) SetGkrInfo(info constraint.GkrInfo) error { + return builder.cs.AddGkr(info) +} diff --git a/internal/generator/backend/template/representations/gkr.go.tmpl b/internal/generator/backend/template/representations/gkr.go.tmpl index 1d6df8406a..d405ea501c 100644 --- a/internal/generator/backend/template/representations/gkr.go.tmpl +++ b/internal/generator/backend/template/representations/gkr.go.tmpl @@ -4,8 +4,8 @@ import ( {{- template "import_polynomial" .}} fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir" "github.com/consensys/gnark-crypto/utils" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + hint "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/std/utils/algo_utils" "hash" "math/big" @@ -65,7 +65,7 @@ func (a gkrAssignment) setOuts(circuit constraint.GkrCircuit, outs []*big.Int) { // Check if outsI == len(outs)? } -func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Function { +func gkrSolveHint(info constraint.GkrInfo, solvingData *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { // assumes assignmentVector is arranged wire first, instance second in order of solution circuit := info.Circuit @@ -129,7 +129,7 @@ func frToBigInts(dst []*big.Int, src []fr.Element) { } } -func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { +func gkrProveHint(hashName string, data *gkrSolvingData) hint.Hint { return func(_ *big.Int, ins, outs []*big.Int) error { insBytes := algo_utils.Map(ins[1:], func(i *big.Int) []byte { // the first input is dummy, just to ensure the solver's work is done before the prover is called @@ -165,8 +165,8 @@ func gkrProveHint(hashName string, data *gkrSolvingData) hint.Function { } } -func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.ID]hint.Function) map[hint.ID]hint.Function { - res := make(map[hint.ID]hint.Function, len(hintFunctions)+2) +func defineGkrHints(info constraint.GkrInfo, hintFunctions map[hint.HintID]hint.Hint) map[hint.HintID]hint.Hint { + res := make(map[hint.HintID]hint.Hint, len(hintFunctions)+2) for k, v := range hintFunctions { res[k] = v } diff --git a/std/gkr/api.go b/std/gkr/api.go index 2bb88bc5fc..7515e93163 100644 --- a/std/gkr/api.go +++ b/std/gkr/api.go @@ -1,8 +1,8 @@ package gkr import ( - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/frontend" "github.com/consensys/gnark/std/utils/algo_utils" "math/big" @@ -122,7 +122,7 @@ func (api *API) Compiler() frontend.Compiler { panic("not implemented") } -func (api *API) NewHint(f hint.Function, nbOutputs int, inputs ...frontend.Variable) ([]frontend.Variable, error) { +func (api *API) NewHint(f solver.Hint, nbOutputs int, inputs ...frontend.Variable) ([]frontend.Variable, error) { panic("not implemented") } diff --git a/std/gkr/api_test.go b/std/gkr/api_test.go index 1325be3288..3dd889c7e6 100644 --- a/std/gkr/api_test.go +++ b/std/gkr/api_test.go @@ -361,7 +361,7 @@ func (c *benchMiMCMerkleTreeCircuit) Define(api frontend.API) error { } Z := solution.Export(z) - challenge, err := api.Compiler().Commit(Z...) + challenge, err := api.Compiler().(frontend.Committer).Commit(Z...) if err != nil { return err } @@ -393,7 +393,7 @@ func testE2E(t *testing.T, circuit, assignment frontend.Circuit) { func registerMiMC() { bn254r1cs.HashBuilderRegistry["mimc"] = bn254MiMC.NewMiMC - stdHash.BuilderRegistry["mimc"] = func(api frontend.API) (stdHash.Hash, error) { + stdHash.BuilderRegistry["mimc"] = func(api frontend.API) (stdHash.FieldHasher, error) { m, err := mimc.NewMiMC(api) return &m, err } @@ -404,7 +404,7 @@ func registerConstant(c int) { bn254r1cs.HashBuilderRegistry[name] = func() hash.Hash { return constHashBn254(c) } - stdHash.BuilderRegistry[name] = func(frontend.API) (stdHash.Hash, error) { + stdHash.BuilderRegistry[name] = func(frontend.API) (stdHash.FieldHasher, error) { return constHash(c), nil } } diff --git a/std/gkr/compile.go b/std/gkr/compile.go index 4b7a719dd9..8d1042ad74 100644 --- a/std/gkr/compile.go +++ b/std/gkr/compile.go @@ -2,8 +2,8 @@ package gkr import ( "fmt" - "github.com/consensys/gnark/backend/hint" "github.com/consensys/gnark/constraint" + "github.com/consensys/gnark/constraint/solver" "github.com/consensys/gnark/frontend" fiatshamir "github.com/consensys/gnark/std/fiat-shamir" "github.com/consensys/gnark/std/hash" @@ -123,7 +123,7 @@ func (api *API) Solve(parentApi frontend.API) (Solution, error) { } outsSerialized, err := parentApi.Compiler().NewHint(SolveHintPlaceholder, solveHintNOut, ins...) - api.toStore.SolveHintID = hint.UUID(SolveHintPlaceholder) + api.toStore.SolveHintID = solver.GetHintID(SolveHintPlaceholder) if err != nil { return Solution{}, err } @@ -176,7 +176,7 @@ func (s Solution) Verify(hashName string, initialChallenges ...frontend.Variable ProveHintPlaceholder, ProofSize(forSnark.circuit, logNbInstances), hintIns...); err != nil { return err } - s.toStore.ProveHintID = hint.UUID(ProveHintPlaceholder) + s.toStore.ProveHintID = solver.GetHintID(ProveHintPlaceholder) forSnarkSorted := algo_utils.MapRange(0, len(s.toStore.Circuit), slicePtrAt(forSnark.circuit)) @@ -184,7 +184,7 @@ func (s Solution) Verify(hashName string, initialChallenges ...frontend.Variable return err } - var hsh hash.Hash + var hsh hash.FieldHasher if hsh, err = hash.BuilderRegistry[hashName](s.parentApi); err != nil { return err } diff --git a/std/hash/hash.go b/std/hash/hash.go index 307a7fc4b5..67e0d91ce1 100644 --- a/std/hash/hash.go +++ b/std/hash/hash.go @@ -37,7 +37,7 @@ type FieldHasher interface { Reset() } -var BuilderRegistry = make(map[string]func(api frontend.API) (Hash, error)) +var BuilderRegistry = make(map[string]func(api frontend.API) (FieldHasher, error)) // BinaryHasher hashes inputs into a short digest. It takes as inputs bytes and // outputs byte array whose length depends on the underlying hash function. For