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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -99,6 +99,12 @@ impl core::fmt::Display for IncompleteTapTree { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
impl From<IncompleteTapTree> for crate::util::psbt::Error { | ||||||||||
fn from(i: IncompleteTapTree) -> Self { | ||||||||||
crate::util::psbt::Error::IncompleteTapTree(i) | ||||||||||
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use more readable names.
Suggested change
|
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Perhaps this could go in |
||||||||||
#[cfg(feature = "std")] | ||||||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))] | ||||||||||
impl std::error::Error for IncompleteTapTree { | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
//! | ||
|
||
use crate::prelude::*; | ||
use core; | ||
use core::convert::TryFrom; | ||
|
||
use crate::io; | ||
|
||
|
@@ -344,7 +346,7 @@ impl Deserialize for TapTree { | |
.map_err(|_| encode::Error::ParseFailed("Tree not in DFS order"))?; | ||
} | ||
if builder.is_finalizable() && !builder.has_hidden_nodes() { | ||
Ok(TapTree(builder)) | ||
Ok(TapTree::try_from(builder).map_err(psbt::Error::from)?) | ||
} else { | ||
Err(encode::Error::ParseFailed("Incomplete taproot Tree")) | ||
} | ||
|
@@ -395,6 +397,17 @@ mod tests { | |
assert_eq!(tree, tree_prime); | ||
} | ||
|
||
#[cfg(feature = "base64")] | ||
#[test] | ||
fn taptree_empty() { | ||
use core::str::FromStr; | ||
use crate::psbt::PartiallySignedTransaction; | ||
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"))))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it fails one case; will change it. |
||
} | ||
|
||
#[test] | ||
fn can_deserialize_non_standard_psbt_sighash_type() { | ||
let non_standard_sighash = [222u8, 0u8, 0u8, 0u8]; // 32 byte value. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inner
IncompleteTapTree
implementserror::Error
so this should returnSome(e)
instead ofNone
, same as forHashParse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/should/must/