rpc: fix OpenRPC hex pattern to allow empty strings #36462

Manually merged
ViniciusCestarii merged 1 commit from openrpc-hex-pattern into master 2026-10-08 08:32:21 +00:00 AGit
ViniciusCestarii commented 2026-10-07 22:46:29 +00:00 (Migrated from github.com)

The OpenRPC schema from getopenrpcinfo declares every STR_HEX value with the pattern ^[0-9a-fA-F]+$. That pattern rejects the empty string, but the node both returns and accepts empty hex. For example:

  • scriptSig.hex is "" for native segwit input (decoderawtransaction, getrawtransaction, etc)
  • decodescript "" succeeds

So a client that validates traffic against the schema rejects valid requests and responses.

This changes the pattern to ^([0-9a-fA-F]{2})*$ (zero or more hex-encoded bytes)

The OpenRPC schema from `getopenrpcinfo` declares every `STR_HEX` value with the pattern `^[0-9a-fA-F]+$`. That pattern rejects the empty string, but the node both returns and accepts empty hex. For example: - `scriptSig.hex` is `""` for native segwit input (`decoderawtransaction`, `getrawtransaction`, etc) - `decodescript ""` succeeds So a client that validates traffic against the schema rejects valid requests and responses. This changes the pattern to `^([0-9a-fA-F]{2})*$` (zero or more hex-encoded bytes)
DrahtBot commented 2026-10-07 22:46:38 +00:00 (Migrated from github.com)

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko, sedited, willcl-ark

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36462 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36462.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36462#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36462#issuecomment-6052580878), [sedited](https://github.com/bitcoin/bitcoin/pull/36462#pullrequestreview-5453541816), [willcl-ark](https://github.com/bitcoin/bitcoin/pull/36462#pullrequestreview-5453697544) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Base: db0bde16b910f43e37252d4172d97f01653ae0f1
Head: 4d7e00d36bf0d287dc241c3aae3852f3d799ed08

Findings

Suggestions

Also assert the STR_HEX result schema (test/functional/rpc_openrpc.py:81, head)

This assertion covers the argument-side STR_HEX schema for createrawtransaction.outputs.data, but the PR changes OpenRPCResultSchema independently. The test does not cover a STR_HEX result such as getrawtransaction's vin[].scriptSig.hex, so a regression that rejects empty response values could go unnoticed. Add an assertion for a STR_HEX result pattern, ideally verifying that it admits "".

Review coverage was incomplete. adversarial: The added even-length restriction remains unverified against all valid STR_HEX traffic. In particular, the definitions of src/rpc/util.cpp::ParseHashV/ParseHexV and numeric-hex result producers such as versionHex and bits were not inspected; their contracts could establish or disprove a schema compatibility regression.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `db0bde16b910f43e37252d4172d97f01653ae0f1` Head: `4d7e00d36bf0d287dc241c3aae3852f3d799ed08` ##### Findings **Suggestions** **Also assert the STR_HEX result schema** (test/functional/rpc_openrpc.py:81, head) This assertion covers the argument-side STR_HEX schema for `createrawtransaction.outputs.data`, but the PR changes `OpenRPCResultSchema` independently. The test does not cover a STR_HEX result such as `getrawtransaction`'s `vin[].scriptSig.hex`, so a regression that rejects empty response values could go unnoticed. Add an assertion for a STR_HEX result pattern, ideally verifying that it admits `""`. Review coverage was incomplete. adversarial: The added even-length restriction remains unverified against all valid STR_HEX traffic. In particular, the definitions of src/rpc/util.cpp::ParseHashV/ParseHexV and numeric-hex result producers such as versionHex and bits were not inspected; their contracts could establish or disprove a schema compatibility regression. [Full review report](<https://review.fish.foo/traces/36462-4d7e00d36bf0d287dc241c3aae3852f3d799ed08-558-1.html>)
maflcko commented 2026-10-08 04:55:08 +00:00 (Migrated from github.com)

lgtm ACK 4d7e00d36b

lgtm ACK 4d7e00d36bf0d287dc241c3aae3852f3d799ed08
sedited (Migrated from github.com) approved these changes 2026-10-08 08:00:23 +00:00
sedited (Migrated from github.com) left a comment
ACK 4d7e00d36bf0d287dc241c3aae3852f3d799ed08
willcl-ark (Migrated from github.com) approved these changes 2026-10-08 08:16:14 +00:00
willcl-ark (Migrated from github.com) left a comment
ACK 4d7e00d36bf0d287dc241c3aae3852f3d799ed08
maflcko commented 2026-10-08 09:09:35 +00:00 (Migrated from github.com)

In theory, one could have size set (in the docs and the schema), if the size is hard and known, but this is probably a massively larger change.

In theory, one could have size set (in the docs and the schema), if the size is hard and known, but this is probably a massively larger change.
fanquake commented 2026-10-08 10:54:54 +00:00 (Migrated from github.com)

Backported to 32.x in #36427.

Backported to `32.x` in #36427.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36462
No description provided.