Skip to content

M8: Prepend version byte to V3+ OP_RETURN scripts#917

Open
DavidGershony wants to merge 1 commit into
mainfrom
security/m8-opreturn-version-byte
Open

M8: Prepend version byte to V3+ OP_RETURN scripts#917
DavidGershony wants to merge 1 commit into
mainfrom
security/m8-opreturn-version-byte

Conversation

@DavidGershony

Copy link
Copy Markdown
Collaborator

Summary

Prepend a 1-byte version marker to OP_RETURN scripts for V3+ projects, enabling future protocol evolution while maintaining backward-compatible parsing.

Problem

The current OP_RETURN format has no version indicator. If the data layout needs to change in the future, there's no way to distinguish between old and new formats during parsing — leading to silent misinterpretation of data.

Solution

Builder (V3+)

Prepend a single byte with value equal to the project version (e.g., 0x03) before the existing data pushes.

Parser

Detect the version byte by checking:

  1. First data push is exactly 1 byte long
  2. Its value is >= 3

If detected, adjust the data start index to skip the version byte. Otherwise, parse using the legacy V1/V2 layout.

Backward Compatibility

  • V1/V2 projects have no version byte — parser recognizes them by the absence of the marker
  • V3+ projects have the version byte — parser adjusts offsets accordingly
  • No existing on-chain data is affected

Testing

All 154 shared tests pass.

V3+ projects prepend a 1-byte version marker (value >= 3) to the
OP_RETURN data. The parser detects this by checking if the first
data push is a single byte with value >= 3, then adjusts the data
start index accordingly.

V1/V2 projects continue using the existing layout without a version
byte (backward compatible parsing preserved).

This enables future protocol versions to evolve the OP_RETURN format
while maintaining backward-compatible parsing of existing projects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant