Skip to content
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: Correct the fillup_index #938

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Conversation

vadorovsky
Copy link
Contributor

@vadorovsky vadorovsky commented Jul 2, 2024

fillup_index used to be our limit of hashes computed for each non-terminal Merkle path in a batched update. However, it didn't work reliably.

fillup_index limited to next_index().trailing_ones() was resulting in filled_subtrees not being updated in case when fillup_index was 0.

Incrementing it by 1, which we used to do, was a workaround which worked for the most cases in a sense of producing correct roots, but the non-terminal Merkle paths were incorrect - they contained one node too many.

Here we are introducing a different approach where we always iterate in 0..self.height range, but we break the loop as soon as we encounter a node on the left. Before breaking the loop, we update filled_subtrees. Therefore, both filled_subtrees and all Merkle paths are correct.

@vadorovsky vadorovsky requested a review from ananas-block as a code owner July 2, 2024 20:05
`fillup_index` used to be our arbitrary limit of hashes computed for
each non-terminal Merkle path in a batched update. However, it didn't
work reliably.

`fillup_index` limited to `next_index().trailing_ones()` was resulting
in `filled_subtrees` not being updated in case when `fillup_index` was 0.

Incrementing it by 1, which we used to do, was a workaround which worked
for the most cases in a sense of producing correct roots, but the
non-terminal Merkle paths were incorrect - they contained one node too
many.

Here we are introducing a different approach where we always iterate in
`0..self.height` range, but we break the loop as soon as we encounter a
node on the left. Before breaking the loop, we update `filled_subtrees`.
Therefore, both `filled_subtrees` and all Merkle paths are correct.
@vadorovsky vadorovsky force-pushed the vaodorovsky/mt-fix-batched-append branch from 2e2c200 to ff646dd Compare July 2, 2024 22:29
@vadorovsky vadorovsky merged commit 216b6e5 into main Jul 2, 2024
14 checks passed
@vadorovsky vadorovsky deleted the vaodorovsky/mt-fix-batched-append branch July 2, 2024 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants