Skip to content

Commit 0f03df0

Browse files
committed
Merge #758: fix: differentiate max witness script size upon context
13a1318 fix: differentiate max witness script size upon context (ChrisCho-H) Pull request description: `MaxWitnessScriptSizeExceeded` is used in the context of `SegwitV0` and `Tap`, where each of max witness script size differs. Moreover, even in the same context of `SegwitV0`, max witness script size differ whether it's standard or consensus rule. I just let `MaxWitnessScriptSizeExceeded` receive param `usize` to differentiate max witness script size upon context, which can fix the wrong err message of `"The Miniscript corresponding Script would be larger than MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."` when `SegwitV0` consensus and `Tap` context ACKs for top commit: apoelstra: ACK 13a1318; successfully ran local tests Tree-SHA512: 213d62443fa8b4d912495e1d60aa1e64165287348b145eb1c93f2e623589c49b0e37636f92d9185af4c3467006d0c0d5f6bf8d986ab1ff332dc5510900e0f1eb
2 parents 59506c6 + 13a1318 commit 0f03df0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/miniscript/context.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ pub enum ScriptContextError {
4747
/// than `MAX_OPS_PER_SCRIPT`(201) opcodes.
4848
MaxOpCountExceeded,
4949
/// The Miniscript(under segwit context) corresponding
50-
/// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE` bytes.
51-
MaxWitnessScriptSizeExceeded,
50+
/// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE`,
51+
/// `MAX_SCRIPT_SIZE` or `MAX_BLOCK`(`Tap`) bytes.
52+
MaxWitnessScriptSizeExceeded { max: usize, got: usize },
5253
/// The Miniscript (under p2sh context) corresponding Script would be
5354
/// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes.
5455
MaxRedeemScriptSizeExceeded,
@@ -81,7 +82,7 @@ impl error::Error for ScriptContextError {
8182
| UncompressedKeysNotAllowed
8283
| MaxWitnessItemsExceeded { .. }
8384
| MaxOpCountExceeded
84-
| MaxWitnessScriptSizeExceeded
85+
| MaxWitnessScriptSizeExceeded { .. }
8586
| MaxRedeemScriptSizeExceeded
8687
| MaxBareScriptSizeExceeded
8788
| MaxScriptSigSizeExceeded
@@ -121,10 +122,11 @@ impl fmt::Display for ScriptContextError {
121122
"At least one satisfaction path in the Miniscript fragment contains \
122123
more than MAX_OPS_PER_SCRIPT opcodes."
123124
),
124-
ScriptContextError::MaxWitnessScriptSizeExceeded => write!(
125+
ScriptContextError::MaxWitnessScriptSizeExceeded { max, got } => write!(
125126
f,
126-
"The Miniscript corresponding Script would be larger than \
127-
MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."
127+
"The Miniscript corresponding Script cannot be larger than \
128+
{} bytes, but got {} bytes.",
129+
max, got
128130
),
129131
ScriptContextError::MaxRedeemScriptSizeExceeded => write!(
130132
f,
@@ -525,7 +527,10 @@ impl ScriptContext for Segwitv0 {
525527
match node_checked {
526528
Ok(_) => {
527529
if ms.ext.pk_cost > MAX_SCRIPT_SIZE {
528-
Err(ScriptContextError::MaxWitnessScriptSizeExceeded)
530+
Err(ScriptContextError::MaxWitnessScriptSizeExceeded {
531+
max: MAX_SCRIPT_SIZE,
532+
got: ms.ext.pk_cost,
533+
})
529534
} else {
530535
Ok(())
531536
}
@@ -550,7 +555,10 @@ impl ScriptContext for Segwitv0 {
550555
ms: &Miniscript<Pk, Self>,
551556
) -> Result<(), ScriptContextError> {
552557
if ms.ext.pk_cost > MAX_STANDARD_P2WSH_SCRIPT_SIZE {
553-
return Err(ScriptContextError::MaxWitnessScriptSizeExceeded);
558+
return Err(ScriptContextError::MaxWitnessScriptSizeExceeded {
559+
max: MAX_STANDARD_P2WSH_SCRIPT_SIZE,
560+
got: ms.ext.pk_cost,
561+
});
554562
}
555563
Ok(())
556564
}
@@ -644,7 +652,10 @@ impl ScriptContext for Tap {
644652
// some guarantees are not easy to satisfy because of knapsack
645653
// constraints
646654
if ms.ext.pk_cost as u64 > Weight::MAX_BLOCK.to_wu() {
647-
Err(ScriptContextError::MaxWitnessScriptSizeExceeded)
655+
Err(ScriptContextError::MaxWitnessScriptSizeExceeded {
656+
max: Weight::MAX_BLOCK.to_wu() as usize,
657+
got: ms.ext.pk_cost,
658+
})
648659
} else {
649660
Ok(())
650661
}

src/miniscript/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ mod tests {
16901690
);
16911691
assert_eq!(
16921692
segwit_multi_ms.unwrap_err().to_string(),
1693-
"The Miniscript corresponding Script would be larger than MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."
1693+
"The Miniscript corresponding Script cannot be larger than 3600 bytes, but got 4110 bytes."
16941694
);
16951695
assert_eq!(
16961696
bare_multi_ms.unwrap_err().to_string(),

0 commit comments

Comments
 (0)