31 lines
No EOL
1 KiB
Text
31 lines
No EOL
1 KiB
Text
import "hashes/sha256/512bit.code" as sha256
|
|
import "utils/multiplexer/256bit.code" as multiplex
|
|
import "utils/binary/not.code" as NOT
|
|
|
|
// Merke-Tree inclusion proof for tree depth 3
|
|
|
|
def main(field treeDepth, field[256] rootDigest, private field[256] leafDigest, private field[2] directionSelector, field[256] PathDigest0, private field[256] PathDigest1) -> (field):
|
|
|
|
//Setup
|
|
field[256] currentDigest = leafDigest
|
|
field counter = 1
|
|
field currentDirection = 0
|
|
|
|
//Loop up the tree
|
|
currentDirection = directionSelector[0]
|
|
lhs = multiplex(currentDirection, currentDigest, PathDigest0)
|
|
rhs = multiplex(NOT(currentDirection), currentDigest, PathDigest0)
|
|
currentDigest = sha256(lhs, rhs)
|
|
counter = counter + 1
|
|
|
|
currentDirection = directionSelector[1]
|
|
lhs = multiplex(currentDirection, currentDigest, PathDigest1)
|
|
rhs = multiplex(NOT(currentDirection), currentDigest, PathDigest1)
|
|
currentDigest = sha256(lhs, rhs)
|
|
counter = counter + 1
|
|
|
|
//Asserts
|
|
counter == treeDepth
|
|
rootDigest == currentDigest
|
|
|
|
return 1 //return true in success |