Skip to content

Verify PSBT inputs rather than check for fields being empty - #25595

Merged
fanquake merged 2 commits into
bitcoin:masterfrom
instagibbs:verify_psbt_input
Oct 20, 2022
Merged

fanquake merged 2 commits into
bitcoin:masterfrom
instagibbs:verify_psbt_input

Conversation

@instagibbs

Copy link
Copy Markdown
Member

In a few keys spots, PSBT finality is checked by looking for non-empty witness data.

This complicates a couple things:

  1. Empty data can be valid in certain cases
  2. User may be passed bogus final data by a counterparty during PSBT work happening, and end up with incorrect signatures that they may not be able to check in other contexts if the UTXO doesn't exist yet in chain/mempool, timelocks, etc.

On the whole I think these heavier checks are worth it in case someone is actually assuming the signatures are correct if our API is saying so.

@fanquake
fanquake requested a review from achow101 July 12, 2022 16:10
@DrahtBot

DrahtBot commented Jul 12, 2022 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #21283 (Implement BIP 370 PSBTv2 by achow101)
  • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Comment thread src/psbt.cpp Resolved
@achow101

Copy link
Copy Markdown
Member

ACK 862236cf707e49174b0fa3413d42b3205d2ea3eb

Comment thread src/psbt.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is having the dummy checker correct? While this will check the script, it will also pass any signature as valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sounds like I need tests eh

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

suggested alternative?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To actually verify the signatures you need to use a TransactionSignatureChecker. The data that needs to be passed into that are all available in the callers to this function.

@instagibbs
instagibbs force-pushed the verify_psbt_input branch 2 times, most recently from 8b7f6a2 to 5cbd014 Compare October 12, 2022 17:11
@instagibbs

Copy link
Copy Markdown
Member Author

Fixed the tests, it now fails if signatures fail and passes when they're complete.

Comment thread src/psbt.cpp Outdated
Comment on lines 283 to 303

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The UTXO fetching has snuck back in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I went back and forth, the "extra code" to me seems to make the interface cleaner? Leaving as is if that's ok.

Comment thread src/psbt.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should probably be specific and use MutableTransactionSignatureChecker

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@instagibbs

Copy link
Copy Markdown
Member Author

@achow101 maybe a silent merge conflict on master?

@achow101

Copy link
Copy Markdown
Member

@achow101 maybe a silent merge conflict on master?

Yes: #24407 (comment)

@achow101

Copy link
Copy Markdown
Member

ACK 2e8798389aacdfcd42ca818459fb9c824af18da1

I'd like to see a test, but this could go in as is.

@instagibbs

Copy link
Copy Markdown
Member Author

Added a basic test that fails if parent commit is reverted

@achow101

Copy link
Copy Markdown
Member

ACK e133264

@fanquake
fanquake merged commit 2ac71d2 into bitcoin:master Oct 20, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants