Summary
function _convertAssetsToUsdc(
uint128 dexSwapStrategyId,
address asset,
uint256 assetAmount,
bytes memory path,
address recipient,
address usdc
)
internal
returns (uint256 usdcOut)
{
if (assetAmount == 0) revert Errors.AssetAmountIsZero(asset);
if (asset == usdc) {
usdcOut = assetAmount;
} else {
DexSwapStrategy.Data storage dexSwapStrategy = DexSwapStrategy.loadExisting(dexSwapStrategyId);
IERC20(asset).approve(dexSwapStrategy.dexAdapter, assetAmount);
if (path.length == 0) {
SwapExactInputSinglePayload memory swapCallData = SwapExactInputSinglePayload({
tokenIn: asset,
tokenOut: usdc,
amountIn: assetAmount,
recipient: recipient
});
usdcOut = dexSwapStrategy.executeSwapExactInputSingle(swapCallData);
} else {
SwapExactInputPayload memory swapCallData = SwapExactInputPayload({
path: path,
tokenIn: asset,
tokenOut: usdc,
amountIn: assetAmount,
recipient: recipient
});
usdcOut = dexSwapStrategy.executeSwapExactInput(swapCallData);
}
MarketMakingEngineConfiguration.Data storage marketMakingEngineConfiguration =
MarketMakingEngineConfiguration.load();
uint256 settlementBaseFeeUsd = Collateral.load(usdc).convertUd60x18ToTokenAmount(
ud60x18(marketMakingEngineConfiguration.settlementBaseFeeUsdX18)
);
if (settlementBaseFeeUsd > 0) {
if (usdcOut < settlementBaseFeeUsd) {
revert Errors.FailedToPaySettlementBaseFee();
}
usdcOut -= settlementBaseFeeUsd;
marketMakingEngineConfiguration.distributeProtocolAssetReward(usdc, settlementBaseFeeUsd);
}
}
}
The BaseAdapter
contract incorrectly deducts fees after swap execution, making it vulnerable to price manipulation and execution failures. This violates the CEI (Checks-Effects-Interactions) pattern, leading to potential fund loss and failed swaps due to insufficient balance.
Vulnerability Details
Fee is deducted AFTER the swap executes, meaning an attacker can manipulate the swap to reduce usdcOut
.
If usdcOut < settlementBaseFeeUsd
, the function fails after execution, causing a denial of service (DoS).
A scenario which exploits this :
Attacker manipulates market conditions before the swap executes (e.g., front-running the trade).
-
Swap executes with manipulated pricing, resulting in usdcOut
being lower than expected.
-
Settlement fee deduction happens after execution:
If usdcOut < settlementBaseFeeUsd
, the transaction fails.
If no failure occurs, the attacker benefits from avoiding fees while draining liquidity.
Impact
Failed swaps leading to DoS (Denial of Service)
Loss of protocol revenue
Manipulated Swaps
Potential Insolvency
Tools Used
Manual Review
Recommendations
Deduct the fee BEFORE swapping.