Skip to content

Conversation

@EricGrill
Copy link

Summary

  • Updates the OP_RETURN size limit from 80 bytes to 10,000 bytes to match Bitcoin Core v30's new default -datacarriersize
  • Extends the pushDataLength() function in C++ to support OP_PUSHDATA2 for data larger than 255 bytes
  • Removes the outdated 83-byte assertion that was blocking larger OP_RETURN scripts
  • Adds comprehensive tests for various OP_RETURN data sizes (100, 255, 256, 1000, 10000 bytes)

Background

Bitcoin Core v30 increased the default -datacarriersize from 83 to 10,000 bytes. Transactions with OP_RETURN outputs larger than 80 bytes that are valid under Bitcoin Core 30 were failing to build in wallet-core due to hardcoded limits.

Changes

C++ Code:

  • src/Bitcoin/Script.h: Updated MaxOpReturnLength from 80 to 10000
  • src/Bitcoin/Script.cpp: Extended pushDataLength() to handle sizes > 255 bytes using OP_PUSHDATA2, removed 83-byte assertion

Rust Code:

  • rust/frameworks/tw_utxo/src/transaction/standard_transaction/builder/output.rs: Updated OP_RETURN_DATA_LIMIT from 80 to 10000
  • rust/frameworks/tw_utxo/src/script/standard_script/conditions.rs: Updated capacity hint in new_op_return()

Tests:

  • tests/chains/Bitcoin/BitcoinScriptTests.cpp: Added tests for 100, 255, 256, 1000, and 10000 byte OP_RETURN data
  • Rust tests added in output.rs for the same size ranges

Test plan

  • Unit tests added for C++ buildOpReturnScript() with various data sizes
  • Unit tests added for Rust OutputBuilder::op_return() with various data sizes
  • Tests verify correct opcode selection (OP_PUSHBYTES_N, OP_PUSHDATA1, OP_PUSHDATA2)
  • Tests verify rejection of data > 10000 bytes

Fixes #4548


Generated with Claude Code

Bitcoin Core v30 increased the default -datacarriersize from 83 to 10000 bytes.
This change updates wallet-core to support larger OP_RETURN payloads.

Changes:
- Update MaxOpReturnLength from 80 to 10000 bytes (C++)
- Update OP_RETURN_DATA_LIMIT from 80 to 10000 bytes (Rust)
- Extend pushDataLength() to support OP_PUSHDATA2 for data > 255 bytes
- Remove outdated 83-byte assertion in buildOpReturnScript()
- Add comprehensive tests for larger OP_RETURN data sizes

Fixes trustwallet#4548

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@EricGrill EricGrill requested a review from a team as a code owner January 14, 2026 07:26
Copy link
Contributor

@sergei-boiko-trustwallet sergei-boiko-trustwallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! But to be able to merge the PR, could you please add one test with a successfully broadcasted transaction on mainnet? You should generate a new private key, top up with ONLY required funds, and spend the entire balance before publishing the changes into the PR. That's needed to avoid funds loss.
Please add a comment like // Successfully broadcasted tx: https://...

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.

Bitcoin broadcast failing with long OP_RETURN (new Bitcoin v30 rules)

2 participants