diff --git a/src/miniscript/context.rs b/src/miniscript/context.rs index 45b4a03a2..b0cba664f 100644 --- a/src/miniscript/context.rs +++ b/src/miniscript/context.rs @@ -48,7 +48,7 @@ pub enum ScriptContextError { MaxOpCountExceeded, /// The Miniscript(under segwit context) corresponding /// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE` bytes. - MaxWitnessScriptSizeExceeded, + MaxWitnessScriptSizeExceeded(usize), /// The Miniscript (under p2sh context) corresponding Script would be /// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes. MaxRedeemScriptSizeExceeded, @@ -81,7 +81,7 @@ impl error::Error for ScriptContextError { | UncompressedKeysNotAllowed | MaxWitnessItemssExceeded { .. } | MaxOpCountExceeded - | MaxWitnessScriptSizeExceeded + | MaxWitnessScriptSizeExceeded(_) | MaxRedeemScriptSizeExceeded | MaxBareScriptSizeExceeded | MaxScriptSigSizeExceeded @@ -121,10 +121,11 @@ impl fmt::Display for ScriptContextError { "At least one satisfaction path in the Miniscript fragment contains \ more than MAX_OPS_PER_SCRIPT opcodes." ), - ScriptContextError::MaxWitnessScriptSizeExceeded => write!( + ScriptContextError::MaxWitnessScriptSizeExceeded(max_size) => write!( f, "The Miniscript corresponding Script would be larger than \ - MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes." + {} bytes.", + max_size ), ScriptContextError::MaxRedeemScriptSizeExceeded => write!( f, @@ -525,7 +526,7 @@ impl ScriptContext for Segwitv0 { match node_checked { Ok(_) => { if ms.ext.pk_cost > MAX_SCRIPT_SIZE { - Err(ScriptContextError::MaxWitnessScriptSizeExceeded) + Err(ScriptContextError::MaxWitnessScriptSizeExceeded(MAX_SCRIPT_SIZE)) } else { Ok(()) } @@ -550,7 +551,9 @@ impl ScriptContext for Segwitv0 { ms: &Miniscript, ) -> Result<(), ScriptContextError> { if ms.ext.pk_cost > MAX_STANDARD_P2WSH_SCRIPT_SIZE { - return Err(ScriptContextError::MaxWitnessScriptSizeExceeded); + return Err(ScriptContextError::MaxWitnessScriptSizeExceeded( + MAX_STANDARD_P2WSH_SCRIPT_SIZE, + )); } Ok(()) } @@ -644,7 +647,9 @@ impl ScriptContext for Tap { // some guarantees are not easy to satisfy because of knapsack // constraints if ms.ext.pk_cost as u64 > Weight::MAX_BLOCK.to_wu() { - Err(ScriptContextError::MaxWitnessScriptSizeExceeded) + Err(ScriptContextError::MaxWitnessScriptSizeExceeded( + Weight::MAX_BLOCK.to_wu() as usize + )) } else { Ok(()) } diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 79aa0a682..e608cb990 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -1690,7 +1690,7 @@ mod tests { ); assert_eq!( segwit_multi_ms.unwrap_err().to_string(), - "The Miniscript corresponding Script would be larger than MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes." + "The Miniscript corresponding Script would be larger than 3600 bytes." ); assert_eq!( bare_multi_ms.unwrap_err().to_string(),