AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 63 Bitcoin

Parse the OP_RETURN push opcode instead of assuming OP_PUSHDATA1

Public commit record

What the developer wrote

Authored by okaybro

81/100 · Strong
Parse the OP_RETURN push opcode instead of assuming OP_PUSHDATA1

The payload was read at a fixed 3-byte offset, which only holds when the script
uses OP_PUSHDATA1. Opcodes 0x01-0x4b are themselves the byte count, and that is
the minimal encoding Bitcoin Core emits, so every payload of 75 bytes or fewer
lost its first byte:

scriptPubKey 6a 28 "Chancellor on the brink of third bailout"
parsed b'hancellor on the brink of third bailout'

PSBTOpReturnView is a pre-signing review screen, so the user approved a
transaction whose OP_RETURN content was displayed wrong. When the payload is not
human-readable it renders as hex, where a one byte shift is invisible.

Read the push opcode and slice to the declared length, in a static helper so the
loop stays readable. OP_PUSHDATA2 and OP_PUSHDATA4 are handled too: Bitcoin Core
v30 raised the default -datacarriersize to 100,000 bytes, and consensus never
limited OP_RETURN data at all, so a payload past what OP_PUSHDATA1 can describe
is no longer exotic.

Several pushes after OP_RETURN are legal and are concatenated; the user is being
shown the data the transaction commits to, and the push boundaries carry no
consensus meaning. Anything that is not a data push, or a push that overruns the
script, ends the walk and the remaining bytes are surfaced verbatim rather than
dropped.

Also reset op_return_data in _parse_outputs, which only ever set it in
__init__, and compare the first byte by slice so an empty scriptPubKey does not
raise IndexError.

Fixes #963

Co-authored-by: ruipereira1 <159703278+ruipereira1@users.noreply.github.com>
Co-authored-by: kwsantiago <44934418+kwsantiago@users.noreply.github.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in SeedSigner, a hardware wallet tool, where the OP_RETURN message shown to users before signing a transaction could be displayed incorrectly. The old code assumed every OP_RETURN payload started with a specific push opcode (OP_PUSHDATA1), so for shorter messages it accidentally cut off the first byte. Because the screen is shown before the user approves the signature, a misleading display could make someone approve a transaction whose embedded message is not what they saw. For non-human-readable payloads shown as hex, the error is invisible. The fix properly reads the push opcode and extracts the correct payload length.

Recommended action

Review and merge the patch, then verify OP_RETURN display for direct pushes, OP_PUSHDATA1/2/4, multiple pushes, truncated scripts, and empty scriptPubKey. Consider adding unit tests for these script patterns in the PSBT parser.

Security signals we found

01

UI misrepresentation of transaction data before signing

02

Incorrect fixed-offset parsing of script opcodes

03

OP_RETURN display bug could mislead user approval

04

Missing reset of op_return_data across parses

05

Potential IndexError on empty scriptPubKey

Risk score

Why this scored 63/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 11/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.