feat: add support for OP_RETURN output on the send path - #2753
Draft
dorianvp wants to merge 10 commits into
Draft
Conversation
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
force-pushed
the
feat/add-opreturn
branch
from
August 31, 2026 21:59
7c41daf to
621831a
Compare
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional OP_RETURN (null-data) output to the send path by keeping
zcash_client_backendfor planning and bypassingcreate_proposed_transactionsonly for the payload-carrying transaction.