Skip to content

fix: harden swap validation - #163

Merged
i5hi merged 3 commits into
trunkfrom
fix/harden-swap-validation
Sep 9, 2026
Merged

i5hi merged 3 commits into
trunkfrom
fix/harden-swap-validation

Conversation

@ethicnology

Copy link
Copy Markdown
Member

Harden Bitcoin and Liquid swap handling against malformed or inconsistent server responses.

This PR:

  • validates hashlocks, timelocks, key roles, addresses, and networks when constructing swap scripts
  • rejects non-minimal or invalid script encodings
  • verifies lockup transaction IDs against the returned transaction hex
  • validates cooperative server keys before MuSig2 signing
  • checks the exact lockup output amount before claiming
  • verifies completed-swap preimages against their expected hashes
  • redacts private keys and preimages from Debug output
  • adds stricter Bitcoin and Liquid network conversions
  • improves coverage for malformed responses and transaction validation

Security impact

Previously, some server-provided values were trusted independently even when they described the same swap. A compromised or faulty server could therefore return inconsistent scripts, keys, transactions, amounts, or network data and defer failure until a later signing or broadcasting step.

The new checks bind these values together and reject inconsistencies before funds are claimed, refunded, or cooperatively signed.

Compatibility

Valid swaps keep the same behavior.

The changes intentionally reject malformed or internally inconsistent API responses that may previously have progressed further through the swap flow.

@i5hi
i5hi merged commit c3e3a6a into trunk Sep 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants