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: provide a safe way to obtain leaf index from mmrIndex #19

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

robinbryce
Copy link
Contributor

When the merklebuilder is adding a node it is guaranteed that the before and after mmrIndex are also valid mmrSizes. This lets it use LeafCount to directly obtain the leafIndex of the item just added.

This led to the regular use of LeafCount as the way to get the leaf index. It is not safe to do this in general.

This change adds FirstMMRSize which returns the size of the smallest valid MMR which containes the node identified by mmrIndex

To provide a clear idiom for safely getting the leaf index from a node index (mmrIndex), LeafIndex(mmrIndex) is additionaly provided as a convenience for

LeafCount(FirstMMRSize(mmrIndex)) - 1

AB#9551

When the merklebuilder is adding a node it is guaranteed that the before
and after mmrIndex are also valid mmrSizes. This lets it use LeafCount
to directly obtain the leafIndex of the item just added.

This led to the regular use of LeafCount as the way to get the leaf
index. It is not safe to do this in general.

This change adds FirstMMRSize which returns the size of the smallest
valid MMR which containes the node identified by mmrIndex

To provide a clear idiom for safely getting the leaf index from a node
index (mmrIndex), LeafIndex(mmrIndex) is additionaly provided as a
convenience for

  LeafCount(FirstMMRSize(mmrIndex)) - 1

AB#9551
@robinbryce robinbryce merged commit 6bea50d into main Jun 5, 2024
1 check passed
@robinbryce robinbryce deleted the dev/robin/9551-leafcount-as-index-footgun branch June 5, 2024 08:33
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