Skip to content

Commit

Permalink
Merge branch 'fix/stacks' into feat/rangecheck-commitment4
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Mar 6, 2023
2 parents cc934b4 + 44fcb40 commit a13313a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
14 changes: 11 additions & 3 deletions backend/witness/witness_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package witness_test

import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -47,11 +49,17 @@ func ExampleWitness() {

// first get the circuit expected schema
schema, _ := frontend.NewSchema(assignment)
json, _ := reconstructed.ToJSON(schema)
ret, _ := reconstructed.ToJSON(schema)

fmt.Println(string(json))
var b bytes.Buffer
json.Indent(&b, ret, "", "\t")
fmt.Println(b.String())
// Output:
// {"X":42,"Y":8000,"E":1}
// {
// "X": 42,
// "Y": 8000,
// "E": 1
// }

}

Expand Down
2 changes: 1 addition & 1 deletion debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func writeStack(sbb *strings.Builder, forceClean ...bool) {
if strings.Contains(frame.File, "test/engine.go") {
continue
}
if strings.Contains(frame.File, "gnark/frontend") {
if strings.Contains(frame.File, "gnark/frontend/cs") {
continue
}
file = filepath.Base(file)
Expand Down
2 changes: 1 addition & 1 deletion debug/symbol_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (st *SymbolTable) CollectStack() []int {
if strings.Contains(frame.File, "test/engine.go") {
continue
}
if strings.Contains(frame.File, "gnark/frontend") {
if strings.Contains(frame.File, "gnark/frontend/cs") {
continue
}
frame.File = filepath.Base(frame.File)
Expand Down
2 changes: 1 addition & 1 deletion frontend/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func parseCircuit(builder Builder, circuit Circuit) (err error) {
return fmt.Errorf("define circuit: %w", err)
}
if err = callDeferred(builder); err != nil {
return fmt.Errorf("")
return fmt.Errorf("deferred: %w", err)
}

return
Expand Down
15 changes: 11 additions & 4 deletions test/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ func IsSolved(circuit, witness frontend.Circuit, field *big.Int, opts ...TestEng
if err = c.Define(e); err != nil {
return fmt.Errorf("define: %w", err)
}
for i, cb := range circuitdefer.GetAll[func(frontend.API) error](e) {
if err = cb(e); err != nil {
return fmt.Errorf("defer %d: %w", i, err)
}
if err = callDeferred(e); err != nil {
return fmt.Errorf("deferred: %w", err)
}

log.Debug().Uint64("add", cptAdd).
Expand All @@ -141,6 +139,15 @@ func IsSolved(circuit, witness frontend.Circuit, field *big.Int, opts ...TestEng
return
}

func callDeferred(builder *engine) error {
for i, cb := range circuitdefer.GetAll[func(frontend.API) error](builder) {
if err := cb(builder); err != nil {
return fmt.Errorf("defer fn %d: %w", i, err)
}
}
return nil
}

var cptAdd, cptMul, cptSub, cptToBinary, cptFromBinary, cptAssertIsEqual uint64

func (e *engine) Add(i1, i2 frontend.Variable, in ...frontend.Variable) frontend.Variable {
Expand Down
7 changes: 2 additions & 5 deletions test/solver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/consensys/gnark/frontend/cs/scs"
"github.com/consensys/gnark/frontend/schema"
"github.com/consensys/gnark/internal/backend/circuits"
"github.com/consensys/gnark/internal/circuitdefer"
"github.com/consensys/gnark/internal/kvstore"
"github.com/consensys/gnark/internal/tinyfield"
"github.com/consensys/gnark/internal/utils"
Expand Down Expand Up @@ -209,10 +208,8 @@ func isSolvedEngine(c frontend.Circuit, field *big.Int, opts ...TestEngineOption
if err = c.Define(e); err != nil {
return fmt.Errorf("define: %w", err)
}
for i, cb := range circuitdefer.GetAll[func(frontend.API) error](e) {
if err = cb(e); err != nil {
return fmt.Errorf("defer %d: %w", i, err)
}
if err = callDeferred(e); err != nil {
return fmt.Errorf("")
}

return
Expand Down

0 comments on commit a13313a

Please sign in to comment.