Index Mathematics Conjectures nbv lettuce Widgets

r1cs_from_output

stdlib/r1cs/r1cs_from_output.nbv

r1cs_from_output(wtns_len, output, indices)

take some outputs and some witness indices and construct an R1CS that constrains the witness accordingly

Calls
calloc, r1cs/r1cs_compose_vertical, r1cs/r1cs_field_constraint
Precompiles
assert_eq!, concat!, len!, loop_flat_map!
Used by
r1cs/r1cs_with_output

Source

# take some outputs and some witness indices
# and construct an R1CS that constrains the
# witness accordingly
(wtns_len, output, indices)

static output_len = len! output
assert_eq! output_len, (len! indices)

static r_a = loop_flat_map! output_len, i {
  static mut out[wtns_len]
  out[indices[i]] = 1
  out
}

static r_b = loop_flat_map! output_len, i {
  concat! 1, calloc(wtns_len - 1)
}

static r_c = loop_flat_map! output_len, i {
  concat! output[i], calloc(wtns_len - 1)
}

r1cs_compose_vertical(
  wtns_len, r_a, r_b, r_c,
  ...r1cs_field_constraint(wtns_len)
)