Skip to content

Commit

Permalink
Merge #1790: fix(wallet): improve safety on finaize psbt
Browse files Browse the repository at this point in the history
e8a9638 fix(wallet): improve safety on finaize psbt (f3r10)

Pull request description:

  <!-- You can erase any parts of this template not applicable to your Pull Request. -->
  fix #1711
  ### Description

  This PR replaces how currently potentially bug-prone PSBT's input access is done using a more carefully approach.

  ### Notes to the reviewers

  <!-- In this section you can include notes directed to the reviewers, like explaining why some parts
  of the PR were done in a specific way -->

  ### Changelog notice

  <!-- Notice the release manager should include in the release tag message changelog -->
  <!-- See https://keepachangelog.com/en/1.0.0/ for examples -->

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  rustaceanrob:
    ACK e8a9638
  evanlinjin:
    ACK e8a9638

Tree-SHA512: ad25a9d5d47cbdc41b11ea4ce57b30c6855ea391c0f053dffbee0c3dd1b06c6b227e056ede69eee6026e8b72915fe06c366d0a4e2fd6a1d454fc8dafed80b74a
  • Loading branch information
evanlinjin committed Jan 10, 2025
2 parents abc3056 + e8a9638 commit b2876d8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,8 +1901,11 @@ impl Wallet {
Ok(_) => {
// Set the UTXO fields, final script_sig and witness
// and clear everything else.
let original = mem::take(&mut psbt.inputs[n]);
let psbt_input = &mut psbt.inputs[n];
let psbt_input = psbt
.inputs
.get_mut(n)
.ok_or(SignerError::InputIndexOutOfRange)?;
let original = mem::take(psbt_input);
psbt_input.non_witness_utxo = original.non_witness_utxo;
psbt_input.witness_utxo = original.witness_utxo;
if !tmp_input.script_sig.is_empty() {
Expand Down

0 comments on commit b2876d8

Please sign in to comment.