Skip to content

BIP375: check SegWit versions in non-witness UTXOs - #2310

Open
zjubiology wants to merge 1 commit into
bitcoin:masterfrom
zjubiology:master
Open

zjubiology wants to merge 1 commit into
bitcoin:masterfrom
zjubiology:master

Conversation

@zjubiology

Copy link
Copy Markdown

BIP375 requires constructors and signers to reject PSBTs that combine silent payment outputs with inputs spending SegWit v2+ outputs.

The reference validator currently performs this check only when the prevout is provided through PSBT_IN_WITNESS_UTXO. BIP174 also permits SegWit inputs to provide the full previous transaction through PSBT_IN_NON_WITNESS_UTXO, so an input containing only that field can currently bypass the SegWit-version check.

Reuse the existing _script_pubkey_from_psbt_input() helper when validating input eligibility. This extracts the referenced scriptPubKey from either UTXO field.

Also add an invalid test vector containing:

  • a silent payment output;
  • a SegWit v2 prevout supplied only through PSBT_IN_NON_WITNESS_UTXO;
  • a matching previous transaction ID and output index.

yenimillet835-crypto

This comment was marked as low quality.

@zjubiology

Copy link
Copy Markdown
Author

@achow101 @andrewtoth Could you please take a look when you have a chance? Thanks!

@fametrano fametrano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The validator change holds: at ea1192c, master (927b6de) accepts the new vector under input_eligibility, this branch rejects it with "Input 0 uses segwit version > 1 with silent payments", and all 43 vectors pass.

The vector's PSBT_IN_PREVIOUS_TXID is byte-reversed. The field holds 9630266b…0c73c9; the double-SHA256 of the PSBT_IN_NON_WITNESS_UTXO transaction is c9730c1b…263096. BIP 174 requires the two to match ("its hash must match the hash specified in the prevout"), and the six existing vectors with a non-witness UTXO store the hash as computed, so a parser that checks this rejects the PSBT for the wrong reason. Reversing the 32 bytes of PSBT_IN_PREVIOUS_TXID, and of prevout_txid in supplementary to match the other vectors, fixes it.

Comment thread bip-0375/bip375_test_vectors.json Outdated
Comment thread bip-0375/bip375_test_vectors.json Outdated
Signed-off-by: zjubiology <zjubiology@outlook.com>
@fametrano

Copy link
Copy Markdown
Contributor

ACK 242bfbe

The new vector's PSBT_IN_PREVIOUS_TXID now matches its non-witness UTXO, the test runner passes 43/43, and the vector is still rejected for the segwit version.

@zjubiology

Copy link
Copy Markdown
Author

ACK 242bfbe

The new vector's PSBT_IN_PREVIOUS_TXID now matches its non-witness UTXO, the test runner passes 43/43, and the vector is still rejected for the segwit version.

Thanks for the review and ACK!

@zjubiology

Copy link
Copy Markdown
Author

@fametrano Thanks for your review! If there's anything need I to do, please feel free to let me know.

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.

3 participants