Skip to content

Commit aa1769c

Browse files
committed
Merge #568: psbt: Rewrite input replacement to avoid forgetting fields
c50bdf8 psbt: Rewrite input replacement to avoid forgetting fields (Steven Roose) Pull request description: The way it was written seemed very prone to forgetting fields if new ones would be added. Like this it just keeps the required fields and all the rest is set to `Default::default()`. ACKs for top commit: sanket1729: utACK c50bdf8 apoelstra: ACK c50bdf8 Tree-SHA512: 80bbd74ec6ed5e72786400a3ef1ca0330047423ca881efc0203f499b1f0aa544d9d2cc0743ecc03273b2ca2949c196fa7a94c8c965439db8993a9f69113b10fd
2 parents 9cf6e9d + c50bdf8 commit aa1769c

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/psbt/finalizer.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//! `https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki`
99
//!
1010
11+
use core::mem;
12+
1113
use bitcoin::hashes::hash160;
1214
use bitcoin::key::XOnlyPublicKey;
1315
use bitcoin::secp256k1::{self, Secp256k1};
@@ -415,8 +417,10 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
415417
// Now mutate the psbt input. Note that we cannot error after this point.
416418
// If the input is mutated, it means that the finalization succeeded.
417419
{
420+
let original = mem::replace(&mut psbt.inputs[index], Default::default());
418421
let input = &mut psbt.inputs[index];
419-
//Fill in the satisfactions
422+
input.non_witness_utxo = original.non_witness_utxo;
423+
input.witness_utxo = original.witness_utxo;
420424
input.final_script_sig = if script_sig.is_empty() {
421425
None
422426
} else {
@@ -427,25 +431,6 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
427431
} else {
428432
Some(witness)
429433
};
430-
//reset everything
431-
input.partial_sigs.clear(); // 0x02
432-
input.sighash_type = None; // 0x03
433-
input.redeem_script = None; // 0x04
434-
input.witness_script = None; // 0x05
435-
input.bip32_derivation.clear(); // 0x05
436-
// finalized witness 0x06 and 0x07 are not clear
437-
// 0x09 Proof of reserves not yet supported
438-
input.ripemd160_preimages.clear(); // 0x0a
439-
input.sha256_preimages.clear(); // 0x0b
440-
input.hash160_preimages.clear(); // 0x0c
441-
input.hash256_preimages.clear(); // 0x0d
442-
// psbt v2 fields till 0x012 not supported
443-
input.tap_key_sig = None; // 0x013
444-
input.tap_script_sigs.clear(); // 0x014
445-
input.tap_scripts.clear(); // 0x015
446-
input.tap_key_origins.clear(); // 0x16
447-
input.tap_internal_key = None; // x017
448-
input.tap_merkle_root = None; // 0x018
449434
}
450435

451436
Ok(())

0 commit comments

Comments
 (0)