26 lines
780 B
Text
26 lines
780 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 condition ? right : left, condition ? left : right;
|
|
}
|
|
|
|
// 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 {
|
|
u32[8] left, u32[8] right = select(directionSelector[i], digest, path[i]);
|
|
digest = hash(left, right);
|
|
}
|
|
|
|
return digest == root;
|
|
}
|
|
|
|
|