-
Notifications
You must be signed in to change notification settings - Fork 295
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
fix: get_next_power_exponent off by 1 #11169
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5490a82
to
6ece169
Compare
a1eec2b
to
2de30bd
Compare
3985ec0
to
06e9cc2
Compare
@@ -20,7 +20,8 @@ pub struct VariableMerkleTree { | |||
/// The smallest exponent `n` where `2^n >= input` | |||
unconstrained fn get_next_power_exponent(input: u32, start: u8) -> u8 { | |||
let mut next_power_exponent = 0; | |||
if input <= 2 << start { | |||
// We check if input is less than or equal to 2^start. | |||
if input <= (1 << start) { |
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.
This was a crux of the bug because 2 << start is not equal to 2^start but to 2^(start+1).
@@ -49,8 +50,8 @@ fn get_prev_power_2(value: u32) -> u32 { | |||
get_next_power_exponent(value, 0) | |||
}; | |||
|
|||
let next_power_2 = 2 << next_power_exponent; |
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.
Here it didn't cause an issue because we were shifting 2 and not 1.
let next_power_2 = 2 << next_power_exponent; | ||
let prev_power_2 = next_power_2 / 2; | ||
let prev_power_2 = 1 << (next_power_exponent - 1); | ||
let next_power_2 = prev_power_2 * 2; |
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.
I sneaked in an optimization. I compute prev_power_2 first and then I multiply by 2 to get next_power_2. This should be cheaper constraint-wise as division is more expensive than multiplication.
2de30bd
to
26c5817
Compare
e56a20c
to
6e9f6c5
Compare
This reverts commit 06e9cc2.
6e9f6c5
to
d4b3da4
Compare
* master: (329 commits) fix(avm): mac build (#11195) fix: docs rebuild patterns (#11191) chore: refactor Solidity Transcript and improve error handling in sol_honk flow (#11158) chore: move witness computation into class plus some other cleanup (#11140) fix: get_next_power_exponent off by 1 (#11169) chore(avm): vm2 followup cleanup (#11186) fix: underconstrained bug (#11174) refactor: VariableMerkleTree readability improvements (#11165) chore: removing noir bug workaround (#10535) chore(docs): Remove node pages (#11161) git subrepo push --branch=master noir-projects/aztec-nr git_subrepo.sh: Fix parent in .gitrepo file. [skip ci] chore: replace relative paths to noir-protocol-circuits git subrepo push --branch=master barretenberg feat(avm2): avm redesign init (#10906) feat: Sync from noir (#11138) feat: simulator split (#11144) chore: rpc server cleanup & misc fixes (#11145) git subrepo push --branch=master noir-projects/aztec-nr git_subrepo.sh: Fix parent in .gitrepo file. [skip ci] ...
There was an issue with
get_next_power_exponent
func which resulted in it returning values off by 1. This didn't cause a bug but it was confusing.