Open TomAFrench opened 5 months ago
we cannot enforce safety for all types which have validity conditions outside of the type system 👀
As an extension of creating the first admonition with this Issue, we might want to set an example with U128 given it's in the stdlib.
Setting an example in terms of:
check_valid
method for U128To take that a step further, we may want to implement an IsValidInput
trait which defined the constraints to be added to a type when it's an input to the circuit (either as an argument to main
or as a return value from an unconstrained function). We'd then call this trait implementation whenever we receive this type from outside of the circuit.
For U128
we would range check the two limbs. For BoundedVec
we'd assert that the length was consistent with the underlying array, etc.
This would make it much easier for users to consistently enforce that these checks are performed.
See note on https://github.com/noir-lang/noir/pull/4217
We should ensure that the documentation explicitly calls out the need for users to add these constraints themselves.