From 92d6da353137c10702fa4d181df2e136a1ca3342 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 21 Sep 2023 04:58:32 +1000 Subject: [PATCH] Fix a subtree comparison edge case (#7587) --- zebra-chain/src/orchard/tree.rs | 7 ++++++- zebra-chain/src/sapling/tree.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zebra-chain/src/orchard/tree.rs b/zebra-chain/src/orchard/tree.rs index 2bbe4872..3e571f42 100644 --- a/zebra-chain/src/orchard/tree.rs +++ b/zebra-chain/src/orchard/tree.rs @@ -440,7 +440,12 @@ impl NoteCommitmentTree { return self.is_complete_subtree(); } - // If `self` is the next index, check for spurious index differences. + // If `self` is the next index, check if the last note completed a subtree. + if self.is_complete_subtree() { + return true; + } + + // Then check for spurious index differences. // // There is one new subtree somewhere in the trees. It is either: // - a new subtree at the end of the previous tree, or diff --git a/zebra-chain/src/sapling/tree.rs b/zebra-chain/src/sapling/tree.rs index c940b94d..80b77ed2 100644 --- a/zebra-chain/src/sapling/tree.rs +++ b/zebra-chain/src/sapling/tree.rs @@ -421,7 +421,12 @@ impl NoteCommitmentTree { return self.is_complete_subtree(); } - // If `self` is the next index, check for spurious index differences. + // If `self` is the next index, check if the last note completed a subtree. + if self.is_complete_subtree() { + return true; + } + + // Then check for spurious index differences. // // There is one new subtree somewhere in the trees. It is either: // - a new subtree at the end of the previous tree, or