Skip to content
Business logic Audit finding Advanced

`exchangeFee` can be escaped

The contract calculates the swapped amount by comparing balances before and after a swap, which can be manipulated by reentering the swap function to perform a fake swap that wraps the real swap, causing the exchange fee to be included in the returned amount. An attacker could thus avoid paying most of the exchange fee.

WatchPug Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-mover-judging/issues/120

Found by

WATCHPUG

Summary

Comparing the before and after balance of the swap call for the swapped amount can be exploited to escape the exchangeFee by wrapping the actual swap inside a fake swap.

Vulnerability Detail

The attacker can reenter with another CardTopupPermit() -> _processTopup() -> IExchangeProxy#executeSwapDirect() at L174 to claw back the fee:

  1. Swap minAmount with 1inch, inside the 1inch swap at ExchangeProxy.sol#L174, reenter and HardenedTopupProxy.sol#CardTopupPermit();
  2. The inner swap is the actual amount: $1M, which should pay for $1000 exchangeFee;
  3. After the inner swap, amountReceived includes the $1000 exchangeFee, which will be sent back to the user.

As a result, the user successfully escaped most of the exchangeFee.

Impact

User can escape the exchangeFee.

Code Snippet

https://github.com/sherlock-audit/2022-10-mover/blob/main/cardtopup_contract/contracts/HardenedTopupProxy.sol#L336-L343

https://github.com/sherlock-audit/2022-10-mover/blob/main/cardtopup_contract/contracts/ExchangeProxy.sol#L160-L185

Tool used

Manual Review

Recommendation

Consider adding nonReentrant() modifier to all the 3 non-view methods in the HardenedTopupProxy:

  • CardTopupPermit();
  • CardTopupTrusted();
  • CardTopupMPTProof().

Discussion

McMannaman

This is a valid point. Would be fixed by adding nonReentrant modifiers.

jack-the-pug

Fix confirmed

McMannaman

The fixes are in https://github.com/viaMover/2022-10-mover/pull/2

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

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

Impact

A user could escape most of the exchange fee.

What the attacker needed

Ability to call swap functions; use of 1inch for swaps

The fix

The fix was to add a nonReentrant modifier to all three non-view methods in HardenedTopupProxy.

How it was found

  1. Swap minAmount with 1inch, inside the 1inch swap at ExchangeProxy.sol#L174, reenter and HardenedTopupProxy.sol#CardTopupPermit();
  2. The inner swap is the actual amount: $1M, which should pay for $1000 exchangeFee;
  3. After the inner swap, amountReceived includes the $1000 exchangeFee, which will be sent back to the user.

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.

The contract charges a fee on swaps by checking how much the balance increased. An attacker can call the swap function again from within the swap, making the contract think the fee was part of the swapped amount and refund it. This lets the attacker avoid paying most of the fee.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Mover

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.