ChiefTrader.sol Wrong implementation of swapExactInput() and swapExactOutput()
Submitted by WatchPug, also found by Meta0xNull
When a caller calls ChiefTrader.sol#swapExactInput(), it will call ITrader(traderAddress).swapExactInput().
return ITrader(traderAddress).swapExactInput(0, amount, recipient, path, options);
However, in the current implementation, inputToken is not approved to the traderAddress.
For example, in UniV3Trader.sol#_swapExactInputSingle, at L89, it tries to transfer inputToken from msg.sender (which is ChiefTrader), since it’s not approved, this will revert.
Plus, the inputToken should also be transferred from the caller before calling the subtrader.
IERC20(input).safeTransferFrom(msg.sender, address(this), amount);
The same problem exists in swapExactOutput():
function swapExactOutput(
uint256 traderId,
uint256 amount,
address,
PathItem[] calldata path,
bytes calldata options
) external returns (uint256) {
require(traderId < _traders.length, TraderExceptionsLibrary.TRADER_NOT_FOUND_EXCEPTION);
_requireAllowedTokens(path);
address traderAddress = _traders[traderId];
address recipient = msg.sender;
return ITrader(traderAddress).swapExactOutput(0, amount, recipient, path, options);
}
Recommendation
Approve the inputToken to the subtrader and transfer from the caller before calling ITrader.swapExactInput() and ITrader.swapExactOutput().
Or maybe just remove support of swapExactInput() and swapExactOutput() in ChiefTrader.
MihanixA (Mellow Protocol) confirmed:
In fact, tokens are approved to the trader https://github.com/code-423n4/2021-12-mellow/blob/6679e2dd118b33481ee81ad013ece4ea723327b5/mellow-vaults/contracts/ERC20Vault.sol#L67 The problem is that
safeTransferFromusesmsg.senderwhich isChiefTraderinstead ofrecipientwhich isERC20Vault.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Mellow Protocol contest. Code4rena made it public on 9 February 2022. Found in the 2021-12-mellow audit contest (finding M-04).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.