Index Mathematics Conjectures nbv lettuce Widgets

Precompiles

Precompiles are built into the compiler and invoked with name!. See the language reference for the invocation syntax.

Vectors

clone!clone! name, [name, ...]Copy named variables without moving them.
concat!concat! a, b, ...Join vectors end to end.
len!len! nameThe length of a named variable, as a static scalar.
slice!slice! vector, start, [len]A contiguous sub-vector of a vector.
slice_ref!slice_ref! name, start, lenA sub-vector of a named variable, without moving the variable.
split_at!split_at! vector, indexSplit a vector into the elements before and from an index, as a tuple.

Loops and mapping

chunks_flat_map!chunks_flat_map! vector, chunk_len[, chunk[, i]] { ... }Map a block over consecutive chunks of a vector and concatenate the results.
chunks_sum_map!chunks_sum_map! vector, chunk_len[, chunk[, i]] [{ ... }]Sum consecutive chunks of a vector element-wise, optionally mapping each chunk through a block.
flat_map!flat_map! vector, v[, i] { ... }Map a block over the elements of a vector and concatenate the results.
loop!loop! count[, i] { ... }Run a block a static number of times.
loop_flat_map!loop_flat_map! count[, i] { ... }Concatenate the values a block returns over a static number of iterations.
loop_map_sum!loop_map_sum! count[, i] { ... }Sum the values a block returns over a static number of iterations.
map_sum!map_sum! vector[, v[, i]] [{ ... }]Sum the elements of a vector, or the values a block returns for each element.
shadow_loop!shadow_loop! count[, i] { ... }Run a block a static number of times in the enclosing scope.

Control flow

if_eq!if_eq! lhs, rhs { ... }Run a block if two static values are equal.
if_lt!if_lt! lhs, rhs { ... }Run a block if one static scalar is less than another.
if_lte!if_lte! lhs, rhs { ... }Run a block if one static scalar is less than or equal to another.
if_ne!if_ne! lhs, rhs { ... }Run a block if two static values differ.

Integer and field arithmetic

div_ceil!div_ceil! lhs, rhsStatic element-wise integer division rounding up.
div_exact!div_exact! lhs, rhsStatic element-wise integer division that fails unless the divisor divides evenly.
div_floor!div_floor! lhs, rhsElement-wise integer division rounding down, static or as an unconstrained witness hint.
field_bit_width!field_bit_width!The number of bits needed to represent any element of the field, as a static scalar.
log2_ceil!log2_ceil! nStatic base 2 logarithm of a scalar, rounded up.
log2_exact!log2_exact! nStatic base 2 logarithm of a scalar, meant for powers of two.
min!min! lhs, rhsStatic element-wise minimum of canonical integer values.
modulo!modulo! lhs, rhsElement-wise integer remainder, static or as an unconstrained witness hint.
root_of_unity!root_of_unity! n [, count]A static primitive n-th root of unity, or its first powers and inverse powers.
sqrt!sqrt! vElement-wise field square root, computed statically or constrained as a witness.
sqrt_ceil!sqrt_ceil! nStatic integer square root of a scalar, rounded up.

Bits and bytes

bytes_from_hex_str!bytes_from_hex_str! "0x..."Encode a hex string literal as static field elements, length first.
to_bits_static!to_bits_static! vThe little-endian bits of a static scalar, as wide as the field.
to_bits_unconstrained!to_bits_unconstrained! vThe little-endian bits of a witness scalar as unconstrained witness hints.

Constraints and witnesses

constrain_eq!constrain_eq! lhs, rhsConstrain two vectors to be equal element-wise.
constrain_mul!constrain_mul! lhs, rhs, outConstrain lhs * rhs = out element-wise, one row per element.
wtns!wtns! exprMaterialize each element of an expression as its own witness entry.

Assertions

assert_eq!assert_eq! lhs, rhs[, "message"]Fail compilation unless two static vectors are equal.
assert_lt!assert_lt! lhs, rhs[, "message"]Fail compilation unless each element of a static vector is less than the matching element of another.
assert_lte!assert_lte! lhs, rhsFail compilation unless each element of a static vector is at most the matching element of another.
assert_ne!assert_ne! lhs, rhs[, "message"]Fail compilation if two static vectors are equal at any index.

Static evaluation

into_public_static!into_public_static! var[, var2, ...]Turn witness variables into statics by publishing their values as outputs.
static_assert_const!static_assert_const! exprConvert a constant witness value back into a static, failing if it depends on the witness.
static_eval!static_eval! { ... }Evaluate a block at compile time, treating every variable as static.

R1CS

r1cs!r1cs! [var, ...] { ... }Compile a block into a separate R1CS and return its matrices as statics.
sample_uniform_r1cs!sample_uniform_r1cs! height, widthSample a random dense R1CS with a satisfying witness, as statics.
sample_uniform_sparse_r1cs!sample_uniform_sparse_r1cs! height, widthSample a random sparse R1CS with a satisfying witness, as statics.

Cryptography

bdlop_blindfold_milli_poseidon_32_16!bdlop_blindfold_milli_poseidon_32_16! a, b, c, wCommit to an R1CS witness with BDLOP and return the blinded argument as witness vectors.
poseidon_milli_state!poseidon_milli_state! output_len, input_len, stateApply the milli Poseidon permutation to a state, reusing cached constraints.

Debugging

println!println! value, [value, ...]Print values while a program is compiled or evaluated.