Skip to content

fix(psbt): Validate previous non-witness UTXO txid in PSBT signing process#4714

Merged
sergei-boiko-trustwallet merged 4 commits intomasterfrom
fix/bitcoin-psbt-validate-prev-txid
Apr 1, 2026
Merged

fix(psbt): Validate previous non-witness UTXO txid in PSBT signing process#4714
sergei-boiko-trustwallet merged 4 commits intomasterfrom
fix/bitcoin-psbt-validate-prev-txid

Conversation

@sergei-boiko-trustwallet
Copy link
Copy Markdown
Contributor

Description

Compute non_witness_utxo.txid() and compare against self.utxo.previous_output.txid according to BIP-174.

How to test

Run Rust tests

Types of changes

Checklist

  • Create pull request as draft initially, unless its complete.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description.

If you're adding a new blockchain

  • I have read the guidelines for adding a new blockchain.

@sergei-boiko-trustwallet sergei-boiko-trustwallet requested a review from a team as a code owner March 31, 2026 14:48
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Binary size comparison

➡️ aarch64-apple-ios: 14.34 MB

➡️ aarch64-apple-ios-sim: 14.34 MB

➡️ aarch64-linux-android: 18.77 MB

➡️ armv7-linux-androideabi: 16.20 MB

➡️ wasm32-unknown-emscripten: 13.68 MB

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Bitcoin PSBT signing by validating that a PSBT input’s non_witness_utxo transaction txid() matches the referenced outpoint txid, as required by BIP-174, preventing signing with tampered previous-transaction data.

Changes:

  • Add non_witness_utxo.txid() vs previous_output.txid validation during PSBT input processing.
  • Add a regression test that tampers with non_witness_utxo output value and expects Error_invalid_utxo.
  • Expose bitcoin::psbt::Psbt from tw_bitcoin::modules::psbt_request and wire tw_bitcoin into tw_tests dev-dependencies.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/chains/tw_bitcoin/src/modules/psbt_request/utxo_psbt.rs Adds txid mismatch validation for non_witness_utxo and a unit test covering mixed witness/non-witness txid computation.
rust/chains/tw_bitcoin/src/modules/psbt_request/mod.rs Re-exports bitcoin::psbt::Psbt for easier use by external crates/tests.
rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/psbt.rs Adds an integration test asserting signing fails when non_witness_utxo contents are tampered.
rust/tw_tests/Cargo.toml Adds tw_bitcoin as a dev-dependency for test-only PSBT deserialization/mutation.
rust/Cargo.lock Updates lockfile for the new tw_bitcoin dependency in tw_tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergei-boiko-trustwallet sergei-boiko-trustwallet merged commit 39e659a into master Apr 1, 2026
15 checks passed
@sergei-boiko-trustwallet sergei-boiko-trustwallet deleted the fix/bitcoin-psbt-validate-prev-txid branch April 1, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants