Created
June 10, 2019 11:03
-
-
Save dangerousfood/bf7014cba82a6e86025fd2c72bc0c73a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean verify_merkle_branch( | |
Bytes32 leaf, List<Bytes32> proof, int depth, int index, Bytes32 root) { | |
Bytes32 value = leaf; | |
for (int i = 0; i < depth; i++) { | |
if (Math.floor(index / Math.pow(2, i)) % 2 != 0) { | |
value = Hash.sha2_256(Bytes.concatenate(proof.get(i), value)); | |
} else { | |
value = Hash.sha2_256(Bytes.concatenate(value, proof.get(i))); | |
} | |
} | |
return value.equals(root); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment