fix(psbt): Validate previous non-witness UTXO txid in PSBT signing process#4714
Merged
sergei-boiko-trustwallet merged 4 commits intomasterfrom Apr 1, 2026
Merged
Conversation
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 |
Contributor
There was a problem hiding this comment.
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()vsprevious_output.txidvalidation during PSBT input processing. - Add a regression test that tampers with
non_witness_utxooutput value and expectsError_invalid_utxo. - Expose
bitcoin::psbt::Psbtfromtw_bitcoin::modules::psbt_requestand wiretw_bitcoinintotw_testsdev-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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
davidkulman-tw
approved these changes
Apr 1, 2026
nikhil-gupta-tw
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Compute
non_witness_utxo.txid()and compare againstself.utxo.previous_output.txidaccording to BIP-174.How to test
Run Rust tests
Types of changes
Checklist
If you're adding a new blockchain