From f59d31132c505063f045addb7719eb92ce9cee10 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 10 Jun 2021 23:57:45 +0100 Subject: [PATCH] Add Orchard empty root test vectors --- orchard_empty_roots.py | 23 +++++++++++++++++++++++ orchard_merkle_tree.py | 8 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 orchard_empty_roots.py diff --git a/orchard_empty_roots.py b/orchard_empty_roots.py new file mode 100644 index 0000000..9358036 --- /dev/null +++ b/orchard_empty_roots.py @@ -0,0 +1,23 @@ +from orchard_merkle_tree import empty_roots +from orchard_pallas import Fp +from tv_output import render_args, render_tv +from utils import i2lebsp + + +def main(): + args = render_args() + + render_tv( + args, + 'orchard_empty_roots', + ( + ('empty_roots', '[[u8; 32]; 33]'), + ), + { + 'empty_roots': list(map(bytes, empty_roots())), + }, + ) + + +if __name__ == '__main__': + main() diff --git a/orchard_merkle_tree.py b/orchard_merkle_tree.py index ac3b5fb..3425b61 100644 --- a/orchard_merkle_tree.py +++ b/orchard_merkle_tree.py @@ -11,6 +11,7 @@ from utils import i2lebsp, leos2bsp # https://zips.z.cash/protocol/nu5.pdf#constants MERKLE_DEPTH = 32 L_MERKLE = 255 +UNCOMMITTED_ORCHARD = Fp(2) # https://zips.z.cash/protocol/nu5.pdf#orchardmerklecrh def merkle_crh(layer, left, right): @@ -30,3 +31,10 @@ right = leos2bsp(right)[:L_MERKLE] parent = Fp(626278560043615083774572461435172561667439770708282630516615972307985967801) assert merkle_crh(MERKLE_DEPTH - 1 - 25, left, right) == parent assert merkle_crh(MERKLE_DEPTH - 1 - 26, left, right) != parent + +def empty_roots(): + empty_roots = [UNCOMMITTED_ORCHARD] + for layer in range(0, MERKLE_DEPTH)[::-1]: + bits = i2lebsp(L_MERKLE, empty_roots[-1].s) + empty_roots.append(merkle_crh(layer, bits, bits)) + return empty_roots