Skip to content

feat: add support for OP_RETURN output on the send path - #2753

Draft
dorianvp wants to merge 10 commits into
zingolabs:devfrom
dorianvp:feat/add-opreturn
Draft

feat: add support for OP_RETURN output on the send path#2753
dorianvp wants to merge 10 commits into
zingolabs:devfrom
dorianvp:feat/add-opreturn

Conversation

@dorianvp

@dorianvp dorianvp commented Aug 31, 2026

Copy link
Copy Markdown
Member

Adds an optional OP_RETURN (null-data) output to the send path by keeping zcash_client_backend for planning and bypassing create_proposed_transactions only for the payload-carrying transaction.

@dorianvp dorianvp changed the title SKETCH: minimal OP_RETURN seam over the existing zcb spend path (alt to #2469) feat: add support for OP_RETURN output on the send path Aug 31, 2026
Adds an optional OP_RETURN (null-data) output to the send path.

`zcash_client_backend` still plans and, for payload-free sends, builds the
whole proposal. When a payload is present it rides the final transaction
of the proposal (the ZIP-320 TEX exposure step, or the single step
otherwise), which is built by driving the `zcash_primitives` transaction
builder directly so `add_transparent_null_data_output` can be called; a
Shield never carries a payload.

Adds a validated `OpReturnData` newtype (<=80 bytes) with a typed error,
and threads `Option<OpReturnData>` through `calculate_transactions`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dorianvp and others added 5 commits September 3, 2026 16:22
Replaces the sketch stub with a working THORChain / MAYAChain swap-deposit
flow. `LightClient::propose_swap_deposit(vault, amount, memo, account)`
sends two transactions, the same shape as a ZIP-320 TEX pair:

1. a deshield from shielded funds to a freshly reserved, wallet-owned
   transparent address, built entirely by zcash_client_backend, and
2. a transparent memo carrier spending that output to the vault with the
   swap memo in an 80-byte OP_RETURN, hand-built on the zcash_primitives
   builder (the only place OP_RETURN support exists upstream).

The deshield funds the carrier exactly, so the carrier has no change and
always balances; its transparent input is the refundable sender THORChain
/ MAYAChain require. Only the transparent carrier is hand-built; the
shielded spend stays in zcb, and all consensus-critical pieces (builder,
ZIP-317 fee, prover, persistence) are reused from upstream.

New: wallet/op_return.rs (validated OpReturnData newtype), wallet/swap.rs
(fee sizing, carrier build/persist, deshield-output location), the
propose_swap_deposit orchestration, and typed errors.

Tests: 9 offline unit tests plus a passing regtest integration test
(swap_deposit_carries_op_return_to_vault_on_chain) proving both
transactions confirm on-chain with the memo in the carrier's OP_RETURN.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Removes explanatory inline comments from the OP_RETURN swap-deposit code
and its tests, leaving the doc comments. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
juanky201271 and others added 4 commits September 6, 2026 12:47
A caller that names a refund address to a counterparty before the
transaction exists must name the one the coming proposal will spend
through. `generate_refund_addresses` cannot serve that: it reserves, so
asking moves the index on, and the proposal then takes the next one — the
counterparty is told an address the wallet never pays from. A swap provider
that reads the refund destination off the deposit's origin sees nothing.

`derive_refund_addresses` is that method, taking `&self` and computing the
same next index without inserting it. Every call answers the same until an
apply reserves. `generate_refund_addresses` now derives and inserts, so the
two cannot disagree about which index is next.

This is ADR 0010's property: reservation belongs to the step where a
transaction bearing the address comes into existence, not to the question.
A quote the user walks away from leaves the gap limit where it was.

The two tests come with it, because the property is the point. They were
written against a bug that had already been found once — a caller reserving
before naming — and they fail if it returns.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`cargo-checkmate (doc)` has been failing on this branch since 46900d9,
before the commit ahead of this one: the module doc links to
`LightWallet::op_return_carrier_fee` and `LightWallet::build_op_return_carrier`,
and both are `pub(crate)`. Under `-D warnings`, rustdoc refuses a public doc
that links to a private item.

Plain code spans say the same thing to a reader and ask rustdoc to resolve
nothing. The alternative — widening both to `pub` — would change the API
surface to satisfy a comment, which is the wrong way round.

Co-Authored-By: Claude Opus 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.

2 participants