-
Notifications
You must be signed in to change notification settings - Fork 180
refactor: remove SortedMultiVec and use Terminal::SortedMulti #915
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
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 |
|---|---|---|
|
|
@@ -36,15 +36,13 @@ mod bare; | |
| mod iter; | ||
| mod segwitv0; | ||
| mod sh; | ||
| mod sortedmulti; | ||
| mod tr; | ||
|
|
||
| // Descriptor Exports | ||
| pub use self::bare::{Bare, Pkh}; | ||
| pub use self::iter::PkIter; | ||
| pub use self::segwitv0::{Wpkh, Wsh, WshInner}; | ||
| pub use self::segwitv0::{Wpkh, Wsh}; | ||
| pub use self::sh::{Sh, ShInner}; | ||
| pub use self::sortedmulti::SortedMultiVec; | ||
| pub use self::tr::{ | ||
| TapTree, TapTreeDepthError, TapTreeIter, TapTreeIterItem, Tr, TrSpendInfo, TrSpendInfoIter, | ||
| TrSpendInfoIterItem, | ||
|
|
@@ -256,18 +254,11 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> { | |
| Descriptor::Pkh(ref pk) => PkIter::from_key(pk.as_inner().clone()), | ||
| Descriptor::Wpkh(ref pk) => PkIter::from_key(pk.as_inner().clone()), | ||
| Descriptor::Sh(ref sh) => match *sh.as_inner() { | ||
| ShInner::Wsh(ref wsh) => match wsh.as_inner() { | ||
| WshInner::SortedMulti(ref sorted) => PkIter::from_sortedmulti(sorted.pks()), | ||
| WshInner::Ms(ref ms) => PkIter::from_miniscript_segwit(ms), | ||
| }, | ||
| ShInner::Wsh(ref wsh) => PkIter::from_miniscript_segwit(wsh.as_inner()), | ||
| ShInner::Wpkh(ref pk) => PkIter::from_key(pk.as_inner().clone()), | ||
| ShInner::SortedMulti(ref sorted) => PkIter::from_sortedmulti(sorted.pks()), | ||
| ShInner::Ms(ref ms) => PkIter::from_miniscript_legacy(ms), | ||
| }, | ||
| Descriptor::Wsh(ref wsh) => match wsh.as_inner() { | ||
| WshInner::SortedMulti(ref sorted) => PkIter::from_sortedmulti(sorted.pks()), | ||
| WshInner::Ms(ref ms) => PkIter::from_miniscript_segwit(ms), | ||
| }, | ||
| Descriptor::Wsh(ref wsh) => PkIter::from_miniscript_segwit(wsh.as_inner()), | ||
| Descriptor::Tr(ref tr) => PkIter::from_tr(tr), | ||
| } | ||
| } | ||
|
|
@@ -313,18 +304,29 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> { | |
| Descriptor::Pkh(ref _pkh) => DescriptorType::Pkh, | ||
| Descriptor::Wpkh(ref _wpkh) => DescriptorType::Wpkh, | ||
| Descriptor::Sh(ref sh) => match sh.as_inner() { | ||
| ShInner::Wsh(ref wsh) => match wsh.as_inner() { | ||
| WshInner::SortedMulti(ref _smv) => DescriptorType::ShWshSortedMulti, | ||
| WshInner::Ms(ref _ms) => DescriptorType::ShWsh, | ||
| }, | ||
| ShInner::Wsh(ref wsh) => { | ||
| if let Terminal::SortedMulti(..) = wsh.as_inner().node { | ||
| DescriptorType::ShWshSortedMulti | ||
|
Member
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. In a65deea: As a followup let's maybe delete this from |
||
| } else { | ||
| DescriptorType::ShWsh | ||
| } | ||
| } | ||
| ShInner::Wpkh(ref _wpkh) => DescriptorType::ShWpkh, | ||
| ShInner::SortedMulti(ref _smv) => DescriptorType::ShSortedMulti, | ||
| ShInner::Ms(ref _ms) => DescriptorType::Sh, | ||
| }, | ||
| Descriptor::Wsh(ref wsh) => match wsh.as_inner() { | ||
| WshInner::SortedMulti(ref _smv) => DescriptorType::WshSortedMulti, | ||
| WshInner::Ms(ref _ms) => DescriptorType::Wsh, | ||
| ShInner::Ms(ref ms) => { | ||
| if let Terminal::SortedMulti(..) = ms.node { | ||
| DescriptorType::ShSortedMulti | ||
| } else { | ||
| DescriptorType::Sh | ||
| } | ||
| } | ||
| }, | ||
| Descriptor::Wsh(ref wsh) => { | ||
| if let Terminal::SortedMulti(..) = wsh.as_inner().node { | ||
| DescriptorType::WshSortedMulti | ||
| } else { | ||
| DescriptorType::Wsh | ||
| } | ||
| } | ||
| Descriptor::Tr(ref _tr) => DescriptorType::Tr, | ||
| } | ||
| } | ||
|
|
@@ -1208,6 +1210,7 @@ mod tests { | |
|
|
||
| use super::{checksum, *}; | ||
| use crate::hex_script; | ||
| use crate::miniscript::context::ScriptContextError; | ||
| #[cfg(feature = "compiler")] | ||
| use crate::policy; | ||
|
|
||
|
|
@@ -1257,7 +1260,7 @@ mod tests { | |
| StdDescriptor::from_str("sh(sortedmulti)") | ||
| .unwrap_err() | ||
| .to_string(), | ||
| "sortedmulti must have at least 1 children, but found 0" | ||
| "expected threshold, found terminal" | ||
| ); //issue 202 | ||
| assert_eq!( | ||
| StdDescriptor::from_str(&format!("sh(sortedmulti(2,{}))", &TEST_PK[3..69])) | ||
|
|
@@ -2884,4 +2887,26 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))"; | |
| let definite: Result<Descriptor<DefiniteDescriptorKey>, _> = desc.try_into(); | ||
| assert!(matches!(definite, Err(NonDefiniteKeyError::Wildcard))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn too_many_pubkeys_for_p2sh() { | ||
|
Contributor
Author
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. FYI: migrated from deleted |
||
| // Arbitrary 65-byte public key (66 with length prefix). | ||
| let pk = PublicKey::from_str( | ||
| "0400232a2acfc9b43fa89f1b4f608fde335d330d7114f70ea42bfb4a41db368a3e3be6934a4097dd25728438ef73debb1f2ffdb07fec0f18049df13bdc5285dc5b", | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| // This is legal for CHECKMULTISIG, but the 8 keys consume the whole 520 bytes | ||
| // allowed by P2SH, meaning that the full script goes over the limit. | ||
| let thresh = Threshold::new(2, vec![pk; 8]).expect("the thresh is ok.."); | ||
| let script = Miniscript::<_, Legacy>::sortedmulti(thresh).encode(); | ||
| let res = Miniscript::<_, Legacy>::decode(&script); | ||
|
|
||
| let error = res.expect_err("decoding should err"); | ||
|
|
||
| match error { | ||
| Error::ContextError(ScriptContextError::MaxRedeemScriptSizeExceeded { .. }) => {} // ok | ||
| other => panic!("unexpected error: {:?}", other), | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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 key point here was to call
sorted_node()and now we don't have something so convenient. See theHACKinfind_sks_msThere 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.
Interesting. So, the issue is that we want to get all the keys in the descriptor, in the order they'd be needed, and we're using
pk_iterfor this. Sincepk_itercan't sort the keys, we have to sort them after the fact.This is a bit of a weird thing to desire -- does this test actually fail without this? It seems like we never use the ordering of
sks_reqd. In fact, we lose the ordering because we iterate over it, produce signatures, then stick them into theBTreeMappsbt.inputs[0].partial_sigs.Also, since #910 I think the logic in this example is actually wrong, or at least inconsistent -- it would sort
sortedmultibut notsortedmulti_a. And your hack doesn't change this.So can we just drop the sortedmulti logic here and treat sortedmulti like multi?