1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/demo/pedersenTree3.code
2019-06-22 17:32:51 +02:00

34 lines
1.2 KiB
Text

import "./pedersen.code" as hash
import "ecc/edwardsCompress.code" as edwardsCompress
import "ecc/babyjubjubParams.code" as context
import "utils/multiplexer/256bitsCond.code" as multiplex
import "utils/binary/not.code" as NOT
// Merke-Tree inclusion proof for tree depth 3 using SNARK efficient pedersen hashes
// directionSelector=> 1/true if current digest is on the rhs of the hash
def main(field[256] rootDigest, private field[256] leafDigest, private field[3] directionSelector, field[256] PathDigest0, private field[256] PathDigest1, private field[256] PathDigest2) -> (field):
context = context()
//Setup
field[256] currentDigest = leafDigest
field counter = 1
//Loop up the tree
preimage = multiplex(directionSelector[0], currentDigest, PathDigest0)
currentDigest = hash(preimage)
counter = counter + 1
preimage = multiplex(directionSelector[1], currentDigest, PathDigest1)
currentDigest = hash(preimage)
counter = counter + 1
preimage = multiplex(directionSelector[2], currentDigest, PathDigest2)
currentDigest = hash(preimage)
counter = counter + 1
//Asserts
//TODO: is depth comparison needed?
// counter == treeDepth
rootDigest == currentDigest
return 1 //return true in success