`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.
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:
- Swap minAmount with 1inch, inside the 1inch swap at
ExchangeProxy.sol#L174, reenter andHardenedTopupProxy.sol#CardTopupPermit(); - The inner swap is the actual amount:
$1M, which should pay for$1000exchangeFee; - After the inner swap,
amountReceivedincludes the$1000exchangeFee, 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
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
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
- Swap minAmount with 1inch, inside the 1inch swap at ExchangeProxy.sol#L174, reenter and HardenedTopupProxy.sol#CardTopupPermit();
- The inner swap is the actual amount: $1M, which should pay for $1000 exchangeFee;
- 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.