Skip to content

Commit

Permalink
fix: underflow when numerator is shorter than divisor
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo-Dallegri committed Dec 11, 2024
1 parent 6353c9a commit ed8bc51
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/fns/unconstrained_ops.nr
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ pub(crate) unconstrained fn __udiv_mod<let N: u32>(
let mut divisor_u60: U60Repr<N, 2> = U60Repr::from(divisor);
let b = divisor_u60;

if !remainder_u60.gte(divisor_u60) {
([0; N], numerator)
} else {
let mut bit_difference = remainder_u60.get_msb() - divisor_u60.get_msb();

let mut accumulator_u60: U60Repr<N, 2> = U60Repr::one();
Expand Down Expand Up @@ -199,6 +202,7 @@ pub(crate) unconstrained fn __udiv_mod<let N: u32>(
}

(U60Repr::into(quotient_u60), U60Repr::into(remainder_u60))
}
}

pub(crate) unconstrained fn __invmod<let N: u32, let MOD_BITS: u32>(
Expand Down

0 comments on commit ed8bc51

Please sign in to comment.