Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Document requirement for range opcode on r_witness in GeneratedAcir::euclidean_division #2437

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,18 @@ impl GeneratedAcir {
let (q_witness, r_witness) =
self.brillig_quotient(lhs.clone(), rhs.clone(), predicate.clone(), max_bit_size + 1);

// Apply range constraints to injected witness values.
// Constrains `q` to be 0 <= q < 2^{q_max_bits}, etc.
// Constrain `q < 2^{max_q_bits}`.
self.range_constraint(q_witness, max_q_bits)?;

// Constrain `r < 2^{max_rhs_bits}`.
//
// If `rhs` is a power of 2, then is just a looser version of the following bound constraint.
// In the case where `rhs` isn't a power of 2 then this range constraint is required
// as the bound constraint creates a new witness.
// This opcode will be optimized out if it is redundant so we always add it for safety.
self.range_constraint(r_witness, max_rhs_bits)?;

// Constrain r < rhs
// Constrain `r < rhs`.
self.bound_constraint_with_offset(&r_witness.into(), rhs, predicate, max_rhs_bits)?;

// a * predicate == (b * q + r) * predicate
Expand Down