Skip to content

Conversation

@EricGrill
Copy link

Summary

This PR updates the isNullDataScript function to allow multiple data push operations after OP_RETURN, matching Bitcoin Core's behavior as of v0.12.0 (2016) which removed the single push restriction.

Changes:

  • Add MaxNullDataScriptSize constant (10000 bytes) for total script size limit
  • Keep MaxDataCarrierSize at 80 bytes for backwards compatibility with NullDataScript function callers
  • Update isNullDataScript to use IsPushOnlyScript to validate that all opcodes after OP_RETURN are valid data pushes (OP_0 through OP_16 and direct/PUSHDATA pushes)
  • Enforce limit on total script size instead of individual push size
  • Update and add test cases for the new behavior

Technical Details:

Previously, btcd only accepted:

  • OP_RETURN alone
  • OP_RETURN + single data push (up to 80 bytes)

After this change, btcd accepts:

  • OP_RETURN alone
  • OP_RETURN + any number of push-only opcodes (total script size <= 10000 bytes)

This matches Bitcoin Core's Solver function which checks:

if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && 
    scriptPubKey.IsPushOnly(scriptPubKey.begin()+1))

Use Cases:

This allows protocols like Metaprotocol, Counterparty, and others that use multiple data pushes in OP_RETURN outputs to be recognized as standard null data scripts.

Test plan

  • Updated existing test cases to reflect new behavior
  • Added test cases for multiple push operations
  • Added test case for non-push opcode after OP_RETURN (should remain NonStandard)
  • Added test cases for scripts at and exceeding the 10000 byte limit
  • Run full test suite (requires Go installation)

Fixes #2305


🤖 Generated with Claude Code

This change updates the isNullDataScript function to allow multiple
data push operations after OP_RETURN, matching Bitcoin Core's behavior
as of v0.12.0 which removed the single push restriction.

Previously, btcd only accepted OP_RETURN followed by a single data push
of up to 80 bytes. This was more restrictive than Bitcoin Core's
implementation.

Changes:
- Add MaxNullDataScriptSize constant (10000 bytes) for total script
  size limit
- Keep MaxDataCarrierSize at 80 bytes for backwards compatibility
  with NullDataScript function callers
- Update isNullDataScript to use IsPushOnlyScript to validate that
  all opcodes after OP_RETURN are valid data pushes
- Enforce limit on total script size instead of individual push size
- Update and add test cases for the new behavior

This allows protocols like the Metaprotocol or Counterparty to use
OP_RETURN outputs with multiple data pushes.

Fixes btcsuite#2305

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Allow multiple push statement for OP_RETURN

1 participant