Skip to content

Commit

Permalink
fix: div_mod_var when a_num_bits <= b_num_bits (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang authored May 10, 2023
1 parent 06905cc commit f566451
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion halo2-base/src/gates/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ pub trait RangeInstructions<F: ScalarField> {
);
let [div_lo, div_hi, div, rem] = [-5, -4, -2, -1].map(|i| ctx.get(i));
self.range_check(ctx, div_lo, b_num_bits);
self.range_check(ctx, div_hi, a_num_bits.saturating_sub(b_num_bits));
if a_num_bits <= b_num_bits {
self.gate().assert_is_const(ctx, &div_hi, &F::zero());
} else {
self.range_check(ctx, div_hi, a_num_bits - b_num_bits);
}

let (bcr0_hi, bcr0_lo) = {
let bcr0 = self.gate().mul_add(ctx, b, Existing(div_lo), Existing(rem));
Expand Down

0 comments on commit f566451

Please sign in to comment.