{
 "number": 36626,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36626",
 "title": "test: check `PSBT_GLOBAL_VERSION` validation on decode",
 "author": "nebula-21",
 "author_association": "CONTRIBUTOR",
 "created_at": "2026-10-23T16:06:24Z",
 "updated_at": "2026-10-29T08:57:46Z",
 "description_hash": "a4ff16cd5b61340f",
 "age_days": 9,
 "draft": false,
 "labels": [
  "Tests"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
 "head_ref": "test-psbt-version-field",
 "head_repo": "nebula-21/bitcoin",
 "head_history": [],
 "additions": 16,
 "deletions": 0,
 "changed_files": 1,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "clean",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {
    "concept_ack": [
     {
      "login": "Bicaru20",
      "url": "https://github.com/bitcoin/bitcoin/pull/36626#pullrequestreview-5665408081"
     }
    ]
   },
   "conflicts": []
  }
 },
 "acks_parsed": {
  "Bicaru20": {
   "kind": "concept_ack",
   "hash": null,
   "t": "2026-10-27T11:00:03Z",
   "stale": false
  }
 },
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 1,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "Bicaru20"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "clean",
  "last_author_activity": "2026-10-23T15:45:25Z",
  "last_reviewer_activity": "2026-10-29T08:57:46Z",
  "last_reviewer": "Bicaru20",
  "author_silent_days": 9,
  "waiting_on_author_days": 3,
  "days_since_update": 3
 },
 "refs": {
  "mentioned": [],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [],
  "conflicts": []
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [
  "test/functional/rpc_psbt.py"
 ],
 "body": "This PR adds coverage for the global PSBT version field validation on decode.\n\n`test_psbt_unsupported_version_field` checks that the PSBT has supported version number into the `PSBT_GLOBAL_VERSION` field.\nThe test can be triggered with this diff:\n\nDiff\n\n```diff\ndiff --git a/src/psbt.h b/src/psbt.h\nindex 5eb5e81428..d90528e01d 100644\n--- a/src/psbt.h\n+++ b/src/psbt.h\n@@ -94,7 +94,7 @@ inline constexpr uint8_t PSBT_SEPARATOR = 0x00;\n inline constexpr std::streamsize MAX_FILE_SIZE_PSBT{100'000'000}; // 100 MB\n\n // PSBT version number\n-inline constexpr uint32_t PSBT_HIGHEST_VERSION = 2;\n+inline constexpr uint32_t PSBT_HIGHEST_VERSION = 4;\n\n /** A structure for PSBT proprietary types */\n struct PSBTProprietary\n```\n\n`test_psbt_missing_version_field` checks that a PSBT  without the `PSBT_GLOBAL_VERSION` field is interpreted as a v0. I've created a v2 and removed the field to check the correct behavior (fails beacuse it was originally a v2 and now is misinterpreted as a v0).\nThe test can be triggered with this diff:\n\nDiff\n\n```diff\ndiff --git a/src/psbt.h b/src/psbt.h\nindex 5eb5e81428..ea11267e0f 100644\n--- a/src/psbt.h\n+++ b/src/psbt.h\n@@ -1515,7 +1515,7 @@ public:\n         if (psbt_ver == 0) {\n             // Make sure that we got an unsigned tx for PSBTv0\n             if (!tx) {\n-                throw std::ios_base::failure(\"No unsigned transaction was provided\");\n+                //throw std::ios_base::failure(\"No unsigned transaction was provided\");\n             }\n             // Make sure no PSBTv2 fields are present\n             if (found_tx_version) {\n```\n\nPrior to this PR, no test would be triggered with this diffs.",
 "commits": [
  {
   "sha": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
   "date": "2026-10-23T15:45:25Z",
   "message": "test: check `PSBT_GLOBAL_VERSION` validation on decode"
  }
 ],
 "timeline": [
  {
   "t": "2026-10-27T10:13:26Z",
   "kind": "review_comment",
   "who": "Bicaru20",
   "assoc": "CONTRIBUTOR",
   "path": "test/functional/rpc_psbt.py",
   "commit": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
   "in_reply_to": null,
   "text": "nit:  Since the test is for PSBTv2, I think it's better to explicity add the psbt version in case the default it is ever changed.\n\n```suggestion\n        psbt = PSBT.from_base64(self.nodes[0].createpsbt([{\"txid\": \"00\" * 32, \"vout\": 0}], [{\"data\": \"00\"}], psbt_version=2))\n```",
   "id": "rc:4387437960",
   "url": "https://github.com/bitcoin/bitcoin/pull/36626#discussion_r4387437960",
   "hash": "a98b1cfdc932e014",
   "edited": "2026-10-27T11:00:03Z"
  },
  {
   "t": "2026-10-27T10:14:30Z",
   "kind": "review_comment",
   "who": "Bicaru20",
   "assoc": "CONTRIBUTOR",
   "path": "test/functional/rpc_psbt.py",
   "commit": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
   "in_reply_to": null,
   "text": "nit: Same as before\n```suggestion\n        psbt = PSBT.from_base64(self.nodes[0].createpsbt([{\"txid\": \"00\" * 32, \"vout\": 0}], [{\"data\": \"00\"}], psbt_version=2))\n```",
   "id": "rc:4387447453",
   "url": "https://github.com/bitcoin/bitcoin/pull/36626#discussion_r4387447453",
   "hash": "1adc2a8c87933eb5",
   "edited": "2026-10-27T11:00:03Z"
  },
  {
   "t": "2026-10-27T11:00:03Z",
   "kind": "review",
   "who": "Bicaru20",
   "assoc": "CONTRIBUTOR",
   "state": "COMMENTED",
   "commit": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
   "text": "Concept ACK.\nLeft a couple of nits.\nI beleive it is good to separate the test into functions, but in this case I  think we could do it with one function that covers both cases, that way we can reuse the PSBT.\n\n```diff\n--- a/test/functional/rpc_psbt.py\n+++ b/test/functional/rpc_psbt.py\n@@ -839,17 +839,15 @@ class PSBTTest(BitcoinTestFramework):\n         assert_raises_rpc_error(-8, \"The PSBT version can only be 2 or 0\", self.nodes[0].converttopsbt, hexstring=rawtx, psbt_version=1)\n         assert_raises_rpc_error(-8, \"The PSBT version can only be 2 or 0\", self.nodes[0].psbtbumpfee, txid=tobump, psbt_version=1)\n\n-    def test_psbt_unsupported_version_field(self):\n+    def test_psbt_version_field(self):\n         self.log.info(\"Test that the global PSBT version is supported on decode\")\n\n-        psbt = PSBT.from_base64(self.nodes[0].createpsbt([{\"txid\": \"00\" * 32, \"vout\": 0}], [{\"data\": \"00\"}]))\n+        psbt = PSBT.from_base64(self.nodes[0].createpsbt([{\"txid\": \"00\" * 32, \"vout\": 0}], [{\"data\": \"00\"}], psbt_version=2))\n         psbt.g.map[PSBT_GLOBAL_VERSION] = (3).to_bytes(4, \"little\")\n         assert_raises_rpc_error(-22, \"TX decode failed Unsupported version number\", self.nodes[0].decodepsbt, psbt.to_base64())\n\n-    def test_psbt_missing_version_field(self):\n         self.log.info(\"Test that a PSBT without the global version is interpreted as v0\")\n\n-        psbt = PSBT.from_base64(self.nodes[0].createpsbt([{\"txid\": \"00\" * 32, \"vout\": 0}], [{\"data\": \"00\"}]))\n         del psbt.g.map[PSBT_GLOBAL_VERSION]\n         assert_raises_rpc_error(-22, \"TX decode failed No unsigned transaction was provided\", self.nodes[0].decodepsbt, psbt.to_base64())\n\n@@ -1836,8 +1834,7 @@ class PSBTTest(BitcoinTestFramework):\n         self.test_psbt_named_parameter_handling()\n         self.test_psbt_roundtrip()\n         self.test_psbt_version()\n-        self.test_psbt_unsupported_version_field()\n-        self.test_psbt_missing_version_field()\n+        self.test_psbt_version_field()\n         self.test_psbt_with_invalid_signature()\n         self.test_musig2_untrusted_derivation()\n\n```",
   "id": "r:5665408081",
   "url": "https://github.com/bitcoin/bitcoin/pull/36626#pullrequestreview-5665408081",
   "hash": "5592f96ad6c1fee8",
   "edited": null
  },
  {
   "t": "2026-10-29T08:57:46Z",
   "kind": "comment",
   "who": "Bicaru20",
   "assoc": "CONTRIBUTOR",
   "text": "After digging a little bit more into the test, I've noticed that regarding `PSBT_GLOBAL_VERSION` there is a case that is not coverd and we could add to this test:\n\n```python\n      psbt.g.map[PSBT_GLOBAL_VERSION] = (1).to_bytes(4, \"little\")\n      assert_raises_rpc_error(-22, \"TX decode failed There is no PSBT version 1\", self.nodes[0].decodepsbt, psbt.to_base64())\n```\nThis is the line where the error is thrown in `psbt.h`: https://github.com/bitcoin/bitcoin/blob/9bf4815b94b9eaf8807f4e569091778da6c338d5/src/psbt.h#L1539",
   "id": "c:6492355359",
   "url": "https://github.com/bitcoin/bitcoin/pull/36626#issuecomment-6492355359",
   "hash": "7520684022931184",
   "edited": null
  }
 ],
 "labels_log": [
  {
   "t": "2026-10-23T16:06:29Z",
   "action": "labeled",
   "label": "Tests",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 4805,
 "text_tokens_estimate": 1201,
 "changed_paths": [
  "test/functional/rpc_psbt.py"
 ],
 "files": [
  {
   "path": "test/functional/rpc_psbt.py",
   "add": 16,
   "del": 0
  }
 ],
 "test_lines": 16,
 "git": {
  "head": "eeb4782bda842f6c9eb8a572301b46f8d5faf30b",
  "head_matches_backup": true,
  "base": "152a55397e451fed9c10041bddf01aa6839847d5",
  "patch_id": "645986f895e3718b",
  "commits": [
   {
    "sha": "eeb4782bda",
    "subject": "test: check `PSBT_GLOBAL_VERSION` validation on decode",
    "files": 1,
    "add": 16,
    "del": 0
   }
  ],
  "patch_truncated": false
 },
 "patch_id": "645986f895e3718b",
 "input_hash": "021ae46b3daada95",
 "extracted_at": "2026-11-02T01:09:49+00:00"
}