From 5f1d75937b84cdc51ad81d7eb2a9b0123c57af3e Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 19 Mar 2024 17:15:06 -0600 Subject: [PATCH] zcash_client_backend: Treat protobuf default as the empty tree. Fixes #1280 --- zcash_client_backend/src/proto.rs | 44 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/zcash_client_backend/src/proto.rs b/zcash_client_backend/src/proto.rs index 3e58bc309..f9706c08b 100644 --- a/zcash_client_backend/src/proto.rs +++ b/zcash_client_backend/src/proto.rs @@ -263,15 +263,19 @@ impl service::TreeState { pub fn sapling_tree( &self, ) -> io::Result> { - let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Hex decoding of Sapling tree bytes failed: {:?}", e), + if self.sapling_tree.is_empty() { + Ok(CommitmentTree::empty()) + } else { + let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| { + io::Error::new( + io::ErrorKind::InvalidData, + format!("Hex decoding of Sapling tree bytes failed: {:?}", e), + ) + })?; + read_commitment_tree::( + &sapling_tree_bytes[..], ) - })?; - read_commitment_tree::( - &sapling_tree_bytes[..], - ) + } } /// Deserializes and returns the Sapling note commitment tree field of the tree state. @@ -280,15 +284,21 @@ impl service::TreeState { &self, ) -> io::Result> { - let orchard_tree_bytes = hex::decode(&self.orchard_tree).map_err(|e| { - io::Error::new( - io::ErrorKind::InvalidData, - format!("Hex decoding of Orchard tree bytes failed: {:?}", e), - ) - })?; - read_commitment_tree::( - &orchard_tree_bytes[..], - ) + if self.orchard_tree.is_empty() { + Ok(CommitmentTree::empty()) + } else { + let orchard_tree_bytes = hex::decode(&self.orchard_tree).map_err(|e| { + io::Error::new( + io::ErrorKind::InvalidData, + format!("Hex decoding of Orchard tree bytes failed: {:?}", e), + ) + })?; + read_commitment_tree::< + MerkleHashOrchard, + _, + { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }, + >(&orchard_tree_bytes[..]) + } } /// Parses this tree state into a [`ChainState`] for use with [`scan_cached_blocks`].