File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use core:: convert:: TryFrom ;
4
4
5
+ use bitcoin:: constants:: MAX_SCRIPT_ELEMENT_SIZE ;
5
6
use bitcoin:: hashes:: Hash ;
6
7
use bitcoin:: script:: { self , PushBytes , ScriptBuf } ;
7
8
use bitcoin:: PubkeyHash ;
@@ -49,12 +50,16 @@ pub(crate) fn witness_size<T: ItemSize>(wit: &[T]) -> usize {
49
50
50
51
pub ( crate ) fn witness_to_scriptsig ( witness : & [ Vec < u8 > ] ) -> ScriptBuf {
51
52
let mut b = script:: Builder :: new ( ) ;
52
- for wit in witness {
53
+ for ( i , wit) in witness. iter ( ) . enumerate ( ) {
53
54
if let Ok ( n) = script:: read_scriptint ( wit) {
54
55
b = b. push_int ( n) ;
55
56
} else {
56
- let push = <& PushBytes >:: try_from ( wit. as_slice ( ) )
57
- . expect ( "All pushes in miniscript are <73 bytes" ) ;
57
+ if i != witness. len ( ) - 1 {
58
+ assert ! ( wit. len( ) < 73 , "All pushes in miniscript are < 73 bytes" ) ;
59
+ } else {
60
+ assert ! ( wit. len( ) <= MAX_SCRIPT_ELEMENT_SIZE , "P2SH redeem script is <= 520 bytes" ) ;
61
+ }
62
+ let push = <& PushBytes >:: try_from ( wit. as_slice ( ) ) . expect ( "checked above" ) ;
58
63
b = b. push_slice ( push)
59
64
}
60
65
}
You can’t perform that action at this time.
0 commit comments