feat(types): add the HashLocked output content variant - #143
Open
rsantacroce wants to merge 1 commit into
Open
Conversation
Phase 1 of docs/specs/ATOMIC_SWAP_PLAN.html. The escrow primitive for one leg of an atomic swap: `claimant` spends it by revealing a preimage of `hash`, or the output's own address reclaims it once the chain reaches `timeout_height`. Both are decided from block data alone, which is the point — completing a cross-chain swap stops requiring any node to observe the other chain. There is deliberately no `refund_to` field. The address that authorises a refund and the address a refund pays have to be the same one, so carrying both would only create a way for them to disagree; the refund pays `Output::address`, which is also the key that signs for it. The hash is SHA-256, not blake3. The counterparty leg is a Bitcoin HTLC gated on OP_SHA256, and two locks that do not open to the same secret are not a swap; they are two refunds. `SwapId` is blake3, so this is the exact place the habit would have produced a silent break, and the doc comment on the variant says so. Appended last. `Content` is Borsh-encoded by variant index into every `Output`, and outputs hash into the block's merkle root, so a reordered variant rewrites the encoding of every block carrying it — a merkle-root mismatch with no compile error pointing at the cause. Nothing is in production yet, so the discipline costs nothing to adopt today; the point is that it predates the moment it starts to matter. `output_content_borsh_discriminants_are_stable` pins the numbering. Moving HashLocked above SwapPending reproduces the failure it exists to catch, with the consequence named in the assertion message rather than left as a bare index mismatch. Ten sites updated, all found by the compiler: the three Serde/Borsh representations, the four `From` conversions, `GetValue`, a predicate, and one exhaustive match in `integration_tests/setup.rs` that only `--all-targets` reaches. No spend rules yet — an output of this type can be created but not spent. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mrg9zkV9bEdAvVEjx1RKLx
rsantacroce
force-pushed
the
feat/hashlocked-output
branch
from
August 30, 2026 16:52
41dd175 to
c18bb69
Compare
Collaborator
Author
|
Updated: Writing the refund rule in Phase 3 made it obvious the field was a second source of truth — the address that authorises a refund and the address a refund pays have to be the same one, and carrying both only creates a way for them to disagree. Refunds now pay The branch is rebuilt to match what landed on Verified: build/fmt/clippy clean on |
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.
The escrow primitive for one leg of an atomic swap:
claimantspends it by revealing a preimage ofhash;refund_toreclaims it once the chain reachestimeout_height. Both are decided from block data alone — which is the point. Completing a cross-chain swap stops requiring any node to observe the other chain, so the vulnerability in #140's sibling analysis (a miner claiming an escrow without paying on BTC) has nothing left to exploit.Two things this PR is careful about
SHA-256, not blake3. The counterparty leg is a Bitcoin HTLC gated on
OP_SHA256. Two locks that don't open to the same secret aren't a swap, they're two refunds — and the failure is silent, since both sides still look claimable until neither is.SwapIdis blake3, so this is exactly where the house habit would have produced the break. The variant's doc comment says so.Appended last, and pinned.
Contentis Borsh-encoded by variant index into everyOutput, and outputs hash into the block's merkle root. A reordered variant rewrites the encoding of every block carrying it, and surfaces as a merkle-root mismatch with nothing pointing at the cause.output_content_borsh_discriminants_are_stablepins the numbering. Verified it has teeth — movingHashLockedaboveSwapPendingreproduces the failure:Note this guard did not previously exist. The plan claimed
ParentChainTypehad one to copy; it does not — that test lives only onfeat/parent-chain-phase-9-docs. The plan is corrected in the same push.Scope
Ten sites, all found by the compiler: the three Serde/Borsh representations, the four
Fromconversions,GetValue, a predicate, and one exhaustive match inintegration_tests/setup.rsthat only--all-targetsreaches.No spend rules yet — an output of this type can be created but not spent. Phase 3 adds the claim and refund paths.
Verification
cargo build --workspace --all-targets,cargo fmt --all --check,cargo clippy --workspace --all-targetsall clean. 56 unit tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01Mrg9zkV9bEdAvVEjx1RKLx