@@ -45,19 +45,19 @@ pub enum ScriptContextError {
45
45
MaxWitnessItemsExceeded { actual : usize , limit : usize } ,
46
46
/// At least one satisfaction path in the Miniscript fragment contains more
47
47
/// than `MAX_OPS_PER_SCRIPT`(201) opcodes.
48
- MaxOpCountExceeded ,
48
+ MaxOpCountExceeded { actual : usize , limit : usize } ,
49
49
/// The Miniscript(under segwit context) corresponding
50
50
/// Script would be larger than `MAX_STANDARD_P2WSH_SCRIPT_SIZE`,
51
51
/// `MAX_SCRIPT_SIZE` or `MAX_BLOCK`(`Tap`) bytes.
52
52
MaxWitnessScriptSizeExceeded { max : usize , got : usize } ,
53
53
/// The Miniscript (under p2sh context) corresponding Script would be
54
54
/// larger than `MAX_SCRIPT_ELEMENT_SIZE` bytes.
55
- MaxRedeemScriptSizeExceeded ,
55
+ MaxRedeemScriptSizeExceeded { max : usize , got : usize } ,
56
56
/// The Miniscript(under bare context) corresponding
57
57
/// Script would be larger than `MAX_SCRIPT_SIZE` bytes.
58
- MaxBareScriptSizeExceeded ,
58
+ MaxBareScriptSizeExceeded { max : usize , got : usize } ,
59
59
/// The policy rules of bitcoin core only permit Script size upto 1650 bytes
60
- MaxScriptSigSizeExceeded ,
60
+ MaxScriptSigSizeExceeded { actual : usize , limit : usize } ,
61
61
/// Impossible to satisfy the miniscript under the current context
62
62
ImpossibleSatisfaction ,
63
63
/// No Multi Node in Taproot context
@@ -81,11 +81,11 @@ impl error::Error for ScriptContextError {
81
81
| XOnlyKeysNotAllowed ( _, _)
82
82
| UncompressedKeysNotAllowed
83
83
| MaxWitnessItemsExceeded { .. }
84
- | MaxOpCountExceeded
84
+ | MaxOpCountExceeded { .. }
85
85
| MaxWitnessScriptSizeExceeded { .. }
86
- | MaxRedeemScriptSizeExceeded
87
- | MaxBareScriptSizeExceeded
88
- | MaxScriptSigSizeExceeded
86
+ | MaxRedeemScriptSizeExceeded { .. }
87
+ | MaxBareScriptSizeExceeded { .. }
88
+ | MaxScriptSigSizeExceeded { .. }
89
89
| ImpossibleSatisfaction
90
90
| TaprootMultiDisabled
91
91
| StackSizeLimitExceeded { .. }
@@ -113,35 +113,39 @@ impl fmt::Display for ScriptContextError {
113
113
}
114
114
ScriptContextError :: MaxWitnessItemsExceeded { actual, limit } => write ! (
115
115
f,
116
- "At least one spending path in the Miniscript fragment has {} more \
117
- witness items than limit {}.",
116
+ "At least one satisfaction path in the Miniscript fragment has {} witness items \
117
+ ( limit: {}) .",
118
118
actual, limit
119
119
) ,
120
- ScriptContextError :: MaxOpCountExceeded => write ! (
120
+ ScriptContextError :: MaxOpCountExceeded { actual , limit } => write ! (
121
121
f,
122
- "At least one satisfaction path in the Miniscript fragment contains \
123
- more than MAX_OPS_PER_SCRIPT opcodes."
122
+ "At least one satisfaction path in the Miniscript fragment contains {} opcodes \
123
+ (limit: {}).",
124
+ actual, limit
124
125
) ,
125
126
ScriptContextError :: MaxWitnessScriptSizeExceeded { max, got } => write ! (
126
127
f,
127
128
"The Miniscript corresponding Script cannot be larger than \
128
- {} bytes, but got {} bytes.",
129
+ {} bytes, but got {} bytes.",
129
130
max, got
130
131
) ,
131
- ScriptContextError :: MaxRedeemScriptSizeExceeded => write ! (
132
+ ScriptContextError :: MaxRedeemScriptSizeExceeded { max , got } => write ! (
132
133
f,
133
- "The Miniscript corresponding Script would be larger than \
134
- MAX_SCRIPT_ELEMENT_SIZE bytes."
134
+ "The Miniscript corresponding Script cannot be larger than \
135
+ {} bytes, but got {} bytes.",
136
+ max, got
135
137
) ,
136
- ScriptContextError :: MaxBareScriptSizeExceeded => write ! (
138
+ ScriptContextError :: MaxBareScriptSizeExceeded { max , got } => write ! (
137
139
f,
138
- "The Miniscript corresponding Script would be larger than \
139
- MAX_SCRIPT_SIZE bytes."
140
+ "The Miniscript corresponding Script cannot be larger than \
141
+ {} bytes, but got {} bytes.",
142
+ max, got
140
143
) ,
141
- ScriptContextError :: MaxScriptSigSizeExceeded => write ! (
144
+ ScriptContextError :: MaxScriptSigSizeExceeded { actual , limit } => write ! (
142
145
f,
143
- "At least one satisfaction in Miniscript would be larger than \
144
- MAX_SCRIPTSIG_SIZE scriptsig"
146
+ "At least one satisfaction path in the Miniscript fragment has {} bytes \
147
+ (limit: {}).",
148
+ actual, limit
145
149
) ,
146
150
ScriptContextError :: ImpossibleSatisfaction => {
147
151
write ! ( f, "Impossible to satisfy Miniscript under the current context" )
@@ -396,8 +400,12 @@ impl ScriptContext for Legacy {
396
400
fn check_witness ( witness : & [ Vec < u8 > ] ) -> Result < ( ) , ScriptContextError > {
397
401
// In future, we could avoid by having a function to count only
398
402
// len of script instead of converting it.
399
- if witness_to_scriptsig ( witness) . len ( ) > MAX_SCRIPTSIG_SIZE {
400
- return Err ( ScriptContextError :: MaxScriptSigSizeExceeded ) ;
403
+ let script_sig = witness_to_scriptsig ( witness) ;
404
+ if script_sig. len ( ) > MAX_SCRIPTSIG_SIZE {
405
+ return Err ( ScriptContextError :: MaxScriptSigSizeExceeded {
406
+ actual : script_sig. len ( ) ,
407
+ limit : MAX_SCRIPTSIG_SIZE ,
408
+ } ) ;
401
409
}
402
410
Ok ( ( ) )
403
411
}
@@ -421,7 +429,10 @@ impl ScriptContext for Legacy {
421
429
match node_checked {
422
430
Ok ( _) => {
423
431
if ms. ext . pk_cost > MAX_SCRIPT_ELEMENT_SIZE {
424
- Err ( ScriptContextError :: MaxRedeemScriptSizeExceeded )
432
+ Err ( ScriptContextError :: MaxRedeemScriptSizeExceeded {
433
+ max : MAX_SCRIPT_ELEMENT_SIZE ,
434
+ got : ms. ext . pk_cost ,
435
+ } )
425
436
} else {
426
437
Ok ( ( ) )
427
438
}
@@ -434,9 +445,12 @@ impl ScriptContext for Legacy {
434
445
ms : & Miniscript < Pk , Self > ,
435
446
) -> Result < ( ) , ScriptContextError > {
436
447
match ms. ext . ops . op_count ( ) {
437
- None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
448
+ None => Err ( ScriptContextError :: ImpossibleSatisfaction ) ,
438
449
Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
439
- Err ( ScriptContextError :: MaxOpCountExceeded )
450
+ Err ( ScriptContextError :: MaxOpCountExceeded {
451
+ actual : op_count,
452
+ limit : MAX_OPS_PER_SCRIPT ,
453
+ } )
440
454
}
441
455
_ => Ok ( ( ) ) ,
442
456
}
@@ -451,7 +465,10 @@ impl ScriptContext for Legacy {
451
465
match ms. max_satisfaction_size ( ) {
452
466
Err ( _e) => Err ( ScriptContextError :: ImpossibleSatisfaction ) ,
453
467
Ok ( size) if size > MAX_SCRIPTSIG_SIZE => {
454
- Err ( ScriptContextError :: MaxScriptSigSizeExceeded )
468
+ Err ( ScriptContextError :: MaxScriptSigSizeExceeded {
469
+ actual : size,
470
+ limit : MAX_SCRIPTSIG_SIZE ,
471
+ } )
455
472
}
456
473
_ => Ok ( ( ) ) ,
457
474
}
@@ -543,9 +560,12 @@ impl ScriptContext for Segwitv0 {
543
560
ms : & Miniscript < Pk , Self > ,
544
561
) -> Result < ( ) , ScriptContextError > {
545
562
match ms. ext . ops . op_count ( ) {
546
- None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
563
+ None => Err ( ScriptContextError :: ImpossibleSatisfaction ) ,
547
564
Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
548
- Err ( ScriptContextError :: MaxOpCountExceeded )
565
+ Err ( ScriptContextError :: MaxOpCountExceeded {
566
+ actual : op_count,
567
+ limit : MAX_OPS_PER_SCRIPT ,
568
+ } )
549
569
}
550
570
_ => Ok ( ( ) ) ,
551
571
}
@@ -760,7 +780,10 @@ impl ScriptContext for BareCtx {
760
780
match node_checked {
761
781
Ok ( _) => {
762
782
if ms. ext . pk_cost > MAX_SCRIPT_SIZE {
763
- Err ( ScriptContextError :: MaxBareScriptSizeExceeded )
783
+ Err ( ScriptContextError :: MaxBareScriptSizeExceeded {
784
+ max : MAX_SCRIPT_SIZE ,
785
+ got : ms. ext . pk_cost ,
786
+ } )
764
787
} else {
765
788
Ok ( ( ) )
766
789
}
@@ -773,9 +796,12 @@ impl ScriptContext for BareCtx {
773
796
ms : & Miniscript < Pk , Self > ,
774
797
) -> Result < ( ) , ScriptContextError > {
775
798
match ms. ext . ops . op_count ( ) {
776
- None => Err ( ScriptContextError :: MaxOpCountExceeded ) ,
799
+ None => Err ( ScriptContextError :: ImpossibleSatisfaction ) ,
777
800
Some ( op_count) if op_count > MAX_OPS_PER_SCRIPT => {
778
- Err ( ScriptContextError :: MaxOpCountExceeded )
801
+ Err ( ScriptContextError :: MaxOpCountExceeded {
802
+ actual : op_count,
803
+ limit : MAX_OPS_PER_SCRIPT ,
804
+ } )
779
805
}
780
806
_ => Ok ( ( ) ) ,
781
807
}
0 commit comments