diff --git a/lib/crypto/merkle.js b/lib/crypto/merkle.js index 8e05dd73..c54245a3 100644 --- a/lib/crypto/merkle.js +++ b/lib/crypto/merkle.js @@ -95,14 +95,16 @@ exports.createBranch = function createBranch(index, leaves) { */ exports.verifyBranch = function verifyBranch(hash, branch, index) { + let root = hash; + for (let otherside of branch) { if (index & 1) - hash = digest.root256(otherside, hash); + root = digest.root256(otherside, root); else - hash = digest.root256(hash, otherside); + root = digest.root256(root, otherside); index >>>= 1; } - return hash; + return root; };