Validate PartiallySignedTransaction after decoding#2093
Open
oliv3rdrt wants to merge 1 commit into
Open
Conversation
Wallet RPC methods and CLI commands accept a hex-encoded PartiallySignedTransaction and decode it with SCALE, which bypasses the invariants that PartiallySignedTransaction::new enforces. A malformed but still decodable transaction could then make the wallet panic, e.g. on a witness/input count mismatch. Call ensure_consistency right after decoding in GenericTransaction::decode_from_untagged_bytes, the shared decode path used by account_sign_raw_transaction and transaction_inspect, so such input is rejected with a proper error instead. The Basic level is used so that transactions that are still being assembled are not rejected.
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.
Problem
Wallet RPC methods and CLI commands that accept a
PartiallySignedTransactiondecode it from bytes with SCALE, which skips the checks thatPartiallySignedTransaction::newperforms. A malformed but still decodable transaction (for example one whose witness count does not match the number of inputs) can therefore reach the wallet and make it panic instead of returning an error.Fix
Call
ensure_consistencyimmediately after decoding inGenericTransaction::decode_from_untagged_bytes, the shared path used byaccount_sign_raw_transactionandtransaction_inspect(and the CLI commands that call them). A newGenericTransactionError::InconsistentPartiallySignedTransactionvariant is returned on failure.The
Basicconsistency level is used on purpose: it enforces the structural invariants that prevent the panics, while still accepting partial transactions that are legitimately incomplete during signing. UsingWithAdditionalInfohere would reject those and also break the existing decode test.Tests
Added a unit test that feeds a hand-encoded, inconsistent
PartiallySignedTransactionthrough the decode path and asserts it is rejected. The existing tests still pass and clippy is clean for the changed crate.Closes #2069