From f6b8a772770f492221dc99281016d7090f981e63 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 30 Oct 2024 13:23:46 -0500 Subject: [PATCH] feat: add function to test empty trees --- librustzcash-wrapper/src/lib.rs | 14 +++++++++++++- src/C/Zcash.chs | 7 +++++++ src/ZcashHaskell/Orchard.hs | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index a469cb8..d011e65 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -36,7 +36,8 @@ use incrementalmerkletree::{ frontier::{ CommitmentTree, Frontier, - NonEmptyFrontier + NonEmptyFrontier, + PathFiller }, witness::IncrementalWitness }; @@ -1618,6 +1619,17 @@ pub extern "C" fn rust_wrapper_combine_orchard_nodes( } } +#[no_mangle] +pub extern "C" fn rust_wrapper_get_orchard_root( + level: u8, + out: *mut u8, + out_len: &mut usize + ){ + let tree: CommitmentTree = CommitmentTree::empty(); + let root = tree.root_at_depth(level, PathFiller::empty()); + let h = Hhex { bytes: root.to_bytes().to_vec() }; + marshall_to_haskell_var(&h, out, out_len, RW); +} #[no_mangle] pub extern "C" fn rust_wrapper_read_orchard_commitment_tree( diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index da2f86b..abb7435 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -276,6 +276,13 @@ import ZcashHaskell.Types -> `()' #} +{# fun unsafe rust_wrapper_get_orchard_root as rustWrapperGetOrchardRootTest + { `Int8' + , getVarBuffer `Buffer HexString'& + } + -> `()' +#} + {# fun unsafe rust_wrapper_read_orchard_commitment_tree as rustWrapperReadOrchardCommitmentTree { toBorshVar* `OrchardFrontier'& , toBorshVar* `BS.ByteString'& diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index 79043ea..170e177 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -218,6 +218,10 @@ getOrchardWitnessAnchor wit = withPureBorshVarBuffer $ rustWrapperReadOrchardWitnessAnchor $ toBytes $ orchWit wit +getOrchardRootTest :: Int -> HexString +getOrchardRootTest level = + withPureBorshVarBuffer $ rustWrapperGetOrchardRootTest $ fromIntegral level + -- | Update a Orchard commitment tree updateOrchardCommitmentTree :: OrchardFrontier -- ^ the base tree