1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00
ZoKrates/zokrates_cli/examples/merkleTree/sha256PathProof3.zok
2020-07-16 00:12:39 +02:00

33 lines
No EOL
1.2 KiB
Text

import "hashes/sha256/512bit" as sha256
import "utils/multiplexer/256bit" as multiplex
// Merkle-Tree inclusion proof for tree depth 3
<<<<<<< HEAD
def main(field treeDepth, u32[8] rootDigest, private u32[8] leafDigest, private bool[2] directionSelector, u32[8] PathDigest0, private u32[8] PathDigest1) -> (field):
=======
def main(field treeDepth, bool[256] rootDigest, private bool[256] leafDigest, private bool[2] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1) -> ():
>>>>>>> 26f4d72ee6e0c802823cf145fbd11a372586eb28
//Setup
u32[8] currentDigest = leafDigest
field counter = 1
bool currentDirection = false
//Loop up the tree
currentDirection = directionSelector[0]
u32[8] lhs = multiplex(currentDirection, currentDigest, PathDigest0)
u32[8] rhs = multiplex(!currentDirection, currentDigest, PathDigest0)
currentDigest = sha256(lhs, rhs)
counter = counter + 1
currentDirection = directionSelector[1]
lhs = multiplex(currentDirection, currentDigest, PathDigest1)
rhs = multiplex(!currentDirection, currentDigest, PathDigest1)
currentDigest = sha256(lhs, rhs)
counter = counter + 1
assert(counter == treeDepth)
assert(rootDigest == currentDigest)
return