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 22
33use core:: convert:: TryFrom ;
44
5+ use bitcoin:: constants:: MAX_SCRIPT_ELEMENT_SIZE ;
56use bitcoin:: hashes:: Hash ;
67use bitcoin:: script:: { self , PushBytes , ScriptBuf } ;
78use bitcoin:: PubkeyHash ;
@@ -49,12 +50,16 @@ pub(crate) fn witness_size<T: ItemSize>(wit: &[T]) -> usize {
4950
5051pub ( crate ) fn witness_to_scriptsig ( witness : & [ Vec < u8 > ] ) -> ScriptBuf {
5152 let mut b = script:: Builder :: new ( ) ;
52- for wit in witness {
53+ for ( i , wit) in witness. iter ( ) . enumerate ( ) {
5354 if let Ok ( n) = script:: read_scriptint ( wit) {
5455 b = b. push_int ( n) ;
5556 } 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" ) ;
5863 b = b. push_slice ( push)
5964 }
6065 }
You can’t perform that action at this time.
0 commit comments