add validation of frontier and tree

This commit is contained in:
Rene Vergara 2024-10-31 10:11:35 -05:00
parent 92cc2aabe4
commit c94bce3c25
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -1514,7 +1514,13 @@ pub extern "C" fn rust_wrapper_read_orchard_frontier(
Some(f2) => { Some(f2) => {
let (pos, leaf, omm) = f2.clone().into_parts(); let (pos, leaf, omm) = f2.clone().into_parts();
let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| Hhex { bytes: x.to_bytes().to_vec()}).collect()}; let f = Hfrontier { position: <u64>::from(pos), leaf: Hhex { bytes: leaf.to_bytes().to_vec()}, ommers: omm.iter().map(|&x| Hhex { bytes: x.to_bytes().to_vec()}).collect()};
let comm_tree2: Frontier<MerkleHashOrchard,32> = Frontier::from_parts(Position::from(f.position), MerkleHashOrchard::from_bytes(&to_array(f.leaf.bytes.clone())).unwrap(), f.ommers.iter().map(|x| MerkleHashOrchard::from_bytes(&to_array(x.bytes.clone())).unwrap() ).collect()).unwrap();
if f1.root() == comm_tree2.root() {
marshall_to_haskell_var(&f, out, out_len, RW); marshall_to_haskell_var(&f, out, out_len, RW);
} else {
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![Hhex { bytes: vec![0]}]};
marshall_to_haskell_var(&f0, out, out_len, RW);
}
}, },
None => { None => {
let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![Hhex { bytes: vec![0]}]}; let f0 = Hfrontier { position: 0, leaf: Hhex { bytes: vec![0]}, ommers: vec![Hhex { bytes: vec![0]}]};