The _fillQuote
function does not validate the received amount of buy tokens against a minimum expected value. This allows attackers to perform sandwich attacks, front-running the transaction to manipulate the swap price, resulting in significant slippage and loss of funds. The current check only ensures the amount is non-zero, which is insufficient to prevent such attacks.
Introduce a minAmountOut
parameter in SwapArgs
and validate that amountOut
(calculated as the difference between post-swap and pre-swap balances) is at least minAmountOut
to ensure the swap meets expected price conditions.
Line 44 – 45
The allowanceTarget
in SwapArgs
is not validated, allowing a malicious user to set it to an arbitrary address. This could lead to the contract approving a malicious spender to transfer unlimited or large amounts of the sell token, resulting in theft of funds if the parent contract does not properly restrict allowanceTarget
.
Validate that allowanceTarget
is either the exchangeProxy
or a trusted list of addresses. Ensure the parent contract enforces strict checks on allowanceTarget
when decoding _swapArgs
.
Line 31 – 35
The amountOut
is calculated as the total balance of the buy token after the swap, including any pre-existing balance in the contract. This leads to incorrect accounting, overreporting the actual tokens received from the swap, which could cause fund mismanagement or exploitation in dependent logic.
Measure the buy token balance before and after the swap, then compute amountOut
as the difference. For example:
uint256 balanceBefore = IERC20(swapArgs.buyToken).balanceOf(address(this));
// Perform swap...
amountOut = IERC20(swapArgs.buyToken).balanceOf(address(this)) - balanceBefore;
Line 44 – 44
The contract does not validate exchangeProxy
and allowanceTarget
addresses beyond checking exchangeProxy
is non-zero. An attacker can supply malicious addresses to steal approved tokens. For example, if allowanceTarget
is set to a malicious contract and swapCallData
triggers a token transfer, the contract’s tokens can be drained. This leads to loss of all approved tokens, as the external call executes arbitrary code with the contract’s funds.
Implement a whitelist for trusted exchangeProxy
and allowanceTarget
addresses. Restrict swaps to pre-approved, audited exchange contracts to prevent unauthorized token transfers.
Line 30 – 40