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 proof generation handling of empty sibilings #72

Merged
merged 3 commits into from
Sep 20, 2024
Merged

Fix proof generation handling of empty sibilings #72

merged 3 commits into from
Sep 20, 2024

Conversation

jimthematrix
Copy link
Contributor

@jimthematrix jimthematrix commented Sep 17, 2024

The Proof object usually contains empty nodes, for efficiency we don't lug the empty node around but instead use a byte array of length 32, so that there are 256 bits one for each level, to indicate which levels are empty/non-empty.

This fixes some bugs in the handling of the array with both marking the bits and reading the bits

Copy link
Contributor

@Chengxuan Chengxuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment on the description of the function

@@ -104,14 +104,29 @@ func (mt *sparseMerkleTree) GetNode(key core.NodeIndex) (core.Node, error) {
// GenerateProof generates the proof of existence (or non-existence) of a leaf node
// for a Merkle Tree given the root. It uses the node's index to represent the node.
// If the rootKey is nil, the current merkletree root is used
func (mt *sparseMerkleTree) GenerateProof(k *big.Int, rootKey core.NodeIndex) (core.Proof, *big.Int, error) {
func (mt *sparseMerkleTree) GenerateProofs(keys []*big.Int, rootKey core.NodeIndex) ([]core.Proof, []*big.Int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this code several times trying to understand how this could relate to the problem described. then realized it's a just a refactor for code convenience. the description of the methods is not updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sorry this was a necessary improvement so that multiple proofs can be generated against the same root inside the sync'ed routine

Co-authored-by: Chengxuan Xing <[email protected]>
Signed-off-by: jimthematrix <[email protected]>
@jimthematrix jimthematrix merged commit b3713ab into main Sep 20, 2024
6 checks passed
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