telegram link : t.me/nullifiersystem
1. Summary & Core Promise
In contracts/atomic-swap/src/lib.rs and contracts/htlc-core/src/lib.rs, cross-chain HTLC atomic swaps rely on counterparties manually revealing secret preimages before expiration. If one counterparty fails to fulfill their side of the swap on an external chain, the trade hangs until full timeout expiration, locking the honest party's funds without an automated dispute claims path.
This feature implements a Cross-Ledger Settlement Time-Lock Atomic Swap Dispute Bridge. It adds automated dual-side secret extraction (apps/api/src/lib/timeouts.ts), automatic refund claim triggers upon counterparty expiration, PostgreSQL transaction locking (SELECT FOR UPDATE), and automated alert webhooks (apps/api/src/lib/webhook.ts).
2. Background & Architectural Risks
- Asymmetric Lockup Risk: One party reveals the secret on Chain A while the counterpart delays revealing on Chain B, risking partial trade execution.
- Relayer Secret Leakage: Failing to extract revealed secrets from on-chain event logs before the local HTLC timeout expires leads to unrecoverable collateral loss.
3. Database Layer Specifications
Migration SQL (029_add_atomic_swap_dispute_bridge.sql)
CREATE TYPE swap_dispute_state AS ENUM ('ACTIVE', 'SECRET_EXTRACTED', 'REFUND_CLAIMABLE', 'RESOLVED');
CREATE TABLE atomic_swap_dispute_bridges (
swap_id VARCHAR(64) PRIMARY KEY,
initiator_address VARCHAR(56) NOT NULL,
counterparty_address VARCHAR(56) NOT NULL,
secret_hash VARCHAR(64) NOT NULL,
secret_preimage VARCHAR(64) NULL,
expiration_ledger INT NOT NULL,
state swap_dispute_state NOT NULL DEFAULT 'ACTIVE',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_swap_expiration ON atomic_swap_dispute_bridges(expiration_ledger, state);
Data Locking (SELECT FOR UPDATE)
BEGIN;
SELECT swap_id, state, expiration_ledger
FROM atomic_swap_dispute_bridges
WHERE swap_id = $1
FOR UPDATE;
-- Update state to REFUND_CLAIMABLE or RESOLVED...
COMMIT;
4. Backend Route & Service Layer Specifications
Route: POST /api/v1/swaps/dispute-claim
- Validation: Zod validates
swapId and checks current ledger height.
- Locking: DB transaction acquires
SELECT FOR UPDATE on atomic_swap_dispute_bridges.
- Preimage Check: If secret preimage was revealed on-chain, extracts secret and completes swap; if expired, triggers automatic refund.
- Response: Returns
HTTP 200 OK with execution proof.
5. Background Processors / Workers
Atomic Swap Secret Extraction Worker (apps/api/src/lib/workers/swapDisputeWorker.ts)
- Watches Stellar and EVM ledger event logs for
SecretRevealed events, extracts preimages, and resolves pending cross-chain legs automatically.
6. Frontend / UI Component Specifications
Component: mobile/frontend/src/components/AtomicSwapDisputeCard.tsx
- Renders real-time HTLC lockup status, secret extraction progress, and one-click
"Claim Dispute Refund" button when timeout threshold is breached.
7. Rigor & Test Plan
- Unit Tests (
contracts/atomic-swap/src/test.rs): Test secret extraction and automated HTLC refund claim on counterparty timeout.
- Concurrency Stress Test (
tests/concurrency/swap_dispute_stress.test.ts): 50 concurrent swap secret extraction calls verifying zero duplicate refund executions.
8. Relevant Files Inventory
New Files to Create
apps/api/src/db/migrations/029_add_atomic_swap_dispute_bridge.sql
apps/api/src/routes/swap-dispute.ts
apps/api/src/lib/workers/swapDisputeWorker.ts
tests/concurrency/swap_dispute_stress.test.ts
mobile/frontend/src/components/AtomicSwapDisputeCard.tsx
Existing Files to Modify
contracts/atomic-swap/src/lib.rs
contracts/htlc-core/src/lib.rs
contracts/atomic-swap/src/test.rs
apps/api/src/lib/timeouts.ts
apps/api/src/lib/webhook.ts
apps/api/src/lib/stellar.ts
9. Acceptance Criteria
10. Contributor Notes
- ⚠️ Atomic Safety: ALWAYS extract and store revealed secret preimages off-chain immediately upon on-chain event emission.
telegram link : t.me/nullifiersystem
1. Summary & Core Promise
In
contracts/atomic-swap/src/lib.rsandcontracts/htlc-core/src/lib.rs, cross-chain HTLC atomic swaps rely on counterparties manually revealing secret preimages before expiration. If one counterparty fails to fulfill their side of the swap on an external chain, the trade hangs until full timeout expiration, locking the honest party's funds without an automated dispute claims path.This feature implements a Cross-Ledger Settlement Time-Lock Atomic Swap Dispute Bridge. It adds automated dual-side secret extraction (
apps/api/src/lib/timeouts.ts), automatic refund claim triggers upon counterparty expiration, PostgreSQL transaction locking (SELECT FOR UPDATE), and automated alert webhooks (apps/api/src/lib/webhook.ts).2. Background & Architectural Risks
3. Database Layer Specifications
Migration SQL (
029_add_atomic_swap_dispute_bridge.sql)Data Locking (
SELECT FOR UPDATE)4. Backend Route & Service Layer Specifications
Route:
POST /api/v1/swaps/dispute-claimswapIdand checks current ledger height.SELECT FOR UPDATEonatomic_swap_dispute_bridges.HTTP 200 OKwith execution proof.5. Background Processors / Workers
Atomic Swap Secret Extraction Worker (
apps/api/src/lib/workers/swapDisputeWorker.ts)SecretRevealedevents, extracts preimages, and resolves pending cross-chain legs automatically.6. Frontend / UI Component Specifications
Component:
mobile/frontend/src/components/AtomicSwapDisputeCard.tsx"Claim Dispute Refund"button when timeout threshold is breached.7. Rigor & Test Plan
contracts/atomic-swap/src/test.rs): Test secret extraction and automated HTLC refund claim on counterparty timeout.tests/concurrency/swap_dispute_stress.test.ts): 50 concurrent swap secret extraction calls verifying zero duplicate refund executions.8. Relevant Files Inventory
New Files to Create
apps/api/src/db/migrations/029_add_atomic_swap_dispute_bridge.sqlapps/api/src/routes/swap-dispute.tsapps/api/src/lib/workers/swapDisputeWorker.tstests/concurrency/swap_dispute_stress.test.tsmobile/frontend/src/components/AtomicSwapDisputeCard.tsxExisting Files to Modify
contracts/atomic-swap/src/lib.rscontracts/htlc-core/src/lib.rscontracts/atomic-swap/src/test.rsapps/api/src/lib/timeouts.tsapps/api/src/lib/webhook.tsapps/api/src/lib/stellar.ts9. Acceptance Criteria
refund()for honest counterparties.SELECT FOR UPDATE.10. Contributor Notes