@@ -4764,19 +4764,23 @@ static bool finalize_p2tr(struct wally_psbt_input *input)
47644764 return true;
47654765}
47664766
4767- static bool is_input_csv_expired (const struct wally_psbt_input * input , uint32_t blocks )
4767+ static bool is_input_csv_expired (const struct wally_psbt * psbt ,
4768+ const struct wally_psbt_input * input ,
4769+ size_t index , uint32_t blocks )
47684770{
4769- if (input -> sequence & ((1 << 31 ) | (1 << 22 )))
4771+ uint32_t seq = psbt -> version == PSBT_0 ? psbt -> tx -> inputs [index ].sequence : input -> sequence ;
4772+ if (seq & ((1u << 31u ) | (1u << 22u )))
47704773 return false; /* Locktime opt-out enabled, or time-based lock */
4774+
47714775 /* Note we don't mask out the locktime value, because we don't want to
47724776 * finalize inputs if a soft-fork we don't know about has changed the
47734777 * meaning of locktime extra bits in a way we don't understand.
47744778 */
4775- return blocks <= input -> sequence ;
4779+ return blocks <= seq ;
47764780}
47774781
47784782static bool finalize_csv2of2_1 (const struct wally_psbt * psbt ,
4779- struct wally_psbt_input * input ,
4783+ struct wally_psbt_input * input , size_t index ,
47804784 const unsigned char * out_script , size_t out_script_len ,
47814785 bool is_witness , bool is_p2sh , bool is_optimized )
47824786{
@@ -4793,7 +4797,7 @@ static bool finalize_csv2of2_1(const struct wally_psbt *psbt,
47934797 & blocks ) != WALLY_OK )
47944798 return false;
47954799
4796- is_expired = tx_version >= 2 && is_input_csv_expired (input , blocks );
4800+ is_expired = tx_version >= 2 && is_input_csv_expired (psbt , input , index , blocks );
47974801 is_expired_unoptimized = is_expired && !is_optimized ;
47984802
47994803 if (is_optimized ) {
@@ -4903,7 +4907,7 @@ int wally_psbt_finalize_input(struct wally_psbt *psbt, size_t index, uint32_t fl
49034907 break ;
49044908 case WALLY_SCRIPT_TYPE_CSV2OF2_1 :
49054909 case WALLY_SCRIPT_TYPE_CSV2OF2_1_OPT :
4906- if (!finalize_csv2of2_1 (psbt , input , out_script , out_script_len ,
4910+ if (!finalize_csv2of2_1 (psbt , input , index , out_script , out_script_len ,
49074911 is_witness , is_p2sh ,
49084912 type == WALLY_SCRIPT_TYPE_CSV2OF2_1_OPT ))
49094913 return WALLY_OK ;
0 commit comments