Swivel lend method doesn’t pull protocol fee from user
The Swivel lend method adds the order fee to the fees mapping but only pulls the lent amount from the user, not the fee. This causes withdrawFee to fail because it tries to transfer more tokens than the contract holds.
Submitted by kenzo, also found by 0x52, 0xkowloon, cccz, Alex the Entreprenerd, hansfriese, kirk-baird, Metatron, and WatchPug
The Swivel lend method adds to fees[u] the order fee, but does not pull that fee from the user. It only pulls the order-post-fee amount.
Impact
withdrawFee will fail, as it tries to transfer more tokens than are in the contract.
Proof of Concept
The Swivel lend method sums up the fees to totalFee, and the amount to send to Swivel in lent:
totalFee += fee;
// Amount lent for this order
uint256 amountLent = amount - fee;
// Sum the total amount lent to Swivel (amount of ERC5095 tokens to mint) minus fees
lent += amountLent;
It then increments fees[u] by totalFee, but only pulls from the user lent:
fees[u] += totalFee;
// transfer underlying tokens from user to illuminate
Safe.transferFrom(IERC20(u), msg.sender, address(this), lent);
Therefore, totalFee has not been pulled from the user. The fees variable now includes tokens which are not in the contract, and withdrawFee will fail as it tries to transfer fees[u].
Recommended Mitigation Steps
Pull lent + totalFee from the user.
sourabhmarathe (Illuminate) confirmed and commented:
There were several issues that marked this ticket as a high-severity issue. Because the current code does not put user funds at risk (that otherwise would not be spent), we believe this issue is a
Med Riskseverity issue.
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 lend function increments the fees mapping by the total fee but only transfers the lent amount from the user, leaving the fee uncollected.
Impact
withdrawFee will fail because it tries to transfer more tokens than are in the contract; the project considers this a medium risk since user funds are not at risk.
What the attacker needed
User calls lend with a fee; Contract has insufficient balance for fees
The fix
The lend function should pull lent + totalFee from the user.
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.
When you lend tokens, the contract is supposed to take a small fee from you and keep it. But the code only takes the amount you lent, not the fee, so the contract's record of fees is higher than the tokens it actually has. Later, when someone tries to withdraw those fees, the transfer fails because there aren't enough tokens.
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.