Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Fix bug in deletion algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
musalbas committed Jul 21, 2020
1 parent db5b71f commit 92d305c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions smt.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,21 @@ func (smt *SparseMerkleTree) deleteWithSideNodes(path []byte, sideNodes [][]byte
copy(sideNode, sideNodes[i])

if currentValue == nil {
// This is the leaf sibling that we need to bubble up the tree.
currentHash = sideNode
currentValue = sideNode
continue
sideNodeValue, err := smt.ms.Get(sideNode)
if err != nil {
return nil, err
}

if smt.th.isLeaf(sideNodeValue) {
// This is the leaf sibling that needs to be bubbled up the tree.
currentHash = sideNode
currentValue = sideNode
continue
} else {
// This is the node sibling that needs to be left in its place.
currentValue = smt.th.placeholder()
nonPlaceholderReached = true
}
}

if !nonPlaceholderReached && bytes.Equal(sideNode, smt.th.placeholder()) {
Expand Down

0 comments on commit 92d305c

Please sign in to comment.