Skip to content

Commit

Permalink
fix(jolt-core): Fixes DIVU and REMU sequence_output (#506)
Browse files Browse the repository at this point in the history
* fix(jolt-core): Fixes DIVU and REMU sequence_output

We return the correct output from sequence output when the divisor is zero, for divu and remu.

* fmt

* addresses review comments
  • Loading branch information
mw2000 authored Nov 20, 2024
1 parent cb21f60 commit c90d6f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 10 additions & 2 deletions jolt-core/src/jolt/instruction/divu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
}

fn sequence_output(x: u64, y: u64) -> u64 {
x / y
if y == 0 {
match WORD_SIZE {
32 => u32::MAX as u64,
64 => u64::MAX,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
}
} else {
x / y
}
}
}

Expand All @@ -238,7 +246,7 @@ mod test {
use crate::{jolt::instruction::JoltInstruction, jolt_virtual_sequence_test};

#[test]
fn div_virtual_sequence_32() {
fn divu_virtual_sequence_32() {
jolt_virtual_sequence_test!(DIVUInstruction::<32>, RV32IM::DIVU);
}
}
12 changes: 8 additions & 4 deletions jolt-core/src/jolt/instruction/remu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for REMUInstruction<WORD
}

fn sequence_output(x: u64, y: u64) -> u64 {
match WORD_SIZE {
32 => (x as u32 % y as u32) as u64,
64 => x % y,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
if y == 0 {
x
} else {
match WORD_SIZE {
32 => (x as u32 % y as u32) as u64,
64 => x % y,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
}
}
}
}
Expand Down

0 comments on commit c90d6f9

Please sign in to comment.