Implement Frontier for Sapling #97

Merged
pitmutt merged 4 commits from rav001 into milestone2 2024-10-18 19:40:35 +00:00
3 changed files with 7 additions and 8 deletions
Showing only changes of commit 96cfe3a52a - Show all commits

View file

@ -1445,9 +1445,10 @@ pub extern "C" fn rust_wrapper_read_sapling_witness(
out: *mut u8, out: *mut u8,
out_len: &mut usize out_len: &mut usize
){ ){
let tree_in: Vec<u8> = marshall_from_haskell_var(tree, tree_len, RW); let tree_in: Hfrontier = marshall_from_haskell_var(tree, tree_len, RW);
let tree_reader = Cursor::new(tree_in); let leaf = Node::from_bytes(to_array(tree_in.leaf.bytes)).unwrap();
let ct: CommitmentTree<Node, SAPLING_DEPTH> = read_commitment_tree(tree_reader).unwrap(); let frontier: Frontier<Node, SAPLING_DEPTH> = Frontier::from_parts(Position::from(tree_in.position), leaf, tree_in.ommers.iter().map(|x| Node::from_bytes(to_array(x.clone())).unwrap() ).collect()).unwrap();
let ct: CommitmentTree<Node, SAPLING_DEPTH> = CommitmentTree::from_frontier(&frontier);
let inc_wit = IncrementalWitness::from_tree(ct); let inc_wit = IncrementalWitness::from_tree(ct);
let mut out_bytes: Vec<u8> = Vec::new(); let mut out_bytes: Vec<u8> = Vec::new();
let result = write_incremental_witness(&inc_wit, &mut out_bytes); let result = write_incremental_witness(&inc_wit, &mut out_bytes);

View file

@ -212,7 +212,7 @@ import ZcashHaskell.Types
#} #}
{# fun unsafe rust_wrapper_read_sapling_witness as rustWrapperReadSaplingWitness {# fun unsafe rust_wrapper_read_sapling_witness as rustWrapperReadSaplingWitness
{ toBorshVar* `BS.ByteString'& { toBorshVar* `SaplingFrontier'&
, getVarBuffer `Buffer HexString'& , getVarBuffer `Buffer HexString'&
} }
-> `()' -> `()'

View file

@ -210,15 +210,13 @@ updateSaplingCommitmentTree tree cmu =
rustWrapperReadSaplingCommitmentTree tree (hexBytes cmu) rustWrapperReadSaplingCommitmentTree tree (hexBytes cmu)
-- | Get the Sapling incremental witness from a commitment tree -- | Get the Sapling incremental witness from a commitment tree
getSaplingWitness :: SaplingCommitmentTree -> Maybe SaplingWitness getSaplingWitness :: SaplingFrontier -> Maybe SaplingWitness
getSaplingWitness tree = getSaplingWitness tree =
if BS.length (hexBytes wit) > 1 if BS.length (hexBytes wit) > 1
then Just $ SaplingWitness wit then Just $ SaplingWitness wit
else Nothing else Nothing
where where
wit = wit = withPureBorshVarBuffer $ rustWrapperReadSaplingWitness tree
withPureBorshVarBuffer $
rustWrapperReadSaplingWitness (hexBytes $ sapTree tree)
-- | Get the Sapling note position from a witness -- | Get the Sapling note position from a witness
getSaplingNotePosition :: SaplingWitness -> Integer getSaplingNotePosition :: SaplingWitness -> Integer