Skip to content

[codex] Move swap router empty-list guards before folds#16

Open
caydyan wants to merge 1 commit into
BitflowFinance:mainfrom
caydyan:codex/swap-router-empty-guard
Open

[codex] Move swap router empty-list guards before folds#16
caydyan wants to merge 1 commit into
BitflowFinance:mainfrom
caydyan:codex/swap-router-empty-guard

Conversation

@caydyan

@caydyan caydyan commented Jun 22, 2026

Copy link
Copy Markdown

Summary

  • Move empty swap-list assertions before the fold in swap-multi, swap-x-for-y-same-multi, and swap-y-for-x-same-multi.
  • Tighten router tests so empty lists assert ERR_EMPTY_SWAPS_LIST directly.
  • Add empty-list coverage for both same-token multi-swap entrypoints.

Audit context

This addresses Sonic Mast's Bitflow dlmm-swap-router-v-1-1 audit R01 from https://gist.github.com/sonic-mast/c3a352aa6b9b46dd42e36f163d9d9b2d. The finding calls out that empty-list checks execute after the fold. Current main no longer has the audited swap-simple-multi entrypoint, so this PR fixes the still-present affected entrypoints.

Why

The prior behavior was functionally safe for empty lists because folding an empty list returns immediately, but the check read as a post-fold condition. Moving it before the fold makes the empty-list guard an explicit precondition and prevents future changes to fold bodies from accidentally placing any work before the guard.

Validation

  • git diff --check
  • clarinet check contracts/dlmm-swap-router-v-1-1.clar

Additional validation attempted:

  • clarinet check for the full project currently fails outside this change on the existing mock-pool / dlmm-pool-trait get-pool-for-add signature mismatch.
  • npx vitest run tests/routers/swap-router.test.ts currently fails before collecting tests because the checked-in deployment plan uses a transaction-type format that this local Clarinet/Vitest stack cannot read.

BTC payout address if this is accepted for any related bounty: bc1qev5ant33v5y89qqjvcf4mh9hlax5svqf5xd7gc

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.

1 participant