fix(bitcoin-psbt): Validate UTXO types for witness and non-witness scripts - #4749
Open
sergei-boiko-trustwallet wants to merge 2 commits into
Open
fix(bitcoin-psbt): Validate UTXO types for witness and non-witness scripts#4749sergei-boiko-trustwallet wants to merge 2 commits into
sergei-boiko-trustwallet wants to merge 2 commits into
Conversation
sergei-boiko-trustwallet
requested review from
a team and
BSCSecChef
as code owners
April 28, 2026 13:58
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens PSBT input validation in the Bitcoin signing flow by rejecting mismatches between the PSBT UTXO container type (witness_utxo vs non_witness_utxo) and the script type, and adds regression tests to ensure invalid PSBTs fail with Error_invalid_utxo.
Changes:
- Enforce
witness_utxovsnon_witness_utxoscript-type constraints inUtxoPsbt. - Add tests covering invalid script types for witness and non-witness UTXOs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rust/tw_tests/tests/chains/bitcoin/bitcoin_sign/psbt.rs | Adds negative tests ensuring mismatched UTXO/script types are rejected. |
| rust/chains/tw_bitcoin/src/modules/psbt_request/utxo_psbt.rs | Introduces script-type checks keyed off whether the PSBT input uses witness vs non-witness UTXO data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Binary size comparison➡️ aarch64-apple-ios: - 14.37 MB
+ 14.37 MB +1 KB➡️ aarch64-apple-ios-sim: - 14.38 MB
+ 14.38 MB +1 KB➡️ aarch64-linux-android: - 18.81 MB
+ 18.82 MB +1 KB➡️ armv7-linux-androideabi: - 16.24 MB
+ 16.24 MB +1 KB➡️ wasm32-unknown-emscripten: - 13.73 MB
+ 13.73 MB +1 KB |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
nikhil-gupta-tw
approved these changes
May 5, 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.
This pull request strengthens the validation logic for PSBT (Partially Signed Bitcoin Transactions) input types by enforcing stricter rules on which script types are allowed for witness and non-witness UTXOs. It also adds comprehensive tests to ensure these rules are correctly enforced and that invalid PSBTs are rejected with appropriate errors.
Validation logic improvements:
UtxoPsbtmethods to require that only P2WPKH script types are allowed for witness UTXOs, and only P2PK/P2PKH script types are allowed for non-witness UTXOs. Attempting to use an invalid script type for a given UTXO type now results in aSigningError::Error_invalid_utxoerror.Testing enhancements:
psbt.rsto verify that:These changes ensure the PSBT signing process is more robust and compliant with expected Bitcoin transaction standards.