Skip to content

Conversation

achow101
Copy link
Member

When analyzing an unspendable PSBT, report that it is unspendable and exit analysis early.

Invalid PSBTs need to be re-created, so the next role is the
Creator (new PSBTRole). Additionally, we need to know what went
wrong so an error field was added to PSBTAnalysis.

A PSBTAnalysis indicating invalid will have empty everything,
next will be set to PSBTRole::CREATOR, and an error message.
@practicalswift
Copy link
Contributor

Concept ACK

Thanks for fixing this!

@Sjors
Copy link
Member

Sjors commented Nov 19, 2019

Concept ACK

@practicalswift
Copy link
Contributor

practicalswift commented Nov 19, 2019

Note to reviewers:

This is the issue (#17149 (comment)) fixed by this PR:

$ bitcoind &
$ bitcoin-cli analyzepsbt "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWAEHYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFv8/wADXYP/7//////8JxOh0LR2HAI8AAAAAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHEAABAACAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHENkMak8AAAAA"
bitcoind: consensus/tx_verify.cpp:130: unsigned int 
    GetP2SHSigOpCount(const CTransaction &, const CCoinsViewCache &): 
    Assertion `!coin.IsSpent()' failed.

@@ -416,5 +416,10 @@ def test_psbt_input_keys(psbt_input, keys):
analyzed = self.nodes[0].analyzepsbt(signed)
assert analyzed['inputs'][0]['has_utxo'] and analyzed['inputs'][0]['is_final'] and analyzed['next'] == 'extractor'

self.log.info("PSBT spending unspendable outputs should have error message and Creator as next")
analysis = self.nodes[0].analyzepsbt('cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWAEHYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFv8/wADXYP/7//////8JxOh0LR2HAI8AAAAAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHEAABAACAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHENkMak8AAAAA')
Copy link
Member

Choose a reason for hiding this comment

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

damnit you should have warned me this crashes Core, lol

Copy link
Member

Choose a reason for hiding this comment

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

      "final_scriptSig": {
        "asm": "1050369 0 0 0 OP_LEFT",
        "hex": "030107100001000080"
      }

why does this PSBT have scriptsigs for OP_RETURN inputs? Can't this PSBT be generated dynamically for better readability? Even if not, we should assert some things using decodepsbt to make sure we know the scriptpubkeys.

Copy link
Contributor

Choose a reason for hiding this comment

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

The PSBT was created by a coverage-guided fuzzer using the fuzzing harness that I added in PR #17136 ("tests: Add fuzzing harness for various PSBT related functions"). The only post-processing done was a test-case minimisation run :)

@instagibbs
Copy link
Member

@practicalswift 2 minutes too late bro 😂

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 19, 2019

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #17211 (Allow fundrawtransaction and walletcreatefundedpsbt to take external inputs by achow101)
  • #17156 (psbt: check that various indexes and amounts are within bounds 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.

@Sjors
Copy link
Member

Sjors commented Nov 20, 2019

ACK 773d457

The new creator role and error field are release note worthy.

This should be back-ported.

@Sjors Sjors mentioned this pull request Nov 23, 2019
@darosior
Copy link
Member

The removal of the input field in case of error would break the API, wouldn't be better to push an empty array instead ?

@achow101
Copy link
Member Author

I don't think this really breaks the api since this error condition would cause a crash rather than return any sort of result previously.

@instagibbs
Copy link
Member

After some thought ACK 773d457

maflcko pushed a commit that referenced this pull request Dec 10, 2019
773d457 Mark PSBTs spending unspendable outputs as invalid in analysis (Andrew Chow)
638e40c Have a PSBTAnalysis state that indicates invalid PSBT (Andrew Chow)

Pull request description:

  When analyzing an unspendable PSBT, report that it is unspendable and exit analysis early.

ACKs for top commit:
  Sjors:
    ACK 773d457
  instagibbs:
    After some thought ACK 773d457

Tree-SHA512: 99b0cb2fa1ea37593fc65a20effe881639d69ddeeecf5197bc87bc7f2220cbeb40f1d429d517e4d27f2e9fb563a00cd845d2b4b1ce05246a75a6cb56fb9b0ba5
@maflcko maflcko merged commit 773d457 into bitcoin:master Dec 10, 2019
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 10, 2019
773d457 Mark PSBTs spending unspendable outputs as invalid in analysis (Andrew Chow)
638e40c Have a PSBTAnalysis state that indicates invalid PSBT (Andrew Chow)

Pull request description:

  When analyzing an unspendable PSBT, report that it is unspendable and exit analysis early.

ACKs for top commit:
  Sjors:
    ACK 773d457
  instagibbs:
    After some thought ACK bitcoin@773d457

Tree-SHA512: 99b0cb2fa1ea37593fc65a20effe881639d69ddeeecf5197bc87bc7f2220cbeb40f1d429d517e4d27f2e9fb563a00cd845d2b4b1ce05246a75a6cb56fb9b0ba5
maflcko pushed a commit that referenced this pull request Dec 11, 2019
7e8b4de rpc: add missing newline in analyzepsbt rpcresult (Jon Atack)

Pull request description:

  follow-up to 638e40c in #17524

  before
  ```
    "error" : "error"               (string) Error message if there is one}
  ```
  after
  ```
    "error" : "error"               (string) Error message if there is one
  }
  ```

ACKs for top commit:
  practicalswift:
    ACK 7e8b4de
  promag:
    ACK 7e8b4de.
  emilengler:
    ACK 7e8b4de

Tree-SHA512: 4cdd365e39d15b7925ea277b7ff3e9bfdc22f5845aa41ca547343b4dabdf319579843a1c7f11fb0edd6abbc31bae2ec96236b83e84f8872bd662848723725e4c
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jan 3, 2020
Invalid PSBTs need to be re-created, so the next role is the
Creator (new PSBTRole). Additionally, we need to know what went
wrong so an error field was added to PSBTAnalysis.

A PSBTAnalysis indicating invalid will have empty everything,
next will be set to PSBTRole::CREATOR, and an error message.

Github-Pull: bitcoin#17524
Rebased-From: 638e40c
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Jan 3, 2020
fanquake added a commit that referenced this pull request Jan 4, 2020
ca5f8de Mark PSBTs spending unspendable outputs as invalid in analysis (Andrew Chow)
5515833 Have a PSBTAnalysis state that indicates invalid PSBT (Andrew Chow)

Pull request description:

  Backport of #17524

ACKs for top commit:
  achow101:
    ACK ca5f8de

Tree-SHA512: b5f2b951beb9477ac3176a0aade845654d2108ca3a9fbc72097ba4b4797df5419053d6b489bbaa03be08cb8cfdc37a83db8b7642ffa52d42b7aa8ea14aff39cc
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Feb 13, 2020
- [0.19] wallet: Reset reused transactions cache bitcoin#18083
- 0.19: Backports bitcoin#17792
- psbt: handle unspendable psbts bitcoin#17524
- qt: Fix comparison function signature bitcoin#17634
- psbt: check that various indexes and amounts are within bounds bitcoin#17156
- [0.19] psbt: check that various indexes and amounts are within bounds bitcoin#18079
- [0.19] Final backports for 0.19.1 bitcoin#17988
- Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash bitcoin#17924
- qt: Fix deprecated QCharRef usage bitcoin#18101
- gui: Throttle GUI update pace when -reindex bitcoin#18121
- gui: Fix race in WalletModel::pollBalanceChanged bitcoin#18123
- gui: Fix unintialized WalletView::progressDialog bitcoin#18062
- Bugfix: GUI: Hide the HD/encrypt icons earlier so they get re-shown if another wallet is open bitcoin#18007
- bug-fix macos: give free bytes to F_PREALLOCATE bitcoin#17887
- test: add missing #include to fix compiler errors bitcoin#17980
- zmq: Fix due to invalid argument and multiple notifiers bitcoin#17445
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 23, 2020
Summary:
 * Have a PSBTAnalysis state that indicates invalid PSBT

Invalid PSBTs need to be re-created, so the next role is the
Creator (new PSBTRole). Additionally, we need to know what went
wrong so an error field was added to PSBTAnalysis.

A PSBTAnalysis indicating invalid will have empty everything,
next will be set to PSBTRole::CREATOR, and an error message.

 * Mark PSBTs spending unspendable outputs as invalid in analysis

This is a backport of Core [[bitcoin/bitcoin#17524 | PR17524]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D8065
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
773d457 Mark PSBTs spending unspendable outputs as invalid in analysis (Andrew Chow)
638e40c Have a PSBTAnalysis state that indicates invalid PSBT (Andrew Chow)

Pull request description:

  When analyzing an unspendable PSBT, report that it is unspendable and exit analysis early.

ACKs for top commit:
  Sjors:
    ACK 773d457
  instagibbs:
    After some thought ACK bitcoin@773d457

Tree-SHA512: 99b0cb2fa1ea37593fc65a20effe881639d69ddeeecf5197bc87bc7f2220cbeb40f1d429d517e4d27f2e9fb563a00cd845d2b4b1ce05246a75a6cb56fb9b0ba5
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants