Prevent TapTree from hidden parts

This commit is contained in:
Dr Maxim Orlovsky 2022-04-05 22:30:34 +02:00
parent b0f3992db1
commit 77715311cf
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
2 changed files with 3 additions and 1 deletions

View File

@ -143,6 +143,8 @@ impl TapTree {
pub fn from_inner(inner: TaprootBuilder) -> Result<Self, IncompleteTapTree> { pub fn from_inner(inner: TaprootBuilder) -> Result<Self, IncompleteTapTree> {
if !inner.is_finalized() { if !inner.is_finalized() {
Err(IncompleteTapTree::NotFinalized(inner)) Err(IncompleteTapTree::NotFinalized(inner))
} else if inner.has_hidden_nodes() {
Err(IncompleteTapTree::HiddenParts(inner))
} else { } else {
Ok(TapTree(inner)) Ok(TapTree(inner))
} }

View File

@ -355,7 +355,7 @@ impl Deserialize for TapTree {
builder = builder.add_leaf_with_ver(*depth, script, leaf_version) builder = builder.add_leaf_with_ver(*depth, script, leaf_version)
.map_err(|_| encode::Error::ParseFailed("Tree not in DFS order"))?; .map_err(|_| encode::Error::ParseFailed("Tree not in DFS order"))?;
} }
if builder.is_finalized() { if builder.is_finalized() || !builder.has_hidden_nodes() {
Ok(TapTree(builder)) Ok(TapTree(builder))
} else { } else {
Err(encode::Error::ParseFailed("Incomplete taproot Tree")) Err(encode::Error::ParseFailed("Incomplete taproot Tree"))