rpc: require a hex string for OP_RETURN data

bitcoin/bitcoin: PR #36978

2 suggestions

Optional improvements

Link

[suggestion] · Numeric data errors display an empty value

A numeric data value such as 99 is correctly rejected, but the diagnostic Data must be hexadecimal string (not '') misleadingly displays an empty string instead of identifying the wrong JSON type.

Location: src/rpc/rawtransaction_util.cpp:128 (head).

Details and suggested fix

For createrawtransaction([], {"data": 99}), ParseHexV leaves strHex empty because the value is not a string. IsHex rejects that empty value, and the error formats it as though it were the supplied input. Report the actual JSON type in the non-string branch of ParseHexV, while continuing to reject numbers. Extend the numeric test to check the full intended diagnostic: its current Data must be hexadecimal string substring assertion does not distinguish a type-specific error from the misleading empty-value suffix.


Link

[suggestion] · Numeric data rejection has no RPC release note

RPCs now reject numeric data previously accepted as hex, despite the existing string-only documentation; a short release note would explain the change, although no current client relying on numeric input was found.

Location: src/rpc/rawtransaction_util.cpp:128 (head).

Details and suggested fix

Previously, ParseHexV(value.getValStr(), "Data") accepted numbers whose textual representation was valid even-length hex, so 99 produced the byte 0x99. Passing the original value now rejects those requests. The shared ParseOutputs change also affects PSBT creation and wallet sending RPCs. Although the help already specifies STR_HEX, doc/developer-notes.md calls for release notes when an API changes. Add a short doc/release-notes-*.md entry explaining that OP_RETURN data must be a JSON hex string and numeric values are now rejected.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The original OP_RETURN support proposal presented data as a hex-encoded byte payload supplied in a JSON string, not as a number. Its usage instructions explicitly hex-encoded text with xxd and passed the result as a quoted data value.

This is evidence that the original public interface was string-based. It provides no stated numeric-to-hex convenience feature or compatibility promise, although examples alone cannot prove that numeric acceptance was unintended.

Source 1

Ralph's inferences

The available evidence points toward numeric acceptance being an incidental consequence of extracting a JSON value's textual representation, rather than an established numeric-data interface. This remains an inference, not a verified account of the coercion's introduction.

At the pinned base, ParseOutputs passes value.getValStr() to ParseHexV; at the head, it passes value directly. Combined with the original string-based usage, this supports distinguishing observed permissive behavior from documented compatibility intent. The inspected history supplies no affirmative compatibility rationale requiring numeric inputs to remain accepted.

Source 1

Compatibility exposure is shared across callers because output interpretation is centralized, but that sharing does not itself establish an intentional promise about numeric OP_RETURN data.

AddOutputs delegates to ParseOutputs, and the inspected wallet code also routes sendtoaddress and sendmany recipients through ParseOutputs. The sendmany documentation explicitly permits numeric or string payment amounts, which is a different contract from the original proposal's hex-string data payload. These inspected call sites establish broader exposure, not a historical justification for numeric data coercion.

Source 1