to_bits_unconstrained!
The little-endian bits of a witness scalar as unconstrained witness hints. Bits and bytes
to_bits_unconstrained! v
Allocates field_bit_width! new witness entries (32 in the milli field) and, during witness computation, fills them with the bits of the canonical integer of v, least significant first.
The bits are unconstrained hints: no row says they are bits or that they recompose to v. Use the stdlib functions that add those constraints, to_bits_exact (a fixed number of bits) or to_bits (all bits, with a check against aliasing past p), unless you are writing such a function.
Arguments
v- Witness scalar.
Returns
A witness vector of field_bit_width! entries. Expression form only.
Constraints
None. Adds field_bit_width! witness entries, including the ones a caller slices off and never uses.
Example
A 4-bit decomposition, constrained the way to_bits_exact does it:
(let x) let bits = slice_from_start((to_bits_unconstrained! x), 4) # each entry is 0 or 1, one row per bit constrain_mul! (clone! bits), valloc(4, 1) - (clone! bits), calloc(4) # and the bits recompose to x constrain_eq! x, from_bits(clone! bits) bits
Notes
Errors: input must be a scalar and, for static inputs (including everything inside static_eval!), input must be a witness value, use to_bits_static for static values. The input may be a linear combination, not just a single witness entry.