-
Notifications
You must be signed in to change notification settings - Fork 0
fix: bug in lca #194
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: bug in lca #194
Conversation
3fe3e39
to
52fbadb
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #194 +/- ##
==========================================
+ Coverage 61.86% 65.49% +3.62%
==========================================
Files 36 36
Lines 1631 1788 +157
Branches 1631 1788 +157
==========================================
+ Hits 1009 1171 +162
+ Misses 571 564 -7
- Partials 51 53 +2 ☔ View full report in Codecov by Sentry. |
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.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @aner-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types.rs
line 112 at r1 (raw file):
if post_common_prefix_len == 0 && self < other { return *self; }
please add a short comment above this block explaining what does this if
indicate (self
is an ancestor of other
?)
Code quote:
if post_common_prefix_len == 0 && self < other {
return *self;
}
crates/committer/src/patricia_merkle_tree/types_test.rs
line 55 at r1 (raw file):
#[case(U256([9,0]), U256([12,0]), U256([1,0]))] #[case(U256([1,0]), U256([2,0]), U256([1,0]))] #[case(U256([2,0]), U256([1,0]), U256([1,0]))]
The order of the u128s may depend on the architecture of the system.
Use U256::new(x)
instead of U256([x, 0])
Code quote:
#[case(U256([1,0]), U256([1,0]), U256([1,0]))]
#[case(U256([2,0]), U256([5,0]), U256([2,0]))]
#[case(U256([5,0]), U256([2,0]), U256([2,0]))]
#[case(U256([8,0]), U256([10,0]), U256([2,0]))]
#[case(U256([9,0]), U256([12,0]), U256([1,0]))]
#[case(U256([1,0]), U256([2,0]), U256([1,0]))]
#[case(U256([2,0]), U256([1,0]), U256([1,0]))]
crates/committer/src/patricia_merkle_tree/types_test.rs
line 59 at r1 (raw file):
U256::from_str_hex("0x200000000000000000000000000000000000000000000000000000000000000").unwrap(), U256::from_str_hex("0x800000000000000000000000000000000000000000000000000000000000000").unwrap(), U256::from_str_hex("0x200000000000000000000000000000000000000000000000000000000000000").unwrap()
this case is a bit difficult to read; can you use U256::from_words
and use bit-shifting to describe the high value?
Code quote:
U256::from_str_hex("0x200000000000000000000000000000000000000000000000000000000000000").unwrap(),
U256::from_str_hex("0x800000000000000000000000000000000000000000000000000000000000000").unwrap(),
U256::from_str_hex("0x200000000000000000000000000000000000000000000000000000000000000").unwrap()
52fbadb
to
4f0d5c6
Compare
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.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types.rs
line 112 at r1 (raw file):
Previously, dorimedini-starkware wrote…
please add a short comment above this block explaining what does this
if
indicate (self
is an ancestor ofother
?)
Done.
crates/committer/src/patricia_merkle_tree/types_test.rs
line 55 at r1 (raw file):
Previously, dorimedini-starkware wrote…
The order of the u128s may depend on the architecture of the system.
UseU256::new(x)
instead ofU256([x, 0])
Done.
crates/committer/src/patricia_merkle_tree/types_test.rs
line 59 at r1 (raw file):
Previously, dorimedini-starkware wrote…
this case is a bit difficult to read; can you use
U256::from_words
and use bit-shifting to describe the high value?
Done.
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.
Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @aner-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types_test.rs
line 51 at r2 (raw file):
#[case(U256::new(1), U256::new(1), U256::new(1))] #[case(U256::new(2), U256::new(5), U256::new(2))] #[case(U256::new(5), U256([2,0]), U256([2,0]))]
still need new
here
Code quote:
U256([2,0]), U256([2,0]))]
crates/committer/src/patricia_merkle_tree/types_test.rs
line 63 at r2 (raw file):
#[case( U256::from_words(6<<121, 12109832645278165874326859176438297), U256::from_words(7<<121, 34269583569287659876592876529763453),
what are these low
values?
Code quote:
U256::from_words(6<<121, 12109832645278165874326859176438297),
U256::from_words(7<<121, 34269583569287659876592876529763453),
crates/committer/src/patricia_merkle_tree/types_test.rs
line 64 at r2 (raw file):
U256::from_words(6<<121, 12109832645278165874326859176438297), U256::from_words(7<<121, 34269583569287659876592876529763453), U256([3,0])
Suggestion:
U256::new(3)
e7c7936
to
ca598c8
Compare
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.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types_test.rs
line 63 at r2 (raw file):
Previously, dorimedini-starkware wrote…
what are these
low
values?
Just some random values, the idea is that it doesn't matter
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.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types_test.rs
line 51 at r2 (raw file):
Previously, dorimedini-starkware wrote…
still need
new
here
Done.
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.
Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @TzahiTaub)
ca598c8
to
aa621c9
Compare
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.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @aner-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types.rs
line 93 at r4 (raw file):
pub(crate) fn is_ancestor_of(&self, descendant: &NodeIndex) -> bool { self.bit_length() < descendant.bit_length()
question: is self not a descendant of self?
please rename function to is_strict_ancestor_of
just for clarity.
On the other hand, the only use case I see would benefit from a weak inequality... maybe change to <=
and rename function to is_ancestor_or_equal
?
Code quote:
self.bit_length() < descendant.bit_length()
crates/committer/src/patricia_merkle_tree/types.rs
line 94 at r4 (raw file):
pub(crate) fn is_ancestor_of(&self, descendant: &NodeIndex) -> bool { self.bit_length() < descendant.bit_length() && *self == *descendant >> (descendant.bit_length() - self.bit_length())
Suggestion:
let (self_bits, descendant_bits) = (self.bit_length(), descendant.bit_length());
self_bits < descendent_bits && *self == *descendant >> (descendant_bits - self_bits)
crates/committer/src/patricia_merkle_tree/types.rs
line 105 at r4 (raw file):
if self.is_ancestor_of(other) { return *self; }
Suggestion:
// If self equal to / is an ancestor of other, return self.
if self.is_ancestor_or_equal(other) {
return *self;
}
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.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @aner-starkware)
crates/committer/src/patricia_merkle_tree/types_test.rs
line 49 at r4 (raw file):
#[rstest] #[case(U256::new(1), U256::new(1), U256::new(1))]
Shorter macro
Suggestion:
uint!(
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.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @aner-starkware)
crates/committer/src/patricia_merkle_tree/types.rs
line 105 at r4 (raw file):
} else { *self >> (bit_length - other_bit_length) };
This is the only fix needed. Please remove the rest of the additions.
Suggestion:
// Bring self and other to a common (low) height.
let (adapted_self, adapter_other) = if self < other {
(*self, *other >> (other_bit_length - bit_length))
} else {
(*self >> (bit_length - other_bit_length), *other)
};
aa621c9
to
e9fbe36
Compare
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.
Reviewable status: 1 of 2 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)
crates/committer/src/patricia_merkle_tree/types.rs
line 93 at r4 (raw file):
Previously, dorimedini-starkware wrote…
question: is self not a descendant of self?
please rename function tois_strict_ancestor_of
just for clarity.On the other hand, the only use case I see would benefit from a weak inequality... maybe change to
<=
and rename function tois_ancestor_or_equal
?
Not relevant anymore.
crates/committer/src/patricia_merkle_tree/types.rs
line 94 at r4 (raw file):
pub(crate) fn is_ancestor_of(&self, descendant: &NodeIndex) -> bool { self.bit_length() < descendant.bit_length() && *self == *descendant >> (descendant.bit_length() - self.bit_length())
Not relevant anymore.
crates/committer/src/patricia_merkle_tree/types.rs
line 105 at r4 (raw file):
if self.is_ancestor_of(other) { return *self; }
Not relevant anymore.
crates/committer/src/patricia_merkle_tree/types.rs
line 105 at r4 (raw file):
Previously, TzahiTaub (Tzahi) wrote…
This is the only fix needed. Please remove the rest of the additions.
Done.
Previously, TzahiTaub (Tzahi) wrote…
This macro works from strings, it's less clear imo. |
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.
Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TzahiTaub)
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.
Reviewed all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @aner-starkware)
crates/committer/src/patricia_merkle_tree/types.rs
line 101 at r5 (raw file):
let other_bit_length = other.bit_length(); // Bring self and other to a common (low) height. let (adapted_self, adapter_other) = if self < other {
Suggestion:
adapted_other
e9fbe36
to
7e5480f
Compare
7e5480f
to
ebfa309
Compare
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.
Reviewed 2 of 2 files at r6.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @aner-starkware)
This change is