ERC5095.deposit doesn't check if received shares is less then provided amount
The deposit function in ERC5095 does not verify that the number of shares returned is at least the amount of base tokens deposited. Due to a 1% slippage tolerance, a user could receive fewer shares than they paid, resulting in a loss of funds.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-illuminate-judging/issues/30
Found by
rvierdiiev
Summary
ERC5095.deposit doesn't check if received shares is less then provided amount. In some cases this leads to lost of funds.
Vulnerability Detail
The main thing with principal tokens is to buy them when the price is lower (you can buy 101 token while paying only 100 base tokens) as underlying price and then at maturity time to get interest(for example in one month you will get 1 base token in our case).
ERC5095.deposit function takes amount of base token that user wants to deposit and returns amount of shares that he received. To not have loses, the amount of shares should be at least bigger than amount of base tokens provided by user.
function deposit(address r, uint256 a) external override returns (uint256) {
if (block.timestamp > maturity) {
revert Exception(
21,
block.timestamp,
maturity,
address(0),
address(0)
);
}
uint128 shares = Cast.u128(previewDeposit(a));
Safe.transferFrom(IERC20(underlying), msg.sender, address(this), a);
// consider the hardcoded slippage limit, 4626 compliance requires no minimum param.
uint128 returned = IMarketPlace(marketplace).sellUnderlying(
underlying,
maturity,
Cast.u128(a),
shares - (shares / 100)
);
_transfer(address(this), r, returned);
return returned;
}
While calling market place, you can see that slippage of 1 percent is provided.
uint128 returned = IMarketPlace(marketplace).sellUnderlying(
underlying,
maturity,
Cast.u128(a),
shares - (shares / 100)
);
But this is not enough in some cases.
For example we have ERC5095 token with short maturity which provides 0.5% of interests.
userA calls deposit function with 1000 as base amount. He wants to get back 1005 share tokens. And after maturity time earn 5 tokens on this trade.
But because of slippage set to 1%, it's possible that the price will change and user will receive 995 share tokens instead of 1005, which means that user has lost 5 base tokens.
I propose to add one more mechanism except of slippage. We need to check if returned shares amount is bigger then provided assets amount.
Impact
Lost of funds.
Code Snippet
Provided above.
Tool used
Manual Review
Recommendation
Add this check at the end
require(returned > a, "received less than provided")
Discussion
Evert0x
@sourabhmarathe which severity would you give this? And why?
sourabhmarathe
Low severity on the basis that ultimately, user funds are not at risk in this case. However, it is still worth noting that this issue should be addressed using the recommended changes provided in this report.
Evert0x
Will keep it medium severity as the protocol agrees to fix the issues which can lead to a loss of funds according to the description.
JTraversa
Ehhhh its not quite loss of funds in the way described, but im on the fence with this one.
It kind of seems that this is a discussion about slippage given the "loss" is the same potential marginal loss as the other tickets that discuss slippage within the EIP-5095 interface.
That said, hes correct in saying that crossing the 1:1 ratio would imply a loss which might be good to avoid... And the proposed remediation isnt extremely gas heavy.
Buuut in some other extreme cases there also could be negative APYs? (Look at Europe yo)
E.g. if we did actually implement this, it would mean that we couldnt mechanically operate in a negative yield environment (though i think a lot of stuff would break as well anyways).
If accepted, I'd personally drop it to a low, given the "potential loss" is still a static amount related to the slippage params discussed in other tickets? 🤷
0x00052
Escalate for 1 USDC
Reminder @Evert0x
sherlock-admin
Escalate for 1 USDC
Reminder @Evert0x
You've created a valid escalation for 1 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
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 deposit function relies only on a 1% slippage tolerance and does not enforce that the returned shares exceed the deposited assets.
Impact
A user could lose funds if the price changes and they receive fewer shares than the base tokens they deposited.
What the attacker needed
User deposits into ERC5095; Price changes unfavourably
The fix
Add a check that the returned shares are greater than the deposited amount.
How it was found
- User calls deposit with a base amount.
- The contract calculates shares via previewDeposit.
- It transfers the base tokens from the user.
- It calls sellUnderlying with a minimum shares amount reduced by 1%.
- The returned shares are transferred to the user, possibly less than the deposited amount.
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 deposit tokens into a contract, you expect to get at least as many shares back as the tokens you put in. Here, the contract allows a 1% difference, so you might get slightly fewer shares, meaning you lose money. The fix is to add a check that the returned shares are more than the deposited amount.
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.