Skip to content

fix(wallet): enforce OP_RETURN standardness via try_add_data#456

Open
tharu-jwd wants to merge 1 commit intobitcoindevkit:masterfrom
tharu-jwd:fix/op-return-standardness
Open

fix(wallet): enforce OP_RETURN standardness via try_add_data#456
tharu-jwd wants to merge 1 commit intobitcoindevkit:masterfrom
tharu-jwd:fix/op-return-standardness

Conversation

@tharu-jwd
Copy link
Copy Markdown

add_data has been silently accepting oversized payloads and multiple OP_RETURNs, both non-standard. Closes bitcoindevkit/bdk-tx#49.

Adds try_add_data that validates at call-site and deprecates add_data:

  • Data payload capped at 80 bytes (Bitcoin Core's MAX_OP_RETURN_RELAY = 83 bytes total scriptPubKey)
  • Errors if an OP_RETURN recipient is already present

Two new CreateTxError variants: OpReturnInvalidDataSize(usize) and MultipleOpReturnOutputs.

Deprecating rather than removing since this is a public API.


Checklist

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Add TxBuilder::try_add_data which validates against Bitcoin Core
standardness rules before adding an OP_RETURN output:

- Data payload must not exceed 80 bytes (Bitcoin Core MAX_OP_RETURN_RELAY
  limits the scriptPubKey to 83 bytes, constraining the payload to 80 bytes)
- At most one OP_RETURN output per transaction is permitted

Add CreateTxError::OpReturnInvalidDataSize and
CreateTxError::MultipleOpReturnOutputs error variants with links to
the relevant Bitcoin Core policy source.

Deprecate add_data in favour of try_add_data per the project
deprecation policy.

Closes #44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Enforce standardness rules for TxBuilder::add_data

1 participant