From 38e4131daaebd45bfe005e753b0b5716a4481d89 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 30 Sep 2024 13:18:47 -0500 Subject: [PATCH] feat!: update Orchard witness calculation Now uses Frontier --- librustzcash-wrapper/src/lib.rs | 7 ++++--- src/C/Zcash.chs | 2 +- src/ZcashHaskell/Orchard.hs | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index 63c4d2b..6034424 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -1548,9 +1548,10 @@ pub extern "C" fn rust_wrapper_read_orchard_witness( out: *mut u8, out_len: &mut usize ){ - let tree_in: Vec = marshall_from_haskell_var(tree, tree_len, RW); - let tree_reader = Cursor::new(tree_in); - let ct: CommitmentTree = read_commitment_tree(tree_reader).unwrap(); + let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW); + let leaf = MerkleHashOrchard::from_bytes(&to_array(tree_in.leaf.bytes)).unwrap(); + let frontier: Frontier = Frontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.clone())).unwrap() ).collect()).unwrap(); + let ct: CommitmentTree = CommitmentTree::from_frontier(&frontier); let inc_wit = IncrementalWitness::from_tree(ct); let mut out_bytes: Vec = Vec::new(); let result = write_incremental_witness(&inc_wit, &mut out_bytes); diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index 884d0e6..beb11e2 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -255,7 +255,7 @@ import ZcashHaskell.Types #} {# fun unsafe rust_wrapper_read_orchard_witness as rustWrapperReadOrchardWitness - { toBorshVar* `BS.ByteString'& + { toBorshVar* `OrchardFrontier'& , getVarBuffer `Buffer HexString'& } -> `()' diff --git a/src/ZcashHaskell/Orchard.hs b/src/ZcashHaskell/Orchard.hs index a4ef75a..1bb7167 100644 --- a/src/ZcashHaskell/Orchard.hs +++ b/src/ZcashHaskell/Orchard.hs @@ -220,15 +220,13 @@ updateOrchardCommitmentTree tree cmx = rustWrapperReadOrchardCommitmentTree tree (hexBytes cmx) -- | Get the Orchard incremental witness from a commitment tree -getOrchardWitness :: OrchardCommitmentTree -> Maybe OrchardWitness +getOrchardWitness :: OrchardFrontier -> Maybe OrchardWitness getOrchardWitness tree = if BS.length (hexBytes wit) > 1 then Just $ OrchardWitness wit else Nothing where - wit = - withPureBorshVarBuffer $ - rustWrapperReadOrchardWitness (hexBytes $ orchTree tree) + wit = withPureBorshVarBuffer $ rustWrapperReadOrchardWitness tree -- | Get the Sapling note position from a witness getOrchardNotePosition :: OrchardWitness -> Integer