{
 "number": 36569,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36569",
 "title": "psbt: analyzepsbt reports an error when outputs exceed inputs",
 "author": "Ravan002",
 "author_association": "FIRST_TIME_CONTRIBUTOR",
 "created_at": "2026-10-18T20:03:23Z",
 "updated_at": "2026-10-20T13:09:10Z",
 "description_hash": "06f7731c920914be",
 "age_days": 14,
 "draft": false,
 "labels": [
  "PSBT"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "82629330135ba7df7ef5fc061ffadca3288043b1",
 "head_ref": "analyzepsbt-outputs-exceed-inputs",
 "head_repo": "Ravan002/bitcoin",
 "head_history": [],
 "additions": 13,
 "deletions": 0,
 "changed_files": 2,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "clean",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {
    "ack": [
     {
      "login": "Yudis-bit",
      "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6265384243"
     },
     {
      "login": "Husteem",
      "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6287850935"
     }
    ]
   },
   "conflicts": []
  }
 },
 "acks_parsed": {
  "Yudis-bit": {
   "kind": "ack",
   "hash": "8262933013",
   "t": "2026-10-19T10:44:08Z",
   "stale": false
  }
 },
 "acks_tally": {
  "ack": 1,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "Husteem",
   "Yudis-bit",
   "winterrdog"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "clean",
  "last_author_activity": "2026-10-18T20:03:07Z",
  "last_reviewer_activity": "2026-10-20T13:09:10Z",
  "last_reviewer": "Husteem",
  "author_silent_days": 14,
  "waiting_on_author_days": 12,
  "days_since_update": 12
 },
 "refs": {
  "mentioned": [],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "`AnalyzePSBT` computes `fee = in_amt - out_amt` once every input amount is known and returns it as is. A PSBT whose outputs are worth more than its inputs therefore gets a negative `fee` and a `next` role of updater, even though no wallet can ever sign it into a valid transaction. The function already returns `PSBT is not valid. ...` for bad input values, unspendable outputs and an out-of-range output total.\n\nAn output total above the input total is reported the same way:\n\n```\nbefore: {\"fee\": -1.00000000, \"next\": \"updater\", ...}\nafter:  {\"next\": \"creator\", \"error\": \"PSBT is not valid. Output amount larger than input amount\"}\n```\n\nThe functional test builds a PSBT that spends a 1 BTC output into a 2 BTC output and checks the error and the `creator` role. Without the change the assertion on `next` fails. `rpc_psbt.py`, `wallet_send.py`, `wallet_multisig_descriptor_psbt.py`, `rpc_openrpc.py` and the psbt unit tests pass.",
 "commits": [
  {
   "sha": "82629330135ba7df7ef5fc061ffadca3288043b1",
   "date": "2026-10-18T20:03:07Z",
   "message": "psbt: analyzepsbt reports an error when outputs exceed inputs\n\nWhen every input amount is known, AnalyzePSBT computed fee as\nin_amt - out_amt and returned it even if it was negative, together with\na negative fee rate and a next role of updater or signer. Treat a PSBT\nthat pays out more than it spends as invalid, like the other amount\nchecks in the same function."
  }
 ],
 "timeline": [
  {
   "t": "2026-10-19T10:44:08Z",
   "kind": "comment",
   "who": "Yudis-bit",
   "assoc": "NONE",
   "text": "Tested ACK 8262933013 on Windows. Would it be worth also adding a unit test in psbt_tests?",
   "id": "c:6265384243",
   "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6265384243",
   "hash": "25fac5ccf8e04414",
   "edited": null
  },
  {
   "t": "2026-10-20T09:28:13Z",
   "kind": "comment",
   "who": "Husteem",
   "assoc": "NONE",
   "text": "tACK 8262933\n\nVerified the bug on `master` (where an overspending PSBT returned a negative fee, empty error, and `signer` role).\n`rpc_psbt.py` passes on this branch.\n\nThe guard in `AnalyzePSBT` is a good fix.\nAlso agree with @Yudis-bit - adding a companion unit test in `psbt_tests.cpp` would be worthwhile for regression coverage here.",
   "id": "c:6287850935",
   "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6287850935",
   "hash": "a1526ebbbc0ead81",
   "edited": null
  },
  {
   "t": "2026-10-20T09:37:53Z",
   "kind": "comment",
   "who": "winterrdog",
   "assoc": "CONTRIBUTOR",
   "text": "@Husteem @Yudis-bit\n\nSorry for bikeshedding. I am trying to understand what the motive for a unit test is here.. What special thing would the unit test assert that the current functional test does not \ud83e\udd14 ?",
   "id": "c:6288015112",
   "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6288015112",
   "hash": "b98fcfb7232a0eae",
   "edited": null
  },
  {
   "t": "2026-10-20T13:09:10Z",
   "kind": "comment",
   "who": "Husteem",
   "assoc": "NONE",
   "text": "Hi @winterrdog. It's totally fine to enquire!\n\nWhile I'd say it's a nit, obviously, the thought was mainly direct coverage on the C++ struct (`has_sane_fee = false` and `fee` staying unset) without spinning up a test node.\n\nThat said, since rpc_psbt.py already asserts both `error` and `next == 'creator'` across the RPC boundary, you're pretty right that it covers the regression well enough.",
   "id": "c:6291601625",
   "url": "https://github.com/bitcoin/bitcoin/pull/36569#issuecomment-6291601625",
   "hash": "24ab7d8567859070",
   "edited": null
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-19T03:28:09Z",
   "action": "labeled",
   "label": "PSBT",
   "who": "fanquake"
  }
 ],
 "state_log": [],
 "text_chars": 2384,
 "text_tokens_estimate": 596,
 "changed_paths": [
  "src/node/psbt.cpp",
  "test/functional/rpc_psbt.py"
 ],
 "files": [
  {
   "path": "src/node/psbt.cpp",
   "add": 5,
   "del": 0
  },
  {
   "path": "test/functional/rpc_psbt.py",
   "add": 8,
   "del": 0
  }
 ],
 "test_lines": 8,
 "git": {
  "head": "82629330135ba7df7ef5fc061ffadca3288043b1",
  "head_matches_backup": true,
  "base": "924f4c4ac78b0cd3b917c694f42c0651a6f3003a",
  "patch_id": "770ca0433a21e37d",
  "commits": [
   {
    "sha": "8262933013",
    "subject": "psbt: analyzepsbt reports an error when outputs exceed inputs",
    "files": 2,
    "add": 13,
    "del": 0
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "770ca0433a21e37d",
 "input_hash": "cc69338c77e72c0a",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}