Index Mathematics Conjectures nbv lettuce Widgets

r1cs!

Compile a block into a separate R1CS and return its matrices as statics. R1CS

r1cs! [var, ...] { ... }

Compiles the block in a fresh VM, as if it were its own program, and returns the resulting constraint system as static values instead of adding it to the current program. This is the starting point for arguing about an R1CS inside nbv, e.g. verifying a proof of the block's statement (recursion).

The named arguments make variables of the enclosing scope available to the block: static variables are copied in under the same name. A witness argument only reserves witness entries in the inner system for its length; it is not visible by name inside the block.

Arguments

var, ...
Zero or more names of variables in scope (any other expression is an error). Statics are copied into the block; witnesses allocate the same number of inner witness entries.

Returns

A tuple of four statics (width, a, b, c): width is the number of witness entries of the inner system, including the leading constant 1 entry, and a, b, c are the three matrices as dense row-major vectors of rows * width elements. It is an expression-form precompile used with a tuple assignment.

Constraints

None in the current program. The block must produce at least one constraint, and must not end with a final expression (an inner program with public outputs is rejected).

Example

static k = 3
(static width, static a, static b, static c) = r1cs! k {
  # one row for the materialization, one for the product
  let y = wtns! 5
  let z = y * y * k
}
concat! width, (len! a)
(static width, static a, static b, static c) = r1cs! {
  static z = 4
}
width

Notes

The inner system is compiled without a witness, so it only describes the constraints. Its matrices can be fed to the standard library's R1CS helpers in stdlib/r1cs or to bdlop_blindfold_milli_poseidon_32_16!. See also sample_uniform_r1cs!.