Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PSBT Deserialization to 174 Compliance over empty Taproot Tree #1194

Closed
wants to merge 2 commits into from

Conversation

JeremyRubin
Copy link
Contributor

Fixes #1192, partly (may also be a bug in Core it seems, so workflows involving core are stil broken?)

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this man. One nit and one suggestion for consideration please.

@@ -127,7 +132,8 @@ impl std::error::Error for Error {
| NonStandardSighashType(_)
| InvalidPreimageHashPair{ .. }
| CombineInconsistentKeySources(_)
| ConsensusEncoding => None,
| ConsensusEncoding
| IncompleteTapTree(_) => None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner IncompleteTapTree implements error::Error so this should return Some(e) instead of None, same as for HashParse.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/should/must/

crate::util::psbt::Error::IncompleteTapTree(i)
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Perhaps this could go in psbt::error belowe the other From impls.

@sanket1729
Copy link
Member

I would like to investigate this a bit more. builder::is_finalizable() implies that tree is complete. So, we should not have hit this branch at all.

@sanket1729
Copy link
Member

Looks like we are allowing empty trees. It was hard to think about this while merging #936 as we were indirectly reliant on the assumption of there being at least one leaf.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider proper error handling required.

src/util/psbt/error.rs Outdated Show resolved Hide resolved
@@ -127,7 +132,8 @@ impl std::error::Error for Error {
| NonStandardSighashType(_)
| InvalidPreimageHashPair{ .. }
| CombineInconsistentKeySources(_)
| ConsensusEncoding => None,
| ConsensusEncoding
| IncompleteTapTree(_) => None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/should/must/

let test_data_containing_empty =
"cHNidP8BAIkCAAAAAWlZ9F5/nRjE0quO8bE8cfKIiVTKHa/Zu6PKwWfpZDmpAAAAAAD9////Anz3nHYAAAAAIlEg7T17MEFOm47gN7FhZB5g4HjviGW4YxZWReJr1c/w0I+AlpgAAAAAACJRIDspRhxBQj5+aJw088IczFSbyRKB7wofy/SQXnErwCcQAAAAAAABASsAlDV3AAAAACJRIBMUosKNoVNU5tEW2Q/tylLRzabMGIprODHM0LbB8h1/IRaXdf3KRBBZMc8epg7uuU3pr42i3YMFnheNDW10F0cpnxkAHzYIzlYAAIABAACAAAAAgAAAAABRAAAAARcgl3X9ykQQWTHPHqYO7rlN6a+Not2DBZ4XjQ1tdBdHKZ8AAQUgT+NhtL213EJgJ51h6FiZYhPgUv48YQKACnnMYpOZPMEBBgAhB0/jYbS9tdxCYCedYehYmWIT4FL+PGECgAp5zGKTmTzBGQAfNgjOVgAAgAEAAIAAAACAAQAAADEBAAAAAQUgrUXPD+fhaOeY7GlxJDZ0pAgUZ0reW+A3wmxMwBAIt14BBgAhB61Fzw/n4WjnmOxpcSQ2dKQIFGdK3lvgN8JsTMAQCLdeGQAfNgjOVgAAgAEAAIAAAACAAAAAAFIAAAAA";
let psbt = PartiallySignedTransaction::from_str(test_data_containing_empty);
assert!(matches!(psbt, Err(psbt::PsbtParseError::PsbtEncoding(encode::Error::ParseFailed("Incomplete taproot Tree")))));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches! is not available in our MSRV. How the hell does this pass CI?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it fails one case; will change it.

Comment on lines +103 to +104
fn from(i: IncompleteTapTree) -> Self {
crate::util::psbt::Error::IncompleteTapTree(i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use more readable names.

Suggested change
fn from(i: IncompleteTapTree) -> Self {
crate::util::psbt::Error::IncompleteTapTree(i)
fn from(error: IncompleteTapTree) -> Self {
crate::util::psbt::Error::IncompleteTapTree(error)

@JeremyRubin
Copy link
Contributor Author

Looks like we are allowing empty trees. It was hard to think about this while merging #936 as we were indirectly reliant on the assumption of there being at least one leaf.

I don't think that's the source of the error, the source of the error is that we directly construct TapTree here rather than using TapTree try_from.

@apoelstra
Copy link
Member

Hmm, maybe it's time already to open a Rust 2021 tracking issue to list stuff like matches! that we'd like to have.

@Kixunil
Copy link
Collaborator

Kixunil commented Aug 19, 2022

@apoelstra #1060 is already open. :) Also matches! is available in 1.42, which is just one version higher than current MSRV.

Co-authored-by: Martin Habovštiak <martin.habovstiak@gmail.com>
@fanquake
Copy link

Note that the related upstream Core PR is now: bitcoin/bitcoin#25858, if anyone here is interested in reviewing.

@JeremyRubin
Copy link
Contributor Author

up for grabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reachable Line in Serialization of Incomple TapTree
6 participants