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

Commit

Permalink
sanityCheck: only calculate siblingHash if necessary, refactor and re…
Browse files Browse the repository at this point in the history
…duce nesting (#57)

Only calculate siblingHash to avoid wasting cycles when unneeded.
Also while here, reverse conditional the code to reduce nesting and
to make reading much simpler.

Fixes #56
  • Loading branch information
odeke-em authored Aug 15, 2021
1 parent a99c0f5 commit 5f13c0f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ func (proof *SparseMerkleProof) sanityCheck(th *treeHasher) bool {
}

// Check that the sibling data hashes to the first side node if not nil
if proof.SiblingData != nil {
siblingHash := th.digest(proof.SiblingData)
if proof.SideNodes != nil && len(proof.SideNodes) > 0 {
if !bytes.Equal(proof.SideNodes[0], siblingHash) {
return false
}
}
if proof.SiblingData == nil || len(proof.SideNodes) == 0 {
return true
}

return true
siblingHash := th.digest(proof.SiblingData)
return bytes.Equal(proof.SideNodes[0], siblingHash)
}

// SparseCompactMerkleProof is a compact Merkle proof for an element in a SparseMerkleTree.
Expand Down

0 comments on commit 5f13c0f

Please sign in to comment.