TapTree can be build from TaprootBuilder having hidden branches; however PSBT does not provide format for presenting hidden branches. Thus, TapTree psbt serialization is buggy: it will present incorrect representation of trees/descriptors with hidden branches. As a result, TapTree also fails to roundtrip if a hidden branch is present:
#[test]
fn taptree_roundtrip_hidden() {
let mut builder = compose_taproot_builder(0x51, [2, 2, 2]);
builder = builder.add_leaf_with_ver(3, Script::from_hex("b9").unwrap(), LeafVersion::from_consensus(0xC2).unwrap()).unwrap();
builder = builder.add_hidden(3, sha256::Hash::default()).unwrap();
let tree = TapTree::from_inner(builder).unwrap();
let tree_prime = TapTree::deserialize(&tree.serialize()).unwrap();
assert_eq!(tree, tree_prime);
}
fails: test result: FAILED. 248 passed; 1 failed
---- util::psbt::serialize::tests::taptree_roundtrip_hidden stdout ----
thread 'util::psbt::serialize::tests::taptree_roundtrip_hidden' panicked at 'called Result::unwrap() on an Err value: ParseFailed("Tree not in DFS order")', src/util/psbt/serialize.rs:415:66
The proposed solution is to introduce TaprootBuilder::has_hidden_branches and check that in TapTree::from_inner, returning error. I am already working on a PR fixing that.
Related discussion: #924 (comment)
TapTreecan be build fromTaprootBuilderhaving hidden branches; however PSBT does not provide format for presenting hidden branches. Thus,TapTreepsbt serialization is buggy: it will present incorrect representation of trees/descriptors with hidden branches. As a result,TapTreealso fails to roundtrip if a hidden branch is present:fails:
test result: FAILED. 248 passed; 1 failed---- util::psbt::serialize::tests::taptree_roundtrip_hidden stdout ----
thread 'util::psbt::serialize::tests::taptree_roundtrip_hidden' panicked at 'called
Result::unwrap()on anErrvalue: ParseFailed("Tree not in DFS order")', src/util/psbt/serialize.rs:415:66The proposed solution is to introduce
TaprootBuilder::has_hidden_branchesand check that inTapTree::from_inner, returning error. I am already working on a PR fixing that.Related discussion: #924 (comment)