Skip to content

Commit

Permalink
Merge pull request #2890 from o1-labs/o1vm/mips-sign-extend-case-zero
Browse files Browse the repository at this point in the history
o1vm/mips: use u64 to avoid overflow when bitlength is 0
  • Loading branch information
dannywillems authored Dec 24, 2024
2 parents 677ec14 + a709048 commit 00327cc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion o1vm/src/interpreters/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,13 @@ pub trait InterpreterEnv {
let pos = self.alloc_scratch();
unsafe { self.bitmask(x, bitlength, bitlength - 1, pos) }
};
high_bit * Self::constant(((1 << (32 - bitlength)) - 1) << bitlength) + x.clone()
// Casting in u64 for special case of bitlength = 0 to avoid overflow.
// No condition for constant time execution.
// Decomposing the steps for readability.
let v: u64 = (1u64 << (32 - bitlength)) - 1;
let v: u64 = v << bitlength;
let v: u32 = v as u32;
high_bit * Self::constant(v) + x.clone()
}

fn report_exit(&mut self, exit_code: &Self::Variable);
Expand Down

0 comments on commit 00327cc

Please sign in to comment.