Enforce swap consensus rules during block validation#71
Open
1440000bytes wants to merge 2 commits into
Open
Conversation
Collaborator
|
Thanks for the contribution! There are a few CI failures to address — mostly formatting and similar minor issues. Once those are fixed, I'll go ahead and merge. |
5aa62b7 to
41ae51e
Compare
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 three swap validators in
lib/state/swap.rsare only reached from the mempool path,State::validate_transaction(lib state/mod.rs). The block-application path used for every connected block —prevalidate-connect_prevalidated(lib state/block.rs, called fromconnect_tip_inlib/node/net_task.rs) — only checks value conservation, utreexo proofs, sigops, size, the merkle root, double-spends, and signatures. It never callsvalidate_swap_create,validate_swap_claim, orvalidate_no_locked_outputs.SwapPendingoutput can be spent in a regular transaction, bypassing the swap entirely (the spender double-spends a counterparty who already paid the L1 side).SwapClaimcan be included that pays the attacker rather than the recipient fixed at swap creation, since the address binding check onSwapPendinginputs is intentionally skipped for claims.Fix
Add
swap::validate_block_transaction, invoked per transaction in bothprevalidateandvalidate:SwapCreate- existingvalidate_swap_createRegular- existingvalidate_no_locked_outputsSwapClaim- newvalidate_swap_claim_consensusA swap's
state(Pending-WaitingConfirmations-ReadyToClaim) is set by each node's own parent-chain monitoring (query_and_update_swapinlib/state/two_way_peg_data.rs, plus manual RPC/GUI updates). It is not deterministic across nodes — which is exactly whyconnecttrusts the block and force-advances local state. Calling the fullvalidate_swap_claimhere would let a node that hasn't yet observed the L1 fill reject an otherwise valid block and split consensus.So
validate_swap_claim_consensusenforces only the rules that follow deterministically from on-chain data:Test
New unit tests in
lib/state/swap.rsblock_validation_rejects_spending_locked_output— a regular tx spending a swap-locked output is rejectedblock_validation_rejects_claim_to_wrong_recipient— a pre-specified claim paying someone else is rejectedblock_validation_accepts_claim_to_recipient— a legitimate claim still passes (no false rejection)