First 1 wei deposit can produce loss of user xETH funds in wxETH
The wxETH stake function allows deposits that mint zero shares, so a user can lose their xETH. An attacker can make the first tiny deposit and then, due to the contract's dripping of rewards, cause later depositors to receive no shares for their funds.
carlitox477 Follow with d3e4
Originally disclosed on Code4rena
Submitted by carlitox477, also found by d3e4
The present implementation of the wxETH::stake functions permits the sending of tokens to the contract, even if the quantity of wxETH is zero. This can result in users losing funds, particularly when the initial deposit is only 1 wei, and the extent to which xETH is dripped (alongside its dripping period) is taken into consideration.
The issue arises when xETHAmount * BASE_UNIT) < exchangeRate() during the second deposit.
There is a potential risk of losing funds in certain feasible scenarios due to the incorrect handling of round-down situations.
Proof of Concept
Here a coded POC that shows what would happen if:
- The protocol wants to drip 70 xETH in its first week as a way of promotion
- Alice realized this and decided to make the first deposit (by frontrunning every other deposits)
- The second deposit of $104166666666666601; wei$ happens 15 minutes after Alice’s deposit
Here’s the output of the coded POC:
Logs:
Min amount to deposit to get a single share: 104166666666666601 wei
Bob xETH before staking: 104166666666666600
Bob wxETH after staking balance 0
Other scenarios
Here are the numbers of other scenario:
| 1 eth in 1 year | | 10 eth in 1 year | | 100 eth in 1 year | | 1000 eth in 1 year | |
Time until second deposit | Min amount to deposit (ETH) | Value(USD) | Min amount to deposit | Value(USD) | Min amount to deposit | Value(USD) | Min amount to deposit | Value(USD) |
1 minute | 0,000001902587519 | 0,003424657534 | 0,00001902587519 | 0,03424657534 | 0,0001902587519 | 0,3424657534 | 0,001902587519 | 3,424657534 |
15 minutes | 0,00002853881279 | 0,05136986301 | 0,0002853881279 | 0,5136986301 | 0,002853881279 | 5,136986301 | 0,02853881279 | 51,36986301 |
1 hour | 0,0001141552511 | 0,2054794521 | 0,001141552511 | 2,054794521 | 0,01141552511 | 20,54794521 | 0,1141552511 | 205,4794521 |
24 hours | 0,002739726027 | 4,931506849 | 0,02739726027 | 49,31506849 | 0,2739726027 | 493,1506849 | 2,739726027 | 4931,506849 |
1 week | 0,01917808219 | 34,52054795 | 0,1917808219 | 345,2054795 | 1,917808219 | 3452,054795 | 19,17808219 | 34520,54795 |
| 70 eth in 1 week | |
Time until second deposit | Min amount to deposit (ETH) | Value(USD) |
1 minute | 0,006944444444 | 12,5 |
15 minutes | 0,1041666667 | 187,5 |
1 hour | 0,4166666667 | 750 |
Mitigation steps
Check mintAmount > 0 in function wxETH::stake. This means:
function stake(uint256 xETHAmount) external drip returns (uint256) {
/// @dev calculate the amount of wxETH to mint
uint256 mintAmount = previewStake(xETHAmount);
+ if (mintAmount == 0){
+ revert ERROR_MINTING_0_SHARES();
+ }
/// @dev transfer xETH from the user to the contract
xETH.safeTransferFrom(msg.sender, address(this), xETHAmount);
/// @dev emit event
emit Stake(msg.sender, xETHAmount, mintAmount);
/// @dev mint the wxETH to the user
_mint(msg.sender, mintAmount);
return mintAmount;
}
I don’t think this and it’s duplicates are all one issue, but two different issues. One issue is the standard inflation attack by transferring tokens directly to the contract. This is described by #4, #21 and #22. The other issue is the one described in #3 and #24. There the inflation is instead caused by the contract itself, by dripping, which is another loophole that may be exploited even if the vulnerability causing the inflation attack is patched.
vaporkane (xETH) acknowledged, but disagreed with severity
kirk-baird (judge) decreased severity to Medium and commented:
@d3e4 - I agree with this comment that these attacks are different enough to warrant separate issues.
Further, since these attacks can only be executed by the very first staker and there is only a single exchange rate the likelihood of attack is very low. I’m therefore downgrading the severity to medium.
Additionally, the chance of the drip attack is extremely low since the user would need to be the only staker for an extended period of time. This borders between a low and medium severity but I will generously consider it medium in this case.
Don’t allow minting of 0 shares.
PR: https://github.com/code-423n4/2023-05-xeth/commit/fbb29727ce21857f60c1c94fff43c73b4124a4b4
Status: Not fully mitigated. Full details in reports from ronnyx2017 and d3e4, and also included in the Mitigation Review section below.
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
Likely the stake function does not check that the calculated mint amount is greater than zero, so rounding down can result in zero shares being minted while tokens are still transferred.
Impact
A later depositor could lose their entire xETH deposit because they receive zero wxETH shares, but the attack requires being the very first staker and the only staker for an extended period, making it unlikely.
What the attacker needed
Attacker is the first depositor; attacker remains the only staker for a period; protocol is dripping rewards
The fix
The stake function should revert if the calculated mint amount is zero, and this was partially mitigated but not fully.
How it was found
- The protocol drips 70 xETH in the first week as a promotion.
- Alice front-runs all other deposits and makes the first deposit of 1 wei.
- A second deposit of about 0.104 xETH occurs 15 minutes after Alice's deposit.
- The second depositor receives zero wxETH shares for their xETH.
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 put money into a savings contract, you normally get shares representing your deposit. Here, the contract could give you zero shares for a small deposit, meaning your money is taken but you get nothing back. An attacker can set things up so that later users are the ones who lose out.
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.