Skip to content

Instantly share code, notes, and snippets.

@dangerousfood
Created June 10, 2019 11:03
Show Gist options
  • Save dangerousfood/bf7014cba82a6e86025fd2c72bc0c73a to your computer and use it in GitHub Desktop.
Save dangerousfood/bf7014cba82a6e86025fd2c72bc0c73a to your computer and use it in GitHub Desktop.
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