Skip to content

Commit 040c29d

Browse files
committed
miniscript: remove MalleablePkH script context rule
This rule is weird and wrong in a number of ways. It was introduced in PR rust-bitcoin#97 c93bdef which was the massive PR that introduced the Ctx parameter. This particular rule wasn't commented on, but we can infer some things: * From the docs on the error and my vague memory, the problem was that we couldn't estimate satisfaction for a pubkeyhash fragment because we didn't know if the key was 33 or 65 bytes ahead of time. * Therefore, the code bans this in a legacy context, but not in bare contexts (in bare contexts there is a comment saying that bare fragments "can't contain miniscript because of standardness rules" so maybe we thought about this ... but that comment has never been true, so we thought wrong..). We should've banned the fragment in bare contexts as well. * Also, while the error is called MalleablePkH, none of this has anything to do with malleability! Later, in rust-bitcoin#431, we introduced the RawPkH fragment and put a pubkey into the PkH fragment. At that point, for PkH we always knew the pubkey and could just directly compute its size using the `is_uncompressed` accessor. The RawPkH fragment was a second-class citizen which didn't even have a string serialization. At this point we should have dropped the MalleablePkH rule. Still later, in rust-bitcoin#461, we introduced `ExtParams` and the ability to parse "insane" scripts in a more flexible way, including enabling the experimental `expr_raw_raw_pkh` fragment. We then gained an error `Analyzable::ContainsRawPkh` which conceptually overlaps with `ScriptContextError::MalleablePkH` but which isn't tied to any context, just whether the user has enabled this second-class feature.
1 parent a5c477b commit 040c29d

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/miniscript/context.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ use crate::{hash256, Error, ForEachKey, Miniscript, MiniscriptKey, Terminal};
2121
/// Error for Script Context
2222
#[derive(Clone, PartialEq, Eq, Debug)]
2323
pub enum ScriptContextError {
24-
/// Script Context does not permit PkH for non-malleability
25-
/// It is not possible to estimate the pubkey size at the creation
26-
/// time because of uncompressed pubkeys
27-
MalleablePkH,
2824
/// Script Context does not permit OrI for non-malleability
2925
/// Legacy fragments allow non-minimal IF which results in malleability
3026
MalleableOrI,
@@ -74,8 +70,7 @@ impl error::Error for ScriptContextError {
7470
use self::ScriptContextError::*;
7571

7672
match self {
77-
MalleablePkH
78-
| MalleableOrI
73+
MalleableOrI
7974
| MalleableDupIf
8075
| CompressedOnly(_)
8176
| XOnlyKeysNotAllowed(_, _)
@@ -97,7 +92,6 @@ impl error::Error for ScriptContextError {
9792
impl fmt::Display for ScriptContextError {
9893
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9994
match *self {
100-
ScriptContextError::MalleablePkH => write!(f, "PkH is malleable under Legacy rules"),
10195
ScriptContextError::MalleableOrI => write!(f, "OrI is malleable under Legacy rules"),
10296
ScriptContextError::MalleableDupIf => {
10397
write!(f, "DupIf is malleable under Legacy rules")
@@ -380,8 +374,6 @@ impl ScriptContext for Legacy {
380374
frag: &Terminal<Pk, Self>,
381375
) -> Result<(), ScriptContextError> {
382376
match *frag {
383-
Terminal::PkH(ref _pkh) => Err(ScriptContextError::MalleablePkH),
384-
Terminal::RawPkH(ref _pk) => Err(ScriptContextError::MalleablePkH),
385377
Terminal::OrI(ref _a, ref _b) => Err(ScriptContextError::MalleableOrI),
386378
Terminal::DupIf(ref _ms) => Err(ScriptContextError::MalleableDupIf),
387379
_ => Ok(()),

0 commit comments

Comments
 (0)