1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_cli/examples/merkleTree/sha256PathProof3.zok
2022-06-28 19:23:45 +02:00

26 lines
752 B
Text

import "hashes/sha256/512bit" as hash;
import "hashes/utils/256bitsDirectionHelper" as multiplex;
const u32 DEPTH = 3;
def select(bool condition, u32[8] left, u32[8] right) -> (u32[8], u32[8]) {
return (condition ? right : left, condition ? left : right);
}
// Merke-Tree inclusion proof for tree depth 4 using sha256
// directionSelector => true if current digest is on the rhs of the hash
def main(u32[8] root, private u32[8] leaf, private bool[DEPTH] directionSelector, private u32[DEPTH][8] path) -> bool {
// Start from the leaf
u32[8] mut digest = leaf;
// Loop up the tree
for u32 i in 0..DEPTH {
(u32[8], u32[8]) s = select(directionSelector[i], digest, path[i]);
digest = hash(s.0, s.1);
}
return digest == root;
}