Skip to content

Commit

Permalink
Merge pull request #2908 from o1-labs/dw/riscv32im-check-boolean
Browse files Browse the repository at this point in the history
o1vm/riscv32im: simplify assert_boolean
  • Loading branch information
dannywillems authored Dec 24, 2024
2 parents 119f341 + a0177ab commit faa6062
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
4 changes: 2 additions & 2 deletions o1vm/src/interpreters/riscv32im/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl<Fp: Field> InterpreterEnv for Env<Fp> {
// No-op, witness only
}

fn check_boolean(_x: &Self::Variable) {
// No-op, witness only
fn assert_boolean(&mut self, x: &Self::Variable) {
self.add_constraint(x.clone() * x.clone() - x.clone());
}

fn add_lookup(&mut self, lookup: Lookup<Self::Variable>) {
Expand Down
8 changes: 1 addition & 7 deletions o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,8 @@ pub trait InterpreterEnv {
self.add_constraint(x - y);
}

/// Check that the witness value `x` is a boolean (`0` or `1`); otherwise abort.
fn check_boolean(x: &Self::Variable);

/// Assert that the value `x` is boolean, and add a constraint in the proof system.
fn assert_boolean(&mut self, x: &Self::Variable) {
Self::check_boolean(x);
self.add_constraint(x.clone() * x.clone() - x.clone());
}
fn assert_boolean(&mut self, x: &Self::Variable);

fn add_lookup(&mut self, lookup: Lookup<Self::Variable>);

Expand Down
4 changes: 2 additions & 2 deletions o1vm/src/interpreters/riscv32im/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl<Fp: Field> InterpreterEnv for Env<Fp> {
assert_eq!(*x, *y);
}

fn check_boolean(x: &Self::Variable) {
if !(*x == 0 || *x == 1) {
fn assert_boolean(&mut self, x: &Self::Variable) {
if *x != 0 && *x != 1 {
panic!("The value {} is not a boolean", *x);
}
}
Expand Down

0 comments on commit faa6062

Please sign in to comment.