Skip to content

Commit

Permalink
Merge pull request #2905 from o1-labs/dw/mul-overflow
Browse files Browse the repository at this point in the history
o1vm/riscv32im: test overflow for MUL
  • Loading branch information
dannywillems authored Dec 24, 2024
2 parents 12a1b74 + 54c8053 commit 0ae7560
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Binary file added o1vm/resources/programs/riscv32im/bin/mul_overflow
Binary file not shown.
18 changes: 18 additions & 0 deletions o1vm/resources/programs/riscv32im/src/mul_overflow.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.section .text
.globl _start

_start:
li t0, 10000000 # Large number
li t1, 10000000 # Another large number
mul t2, t0, t1 # Test large multiplication (Expected overflow)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
16 changes: 16 additions & 0 deletions o1vm/tests/test_riscv_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,19 @@ fn test_remu_by_zero() {
witness.step();
}
}

#[test]
fn test_mul_overflow() {
let curr_dir = std::env::current_dir().unwrap();
let path = curr_dir.join(std::path::PathBuf::from(
"resources/programs/riscv32im/bin/mul_overflow",
));
let state = o1vm::elf_loader::parse_riscv32(&path).unwrap();
let mut witness = Env::<Fp>::create(PAGE_SIZE.try_into().unwrap(), state);

while !witness.halt {
witness.step();
}

assert_eq!(witness.registers[T2], 276447232);
}

0 comments on commit 0ae7560

Please sign in to comment.