diff --git a/backend/witness/witness_test.go b/backend/witness/witness_test.go index ba127b3240..d7feca17a4 100644 --- a/backend/witness/witness_test.go +++ b/backend/witness/witness_test.go @@ -1,6 +1,8 @@ package witness_test import ( + "bytes" + "encoding/json" "fmt" "reflect" "testing" @@ -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 + // } } diff --git a/debug/debug.go b/debug/debug.go index 95e1079768..32b891c38a 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -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) diff --git a/debug/symbol_table.go b/debug/symbol_table.go index 6ce2f68bb3..dc25c3e8d8 100644 --- a/debug/symbol_table.go +++ b/debug/symbol_table.go @@ -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) diff --git a/frontend/compile.go b/frontend/compile.go index 439b5802a5..02f0ec384f 100644 --- a/frontend/compile.go +++ b/frontend/compile.go @@ -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 diff --git a/test/engine.go b/test/engine.go index ece99f8bad..e72ff5f8e7 100644 --- a/test/engine.go +++ b/test/engine.go @@ -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). @@ -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 { diff --git a/test/solver_test.go b/test/solver_test.go index 9fb88da92d..af8adbe9c1 100644 --- a/test/solver_test.go +++ b/test/solver_test.go @@ -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" @@ -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