Index Mathematics Conjectures nbv lettuce Widgets

r1cs_into_output

stdlib/r1cs/r1cs_into_output.nbv

r1cs_into_output(static wtns_len, static r_a, static r_b, static r_c)

No description.

Calls
is_zero, r1cs/r1cs_assert_field
Precompiles
assert_eq!, clone!, if_ne!, loop!, slice!
Used by
slip/slip_r1cs_arg_verify

Source

(
  static wtns_len,
  static r_a,
  static r_b,
  static r_c
)

static f_c_i = r1cs_assert_field(wtns_len, ...clone! r_a, r_b, r_c)

static mut wtns_indices[f_c_i]
static mut output[f_c_i]

loop! f_c_i, i {
  # get the constraint rows from the r1cs
  static a_row = slice! (clone! r_a), i * wtns_len, wtns_len
  static b_row = slice! (clone! r_b), i * wtns_len, wtns_len
  static c_row = slice! (clone! r_c), i * wtns_len, wtns_len

  # a row should have exactly 1 non-zero entry which is = 1
  static mut has_a_one = 0
  # the witness index being revealed/output/constrained
  static mut wtns_i = 0
  loop! wtns_len, i {
    if_ne! a_row[i], 0 {
      assert_eq! 1, a_row[i], "r1cs A row should contain a 1 element"
      assert_eq! 0, has_a_one, "r1cs A row has multiple non-zero entries"
      has_a_one = 1
      wtns_i = i
    }
  }

  # the b row should be [1, 0, 0, 0, 0, ...]
  assert_eq! 1, b_row[0], "r1cs B row first entry is not 1"
  assert_eq! 1, is_zero(slice! b_row, 1), "r1cs B row contains trailing non-zero elements"

  # the c row should be the conjectured output value
  output[i] = c_row[0]
  assert_eq! 1, is_zero(slice! c_row, 1), "r1cs C row contains trailing non-zero elements"
  wtns_indices[i] = wtns_i
}

(output, wtns_indices)