arnaucube
arnaucube/asmtPublic Self-hosted repository
add method VerifyInclusionWithRootC

Signed-off-by: p4u <pau@dabax.net>
p4u pau@dabax.net
Mon, 22 Mar 2021 11:35:02 +0100
commit

c679bcb81794b9ed8d09284bdb940d5846714146

parent

6fb3b028ac718d2a0248175bd0443c7bf8b68702

1 files changed, 6 insertions(+), 0 deletions(-)

jump to
M trie_merkle_proof.go → trie_merkle_proof.go

@@ -171,6 +171,12 @@ leafHash := s.hash(key, value, []byte{byte(s.TrieHeight - length)})

return bytes.Equal(s.Root, s.verifyInclusionC(bitmap, key, leafHash, ap, length, 0, 0)) } +// VerifyInclusionWithRootC verifies that key/value is included in the trie with latest root +func (s *Trie) VerifyInclusionWithRootC(root, bitmap, key, value []byte, ap [][]byte, length int) bool { + leafHash := s.hash(key, value, []byte{byte(s.TrieHeight - length)}) + return bytes.Equal(root, s.verifyInclusionC(bitmap, key, leafHash, ap, length, 0, 0)) +} + // verifyInclusionC returns the merkle root by hashing the merkle proof items func (s *Trie) verifyInclusionC(bitmap, key, leafHash []byte, ap [][]byte, length, keyIndex, apIndex int) []byte { if keyIndex == length {