In the function _handleERC20Received, the fee was incorrectly charged
The contract incorrectly charged an external swap fee on internal swaps, and when an internal swap failed, the fee was not refunded to the user. This meant users paid an extra fee on internal swaps and lost that fee on failures.
Aamirusmani1552 Follow with Nyx, aman and 6 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-03-woofi-swap-judging/issues/114
Found by
Aamirusmani1552, Nyx, aman, charles__cheerful, hals, mstpr-brainbot, petro1912, yotov721, zraxx
Summary
In the function _handleERC20Received, the fee was incorrectly charged.
Vulnerability Detail
In the contract, when external swap occurs, a portion of the fee will be charged. However, in function _handleERC20Received, the fee is also charged in internal swap.
} else {
// Deduct the external swap fee
uint256 fee = (bridgedAmount * dstExternalFeeRate) / FEE_BASE;
bridgedAmount -= fee; // @@audit: fee should not be applied to internal swap
TransferHelper.safeApprove(bridgedToken, address(wooRouter), bridgedAmount);
if (dst1inch.swapRouter != address(0)) {
try
wooRouter.externalSwap(
At the same time, when the internal swap fails, this part of the fee will not be returned to the user.
Impact
Internal swaps are incorrectly charged, and fees are not refunded when internal swap fail.
Code Snippet
Tool used
Manual Review
Recommendation
Apply fee calculation only to external swaps.
function _handleERC20Received(
uint256 refId,
address to,
address toToken,
address bridgedToken,
uint256 bridgedAmount,
uint256 minToAmount,
Dst1inch memory dst1inch
) internal {
address msgSender = _msgSender();
// ...
} else {
if (dst1inch.swapRouter != address(0)) {
// Deduct the external swap fee
uint256 fee = (bridgedAmount * dstExternalFeeRate) / FEE_BASE;
bridgedAmount -= fee;
TransferHelper.safeApprove(bridgedToken, address(wooRouter), bridgedAmount);
try
wooRouter.externalSwap(
// ...
)
returns (uint256 realToAmount) {
emit WooCrossSwapOnDstChain(
// ...
);
} catch {
bridgedAmount += fee;
TransferHelper.safeTransfer(bridgedToken, to, bridgedAmount);
emit WooCrossSwapOnDstChain(
// ...
);
}
} else {
TransferHelper.safeApprove(bridgedToken, address(wooRouter), bridgedAmount);
try wooRouter.swap(bridgedToken, toToken, bridgedAmount, minToAmount, payable(to), to) returns (
uint256 realToAmount
) {
// ...
} catch {
// ...
}
}
}
}
Discussion
sherlock-admin4
The protocol team fixed this issue in the following PRs/commits: https://github.com/woonetwork/WooPoolV2/pull/112/commits/be8655bf5d9660684eff1e2c12ff5d140fddc474
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
The fee deduction was placed in a code branch that handles both external and internal swaps, instead of only the external swap path.
Impact
Users were overcharged on internal swaps and could lose the fee if the internal swap failed.
What the attacker needed
None
The fix
The fee calculation should be applied only to external swaps, and the fee should be refunded if the external swap fails.
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.
This is a smart contract bug where a fee meant only for swaps that go through an external service was also taken from swaps done internally. So users paid more than they should, and if the internal swap failed, they didn't get that extra fee back.
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.