[Contract] Add Cross-Chain Payload Replay Protection via Nonce and Domain Separator - #739
Open
iexwr wants to merge 2 commits into
Open
[Contract] Add Cross-Chain Payload Replay Protection via Nonce and Domain Separator#739iexwr wants to merge 2 commits into
iexwr wants to merge 2 commits into
Conversation
… verification (SoroLabs#638) Add cross-chain payload replay protection to CrossChainVerifier. Problem: verify_message accepted a raw leaf hash with no domain separation, allowing the same Merkle proof to be replayed across different chains, to different destination contracts, or multiple times. Solution: - New Payload struct with chain_id, destination_contract, nonce, data - compute_payload_hash() helper computing sha256(chain_id || dest || nonce || data), binding every message to a unique chain, contract, and nonce - verify_message now accepts Payload instead of raw leaf hash, computes the domain-separated hash internally - Nonce tracking via NonceUsed storage key to prevent replay on the destination contract - 10 unit tests, all passing: - Existing: initialization, double-init, root update, no-root panic - Updated: verify_message success with Payload - New: replay rejection, different nonce allowed, hash differs by chain_id, hash differs by nonce, hash differs by destination
|
@iexwr Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Author
|
@EDOHWARES Hello |
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.
Closes #638
Summary
Adds cross-chain payload replay protection to the
CrossChainVerifiercontract. The previous implementation accepted a rawleafhash with no domain separation, allowing the same Merkle proof to be replayed across different source chains, different destination contracts, or multiple times against the same contract.Problem
The original
verify_messagetook aBytesN<32> leafparameter with no binding to:Changes
contracts/cross_chain_verifier/src/lib.rsNew types:
Payloadstruct withchain_id: u32,destination_contract: Address,nonce: u64,data: BytesDataKey::NonceUsed(u64)for replay protection storageverify_messagesignature change:leaf: BytesN<32>→payload: Payloadsha256(chain_id || destination_contract.to_xdr() || nonce || data)New helper (outside
#[contractimpl]for reference params):compute_payload_hash(env, payload)— the domain-separated hash functioncontracts/cross_chain_verifier/src/test.rsUpdated tests:
test_verify_message_success— usesPayloadstructtest_verify_message_no_root— usesPayloadstructNew tests:
test_verify_message_replay_rejected"Nonce already used"test_verify_message_different_nonce_allowedtest_compute_payload_hash_differs_by_chain_idtest_compute_payload_hash_differs_by_noncetest_compute_payload_hash_differs_by_destinationVerification
cargo fmtcleanDesign Notes
typed_data_auth(EIP-712 style)CrossChainVerifierdeployment has its own nonce namespacecompute_payload_hashhelper is outside#[contractimpl]so it can accept&Payloadreferences without Soroban's FFI restrictions