RubiconRouter maxSellAllAmount does not transfer user’s fund into its address, causing calls to always revert
The maxSellAllAmount function in RubiconRouter does not transfer the user's tokens into the router's address before calling the market contract. As a result, the market's attempt to take tokens from the router always fails, causing the function to revert.
Submitted by PP1004, also found by IllIllI
The RubiconRouter function maxSellAllAmount does not transfer user’s fund into its address, causing the function to always revert
Proof of Concept
Since there is no fund transferred into router during the maxSellAllAmount call, it will always revert when RubiconMarket tries to take tokens from it.
Recommended Mitigation Steps
Add a transfer of fund to the function
/// @dev this function takes a user's entire balance for the trade in case they want to do a max trade so there's no leftover dust
function maxSellAllAmount(
ERC20 pay_gem,
ERC20 buy_gem,
uint256 min_fill_amount
) external returns (uint256 fill) {
//swaps msg.sender entire balance in the trade
uint256 maxAmount = ERC20(buy_gem).balanceOf(msg.sender);
ERC20(buy_gem).safeTransferFrom(msg.sender, address(this), maxAmount);
fill = RubiconMarket(RubiconMarketAddress).sellAllAmount(
pay_gem,
maxAmount,
buy_gem,
min_fill_amount
);
ERC20(buy_gem).transfer(msg.sender, fill);
}
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 function omits a safeTransferFrom call to move the user's tokens into the router before invoking the market's sellAllAmount.
Impact
The maxSellAllAmount function is unusable; every call reverts, so users cannot perform a max sell through the router.
What the attacker needed
None
The fix
Add a transfer of the user's tokens into the router before calling the market's sellAllAmount.
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.
A smart contract function is supposed to move a user's tokens into the router contract first, then trade them. Because that first step is missing, the trading step tries to take tokens that are not there, so the whole call fails every time.
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.