Skip to content

Commit

Permalink
fixes (a16z#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
quangvdao authored Nov 20, 2024
1 parent c90d6f9 commit 856c594
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl<const WORD_SIZE: usize> JoltInstruction for AssertValidSignedRemainderInstr
} else {
let remainder_sign = remainder >> 31;
let divisor_sign = divisor >> 31;
(remainder.abs() < divisor.abs() && remainder_sign == divisor_sign).into()
(remainder.unsigned_abs() < divisor.unsigned_abs()
&& remainder_sign == divisor_sign)
.into()
}
}
64 => {
Expand All @@ -109,7 +111,9 @@ impl<const WORD_SIZE: usize> JoltInstruction for AssertValidSignedRemainderInstr
} else {
let remainder_sign = remainder >> 63;
let divisor_sign = divisor >> 63;
(remainder.abs() < divisor.abs() && remainder_sign == divisor_sign).into()
(remainder.unsigned_abs() < divisor.unsigned_abs()
&& remainder_sign == divisor_sign)
.into()
}
}
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
Expand Down Expand Up @@ -161,6 +165,7 @@ mod test {

// Edge cases
let u32_max: u64 = u32::MAX as u64;
let i32_min: u64 = i32::MIN as u32 as u64;
let instructions = vec![
AssertValidSignedRemainderInstruction::<WORD_SIZE>(100, 0),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(0, 100),
Expand All @@ -170,6 +175,8 @@ mod test {
AssertValidSignedRemainderInstruction::<WORD_SIZE>(u32_max, u32_max),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(u32_max, 1 << 8),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(1 << 8, u32_max),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(4294967295, 3909118204),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(i32_min, i32_min),
];
for instruction in instructions {
jolt_instruction_test!(instruction);
Expand Down Expand Up @@ -199,6 +206,7 @@ mod test {

// Edge cases
let u64_max: u64 = u64::MAX;
let i64_min: u64 = i64::MIN as u64;
let instructions = vec![
AssertValidSignedRemainderInstruction::<WORD_SIZE>(100, 0),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(0, 100),
Expand All @@ -210,6 +218,7 @@ mod test {
AssertValidSignedRemainderInstruction::<WORD_SIZE>(1 << 8, u64_max),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(u64_max, 1 << 40),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(u64_max, u64_max - 1),
AssertValidSignedRemainderInstruction::<WORD_SIZE>(i64_min, i64_min),
];
for instruction in instructions {
jolt_instruction_test!(instruction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl<const WORD_SIZE: usize> JoltInstruction
let mut sum = F::zero();
let mut eq_prod = F::one();

for i in 0..C {
for i in 0..C - 1 {
sum += ltu[i] * eq_prod;
eq_prod *= eq[i];
}
// LTU(r, y) + EQ(y, 0)
sum + divisor_is_zero
// LTU(x, y) + EQ(y, 0)
sum + ltu[C - 1] * eq_prod + divisor_is_zero
}

fn g_poly_degree(&self, C: usize) -> usize {
Expand All @@ -50,7 +50,7 @@ impl<const WORD_SIZE: usize> JoltInstruction
) -> Vec<(Box<dyn LassoSubtable<F>>, SubtableIndices)> {
vec![
(Box::new(LtuSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C)),
(Box::new(EqSubtable::new()), SubtableIndices::from(0..C - 1)),
(
Box::new(RightIsZeroSubtable::new()),
SubtableIndices::from(0..C),
Expand Down

0 comments on commit 856c594

Please sign in to comment.