-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
o1vm/mips: fix failing constraints #2729
Changes from all commits
7d24e4d
0ff0ca0
f0aa273
7d650a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,13 +361,44 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreI | |
} | ||
} | ||
|
||
fn equal(&mut self, x: &Self::Variable, y: &Self::Variable) -> Self::Variable { | ||
// To avoid subtraction overflow in the witness interpreter for u32 | ||
if x > y { | ||
self.is_zero(&(*x - *y)) | ||
fn is_zero(&mut self, x: &Self::Variable) -> Self::Variable { | ||
// write the result | ||
let pos = self.alloc_scratch(); | ||
let res = if *x == 0 { 1 } else { 0 }; | ||
self.write_column(pos, res); | ||
// write the non deterministic advice inv_or_zero | ||
let pos = self.alloc_scratch(); | ||
let inv_or_zero = if *x == 0 { | ||
Fp::zero() | ||
} else { | ||
self.is_zero(&(*y - *x)) | ||
} | ||
Fp::inverse(&Fp::from(*x)).unwrap() | ||
}; | ||
self.write_field_column(pos, inv_or_zero); | ||
// return the result | ||
res | ||
} | ||
|
||
fn equal(&mut self, x: &Self::Variable, y: &Self::Variable) -> Self::Variable { | ||
// We replicate is_zero(x-y), but working on field elt, | ||
// to avoid subtraction overflow in the witness interpreter for u32 | ||
let to_zero_test = Fp::from(*x) - Fp::from(*y); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to convert as early as here in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, but I believe this to be more clear, and the performance is negligibly impacted |
||
let res = { | ||
let pos = self.alloc_scratch(); | ||
let is_zero: u64 = if to_zero_test == Fp::zero() { 1 } else { 0 }; | ||
self.write_column(pos, is_zero); | ||
is_zero | ||
}; | ||
let _to_zero_test_inv_or_zero = { | ||
let pos = self.alloc_scratch(); | ||
let inv_or_zero = if to_zero_test == Fp::zero() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so at first as well, but Inverse_or_zero is forced to return a Variable by the signature, so we can't get the resulting field_inversion we desire here. |
||
Fp::zero() | ||
} else { | ||
Fp::inverse(&to_zero_test).unwrap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See a direct optimisation available here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here, built on top of that one |
||
}; | ||
self.write_field_column(pos, inv_or_zero); | ||
1 // Placeholder value | ||
}; | ||
res | ||
} | ||
|
||
unsafe fn test_less_than( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's less error prone if you move the
is_zero()
ininterpreter.rs
intoconstraint.rs
and define a variant ofis_zero()
inwitness.rs
containing precisely your replication here inequal()
. Otherwise, one could call theis_zero()
frominterpreter.rs
for the witness and incur in the same problem being fixed in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it is more clean