Skip to content
Business logic Audit finding Intermediate

Swap output is trusted without settlement verification

The swap adapter trusted the external pool's reported output amount without checking its own token balance change, so a malicious or buggy pool could make the adapter pay out from its existing inventory. This could drain residual funds or disrupt swaps if the adapter lacked enough tokens.

v12 Follow

Originally disclosed on Code4rena

Submitted by v12 |

Found by V12

  • contracts/aquarius-swap-adapter/src/lib.rs #L220

Targets

  • AquariusSwapAdapter::execute_swap

Affected Locations

  • AquariusSwapAdapter.execute_swap: execute_swap calls the external pool, accepts its returned amount_out as authoritative, and then transfers that amount to recipient without checking the adapter’s actual to_token balance increase.

Description

execute_swap crosses a trust boundary into an external Aquarius pool but never verifies settlement against the adapter’s real token balances. After pool.swap(...) returns, the function only checks the reported amount_out and then forwards exactly that many to_token units to recipient. There is no balance-before/balance-after check to confirm that the pool actually delivered the claimed output, even though the shared swap helper already uses that pattern for external handlers. The supplied test scenario demonstrates the gap: a mock pool can return a value without moving tokens, and the swap still succeeds because the adapter already holds prefunded to_token. As a result, any buggy, malicious, or misregistered pool, or any output token that under-delivers relative to the reported amount, can make the adapter subsidize the swap from unrelated inventory.

Root Cause

execute_swap treats pool.swap’s returned amount_out as authoritative instead of validating the adapter’s actual to_token balance delta after the external call.

Impact

A malicious or broken registered pool can cause the adapter to pay recipients out of its existing to_token balance, draining residual funds or mistaken transfers that happen to be held there. If the adapter does not have enough inventory to cover the overstated amount_out, the final transfer fails and swaps for that pair can be repeatedly disrupted until the condition is corrected.

Proof of Concept

See original finding for full Proof of Concept

Remediation

AquariusSwapAdapter::executeswap now snapshots the adapter’s output-token balance before calling the external pool, computes the actual settled balance delta after the call, enforces minamountout against that real delta, and only transfers/returns the actually received amount. This closes the trust-boundary bug where a pool could overstate amountout and drain preexisting adapter inventory.

View diff


The original report as published on Code4rena, by v12. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

execute_swap treats pool.swap’s returned amount_out as authoritative instead of validating the adapter’s actual to_token balance delta after the external call.

Impact

A malicious or broken registered pool could drain the adapter's existing to_token balance, or if inventory is insufficient, swaps for that pair could be repeatedly disrupted.

What the attacker needed

A registered malicious or buggy pool; adapter holds residual to_token balance

The fix

The adapter was fixed to snapshot its output-token balance before the external call, compute the actual settled delta, enforce min_amount_out against that real delta, and only transfer the actually received amount.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A swap adapter is a piece of code that lets users trade one token for another by calling an outside pool. The adapter believed the pool when it said how many tokens it had sent, instead of checking its own balance. A dishonest pool could lie and make the adapter give away tokens it already held.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by v12

View all

37 more disclosed reports, best first.

More from K2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.