@@ -195,8 +195,8 @@ pub trait ScriptContext:
195195 ms : & Miniscript < Pk , Ctx > ,
196196 ) -> Result < ( ) , ScriptContextError > {
197197 Self :: check_global_consensus_validity ( ms) ?;
198- Self :: check_global_consensus_validity ( ms) ?;
199- Self :: check_local_policy_validity ( ms) ?;
198+ Self :: check_global_policy_validity ( ms) ?;
199+ Self :: check_local_consensus_validity ( ms) ?;
200200 Self :: check_local_policy_validity ( ms) ?;
201201 Ok ( ( ) )
202202 }
@@ -277,26 +277,28 @@ impl ScriptContext for Legacy {
277277 fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
278278 ms : & Miniscript < Pk , Ctx > ,
279279 ) -> Result < ( ) , ScriptContextError > {
280- if let Some ( op_count) = ms. ext . ops_count_sat {
281- if op_count > MAX_OPS_PER_SCRIPT {
282- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
280+ match ms. ext . ops_count_sat {
281+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
282+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
283+ Err ( ScriptContextError :: MaxOpCountExceeded )
283284 }
285+ _ => Ok ( ( ) ) ,
284286 }
285- Ok ( ( ) )
286287 }
287288
288289 fn check_local_policy_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
289290 ms : & Miniscript < Pk , Ctx > ,
290291 ) -> Result < ( ) , ScriptContextError > {
291- if let Some ( size) = ms. max_satisfaction_size ( ) {
292- if size > MAX_SCRIPTSIG_SIZE {
293- return Err ( ScriptContextError :: MaxScriptSigSizeExceeded ) ;
294- }
295- }
296292 // Legacy scripts permit upto 1000 stack elements, 520 bytes consensus limits
297293 // on P2SH size, it is not possible to reach the 1000 elements limit and hence
298294 // we do not check it.
299- Ok ( ( ) )
295+ match ms. max_satisfaction_size ( ) {
296+ None => Err ( ScriptContextError :: MaxScriptSigSizeExceeded ) ,
297+ Some ( size) if size > MAX_SCRIPTSIG_SIZE => {
298+ Err ( ScriptContextError :: MaxScriptSigSizeExceeded )
299+ }
300+ _ => Ok ( ( ) ) ,
301+ }
300302 }
301303
302304 fn max_satisfaction_size < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -348,12 +350,13 @@ impl ScriptContext for Segwitv0 {
348350 fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
349351 ms : & Miniscript < Pk , Ctx > ,
350352 ) -> Result < ( ) , ScriptContextError > {
351- if let Some ( op_count) = ms. ext . ops_count_sat {
352- if op_count > MAX_OPS_PER_SCRIPT {
353- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
353+ match ms. ext . ops_count_sat {
354+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
355+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
356+ Err ( ScriptContextError :: MaxOpCountExceeded )
354357 }
358+ _ => Ok ( ( ) ) ,
355359 }
356- Ok ( ( ) )
357360 }
358361
359362 fn check_global_policy_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -371,12 +374,13 @@ impl ScriptContext for Segwitv0 {
371374 // We don't need to know if this is actually a p2wsh as the standard satisfaction for
372375 // other Segwitv0 defined programs all require (much) less than 100 elements.
373376 // The witness script item is accounted for in max_satisfaction_witness_elements().
374- if let Some ( max_witness_items) = ms. max_satisfaction_witness_elements ( ) {
375- if max_witness_items > MAX_STANDARD_P2WSH_STACK_ITEMS {
376- return Err ( ScriptContextError :: MaxWitnessItemssExceeded ) ;
377+ match ms. max_satisfaction_witness_elements ( ) {
378+ None => Err ( ScriptContextError :: MaxWitnessItemssExceeded ) ,
379+ Some ( max_witness_items) if max_witness_items > MAX_STANDARD_P2WSH_STACK_ITEMS => {
380+ Err ( ScriptContextError :: MaxWitnessItemssExceeded )
377381 }
382+ _ => Ok ( ( ) ) ,
378383 }
379- Ok ( ( ) )
380384 }
381385
382386 fn max_satisfaction_size < Pk : MiniscriptKey , Ctx : ScriptContext > (
@@ -417,12 +421,13 @@ impl ScriptContext for Bare {
417421 fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
418422 ms : & Miniscript < Pk , Ctx > ,
419423 ) -> Result < ( ) , ScriptContextError > {
420- if let Some ( op_count) = ms. ext . ops_count_sat {
421- if op_count > MAX_OPS_PER_SCRIPT {
422- return Err ( ScriptContextError :: MaxOpCountExceeded ) ;
424+ match ms. ext . ops_count_sat {
425+ None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
426+ Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
427+ Err ( ScriptContextError :: MaxOpCountExceeded )
423428 }
429+ _ => Ok ( ( ) ) ,
424430 }
425- Ok ( ( ) )
426431 }
427432
428433 fn other_top_level_checks < Pk : MiniscriptKey , Ctx : ScriptContext > (
0 commit comments