Lists and tuples' ambiguous behavior when used recursively
In sdk/variable.go of the sdk repository, the List[T CircuitVariable]
type itself implements CircuitVariable
. However, should lists be nested, in the following implementation of FromValues
, the loop will never terminate, as fresh lists are empty — so nv
will be zero.
func (l List[T]) FromValues(vs ...frontend.Variable) CircuitVariable {
typ := *new(T)
nv := int(typ.NumVars())
for i := 0; i < len(vs); i += nv {
values := vs[i : i+nv]
l[i] = l[i].FromValues(values...).(T)
}
return l
}
Additionally, the above implementation of FromValues
will also fail for any other types implementing CircuitVariable
, unless all the components of the list have the same positive number of field elements and this size is also the same as the size of the default of type T
.
Similarly, tuples can also not have components that are lists, for the same reason.
We recommend to clearly document these limitations.