1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/examples/merkleTree/sha256PathProof3.zok
2020-06-08 18:43:10 +02:00

30 lines
No EOL
1,005 B
Text

import "hashes/sha256/512bit" as sha256
import "utils/multiplexer/256bit" as multiplex
// Merkle-Tree inclusion proof for tree depth 3
def main(field treeDepth, bool[256] rootDigest, private bool[256] leafDigest, private bool[2] directionSelector, bool[256] PathDigest0, private bool[256] PathDigest1) -> (field):
//Setup
bool[256] currentDigest = leafDigest
field counter = 1
bool currentDirection = false
//Loop up the tree
currentDirection = directionSelector[0]
bool[256] lhs = multiplex(currentDirection, currentDigest, PathDigest0)
bool[256] 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
//Asserts
counter == treeDepth
rootDigest == currentDigest
return 1 //return true in success