@@ -62,6 +62,8 @@ pub enum ScriptContextError {
62
62
ImpossibleSatisfaction ,
63
63
/// No Multi Node in Taproot context
64
64
TaprootMultiDisabled ,
65
+ /// Stack size exceeded in script execution
66
+ StackSizeLimitExceeded ,
65
67
}
66
68
67
69
impl fmt:: Display for ScriptContextError {
@@ -119,6 +121,12 @@ impl fmt::Display for ScriptContextError {
119
121
ScriptContextError :: TaprootMultiDisabled => {
120
122
write ! ( f, "No Multi node in taproot context" )
121
123
}
124
+ ScriptContextError :: StackSizeLimitExceeded => {
125
+ write ! (
126
+ f,
127
+ "Stack limit can exceed in atleast one script path during script execution"
128
+ )
129
+ }
122
130
}
123
131
}
124
132
}
@@ -512,7 +520,7 @@ impl ScriptContext for Tap {
512
520
}
513
521
514
522
fn check_local_consensus_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
515
- _ms : & Miniscript < Pk , Ctx > ,
523
+ ms : & Miniscript < Pk , Ctx > ,
516
524
) -> Result < ( ) , ScriptContextError > {
517
525
// Taproot introduces the concept of sigops budget.
518
526
// In all possible valid miniscripts satisfy the given sigops constraint
@@ -521,8 +529,15 @@ impl ScriptContext for Tap {
521
529
// own unique signature. That is there is no way to re-use signatures for another
522
530
// checksig. Therefore, for each successfully executed checksig, we will have
523
531
// 64 bytes signature and thus sigops budget is always covered.
524
- // There is overall limit of consensus
525
532
// TODO: track height during execution
533
+ if let ( Some ( s) , Some ( h) ) = (
534
+ ms. ext . exec_stack_elem_count_sat ,
535
+ ms. ext . stack_elem_count_sat ,
536
+ ) {
537
+ if s + h > MAX_STACK_SIZE {
538
+ return Err ( ScriptContextError :: StackSizeLimitExceeded ) ;
539
+ }
540
+ }
526
541
Ok ( ( ) )
527
542
}
528
543
@@ -536,7 +551,6 @@ impl ScriptContext for Tap {
536
551
fn check_local_policy_validity < Pk : MiniscriptKey , Ctx : ScriptContext > (
537
552
_ms : & Miniscript < Pk , Ctx > ,
538
553
) -> Result < ( ) , ScriptContextError > {
539
- // TODO: check for policy execution.
540
554
Ok ( ( ) )
541
555
}
542
556
0 commit comments