1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/examples/merkleTree/sha256PathProof3.zok
2022-01-20 18:01:15 +01:00

23 lines
762 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 if condition then right else left fi, if condition then left else right fi
// 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] digest = leaf
// Loop up the tree
for u32 i in 0..DEPTH do
u32[8] left, u32[8] right = select(directionSelector[i], digest, path[i])
digest = hash(left, right)
endfor
return digest == root