From 834bd3dcc9bbcecd8603d85fc17ddb82f2d4ba65 Mon Sep 17 00:00:00 2001 From: ChrisCho-H Date: Thu, 17 Oct 2024 00:12:52 +0900 Subject: [PATCH] feat: add MaxBareScriptSizeExceeded err for bare consensus check --- src/miniscript/context.rs | 11 ++++++++++- src/miniscript/mod.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/miniscript/context.rs b/src/miniscript/context.rs index bb53ed67a..45b4a03a2 100644 --- a/src/miniscript/context.rs +++ b/src/miniscript/context.rs @@ -52,6 +52,9 @@ pub enum ScriptContextError { /// The Miniscript (under p2sh context) corresponding Script would be /// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes. MaxRedeemScriptSizeExceeded, + /// The Miniscript(under bare context) corresponding + /// Script would be larger than `MAX_SCRIPT_SIZE` bytes. + MaxBareScriptSizeExceeded, /// The policy rules of bitcoin core only permit Script size upto 1650 bytes MaxScriptSigSizeExceeded, /// Impossible to satisfy the miniscript under the current context @@ -80,6 +83,7 @@ impl error::Error for ScriptContextError { | MaxOpCountExceeded | MaxWitnessScriptSizeExceeded | MaxRedeemScriptSizeExceeded + | MaxBareScriptSizeExceeded | MaxScriptSigSizeExceeded | ImpossibleSatisfaction | TaprootMultiDisabled @@ -127,6 +131,11 @@ impl fmt::Display for ScriptContextError { "The Miniscript corresponding Script would be larger than \ MAX_SCRIPT_ELEMENT_SIZE bytes." ), + ScriptContextError::MaxBareScriptSizeExceeded => write!( + f, + "The Miniscript corresponding Script would be larger than \ + MAX_SCRIPT_SIZE bytes." + ), ScriptContextError::MaxScriptSigSizeExceeded => write!( f, "At least one satisfaction in Miniscript would be larger than \ @@ -740,7 +749,7 @@ impl ScriptContext for BareCtx { match node_checked { Ok(_) => { if ms.ext.pk_cost > MAX_SCRIPT_SIZE { - Err(ScriptContextError::MaxWitnessScriptSizeExceeded) + Err(ScriptContextError::MaxBareScriptSizeExceeded) } else { Ok(()) } diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 02829ac5f..79aa0a682 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -1694,7 +1694,7 @@ mod tests { ); assert_eq!( bare_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 MAX_SCRIPT_SIZE bytes." ); } }