Closed readygo67 closed 11 months ago
This problem is caused by the following code in frontend/schema/walk.go, where a slice is defined but its length is 0
func (w *walker) Slice(value reflect.Value) error {
if value.Type() == w.targetSlice {
if value.Len() == 0 {
fmt.Printf("ignoring uninitialized slice: %s %s\n", w.name(), reflect.SliceOf(w.target).String())
return nil
}
return w.handleLeaves(value)
}
return nil
}
To handle this problem
import (
"fmt"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/math/bits"
"github.com/consensys/gnark/test"
"testing"
)
type BinaryCircuit1 struct {
Value frontend.Variable
Digits []frontend.Variable
}
func (c *BinaryCircuit1) Define(api frontend.API) error {
v := bits.FromBinary(api, c.Digits)
api.AssertIsEqual(c.Value, v)
return nil
}
func TestBinaryCircuit1(t *testing.T) {
assert := test.NewAssert(t)
digits := []frontend.Variable{1, 1, 1, 1}
value := 15
circuit := BinaryCircuit1{
Digits: make([]frontend.Variable, len(digits)),
}
valid := BinaryCircuit1{
Value: value,
Digits: digits,
}
//validCircuit.Digits = digits
fmt.Printf("circuit:%v\n", valid)
err := test.IsSolved(&circuit, &valid, ecc.BN254.ScalarField())
assert.NoError(err)
}
ignoring uninitialized slice: Digits []frontend.Variable happen in the following circuit.
Description
When running the following TestBinaryCircuit1, it report "ignoring uninitialized slice: Digits []frontend.Variable"
Expected Behavior
The case should be success.
Actual Behavior
reports ignoring uninitialized slice: Digits []frontend.Variable