Withdrawals of rebasing tokens can lead to insolvency and unfair distribution of protocol reserves
The WithdrawQueue contract records a fixed stETH amount for withdrawals, but stETH is a rebasing token whose balance can change. If a negative rebasing event occurs, users who claim early receive more than their fair share, later claims may fail, and the protocol can become insolvent.
LessDupes Follow with SBSecurity, peanuts and 3 others
Originally disclosed on Code4rena
*Submitted by [LessDupes](https://github.com/code-423n4/2024-04-renzo-findings/issues/282), also found by [SBSecurity](https://github.com/code-423n4/2024-04-renzo-findings/issues/599), [peanuts](https://github.com/code-423n4/2024-04-renzo-findings/issues/467), guhu95 ([1](https://github.com/code-423n4/2024-04-renzo-findings/issues/466), [2](https://github.com/code-423n4/2024-04-renzo-findings/issues/285)), [bill](https://github.com/code-423n4/2024-04-renzo-findings/issues/290), [ilchovski](https://github.com/code-423n4/2024-04-renzo-findings/issues/289), and [RamenPeople](https://github.com/code-423n4/2024-04-renzo-findings/issues/288)*
The [`WithdrawQueue`](https://github.com/code-423n4/2024-04-renzo/blob/main/contracts/Withdraw/WithdrawQueue.sol) contract allows users to withdraw their funds in various tokens, including liquid staking derivatives (LSDs) such as stETH. The [`withdraw()`](https://github.com/code-423n4/2024-04-renzo/blob/main/contracts/Withdraw/WithdrawQueue.sol#L206) function calculates the amount of the specified `_assetOut` token equivalent to the ezETH being withdrawn [using](https://github.com/code-423n4/2024-04-renzo/blob/main/contracts/Withdraw/WithdrawQueue.sol#L229) the `renzoOracle.lookupTokenAmountFromValue()` function. This amount is then stored in the `amountToRedeem` field of a new `WithdrawRequest` struct, which is added to the user’s `withdrawRequests` array and the token’s `claimReserve`.
When the user later calls [`claim()`](https://github.com/code-423n4/2024-04-renzo/blob/main/contracts/Withdraw/WithdrawQueue.sol#L279), the contract transfers the `amountToRedeem` to the user via the [`IERC20.transfer()`](https://github.com/code-423n4/2024-04-renzo/blob/main/contracts/Withdraw/WithdrawQueue.sol#L305) function.
However, this implementation does not properly handle rebasing tokens like stETH. The stETH balance of the `WithdrawQueue` can change between the time a withdrawal is recorded and when it is claimed, even though the contract’s stETH shares remain constant.
If the stETH balance decreases during this period due to a rebasing event (e.g., a slashing of the staked ETH), the `amountToRedeem` stored in the `WithdrawRequest` may exceed the contract’s actual stETH balance at the time of claiming. As a result, the withdrawal can fail or result in the user receiving a larger share of the total protocol reserves than intended.
The issue can be illustrated by comparing the behavior of withdrawals for non-rebasing and rebasing LSDs:
1. Non-rebasing LSD (e.g., wBETH):
- User A requests a withdrawal of 10 wBETH (worth 10 ETH) from the protocol.
- While the withdrawal is pending, wBETH’s underlying staked ETH suffers a 50% slashing event.
- The price of wBETH drops to 0.5 ETH per token due to the slashing.
- When User A claims their withdrawal, they receive 10 wBETH, which is now worth only 5 ETH.
- User A bears the loss from the slashing event.
2. Rebasing LSD (e.g., stETH):
- User B requests a withdrawal of 10 stETH (worth 10 ETH) from the protocol.
- While the withdrawal is pending, the underlying staked ETH suffers a 50% slashing event.
- Everyone’s stETH balances are rebased to maintain the ETH peg, so the protocol’s stETH balance is halved.
- When User B claims their withdrawal, they receive the original 10 stETH (still worth 10 ETH) as recorded in the withdrawal request.
- The protocol bears the loss from the slashing event, as it has sent out more than its fair share of the rebased stETH balance.
### Impact
The current withdrawal mechanism for rebasing tokens like stETH can lead to:
- **Unfair distribution of funds:** Users who claim their withdrawals after a rebasing event that decreases the contract’s balance will receive a larger share of the reserves than intended, at the expense of other users.
- **Withdrawal failures:** If the contract’s balance falls below the total `amountToRedeem` of all pending withdrawals due to rebasing, users will face transaction failures when attempting to claim their withdrawals.
### Proof of Concept
We can validate the vulnerability through a Foundry test case POC. This test case will simulate the exploit scenario and confirm the issue by performing the following actions:
1. Alice and Bob initiate withdrawals of their ezETH shares for stETH.
2. Simulate a negative rebasing event by transferring 10% of stETH balance from the `withdrawQueue` contract.
3. Alice claims her withdrawal successfully, receiving her original stETH amount.
4. Bob’s attempt to claim his withdrawal fails due to insufficient stETH balance.
5. Verify that ezETH supply remains unchanged while TVL is significantly reduced, demonstrating ezETH becoming uncollateralized.
The PoC can be run in Foundry by using the setup and mock infra provided [here](https://gist.github.com/3docSec/a4bc6254f709a6218907a3de370ae84e).
```
pragma solidity ^0.8.19;
import "contracts/Errors/Errors.sol";
import "./Setup.sol";
contract H6 is Setup {
function testH6() public {
// we set the buffer to something reasonably high
WithdrawQueueStorageV1.TokenWithdrawBuffer[] memory buffers = new WithdrawQueueStorageV1.TokenWithdrawBuffer[](2);
buffers[0] = WithdrawQueueStorageV1.TokenWithdrawBuffer(address(stETH), 100e18 - 1);
buffers[1] = WithdrawQueueStorageV1.TokenWithdrawBuffer(address(cbETH), 100e18 - 1);
vm.startPrank(OWNER);
withdrawQueue.updateWithdrawBufferTarget(buffers);
// we'll be using stETH and cbETH with unitary price for simplicity
stEthPriceOracle.setAnswer(1e18);
cbEthPriceOracle.setAnswer(1e18);
// and we start with 0 TVL
(, , uint tvl) = restakeManager.calculateTVLs();
assertEq(0, tvl);
// let's then imagine that Alice and Bob hold 90 and 10 ezETH each
address alice = address(1234567890);
address bob = address(1234567891);
stETH.mint(alice, 100e18);
vm.startPrank(alice);
stETH.approve(address(restakeManager), 100e18);
restakeManager.deposit(IERC20(address(stETH)), 100e18);
ezETH.transfer(bob, 10e18);
// �
TVL and balance are as expected
(, , tvl) = restakeManager.calculateTVLs();
assertEq(100e18, tvl);
assertEq(90e18, ezETH.balanceOf(alice));
assertEq(10e18, ezETH.balanceOf(bob));
// Now Bob initiates withdrawal of their shares
vm.startPrank(bob);
ezETH.approve(address(withdrawQueue), 10e18);
withdrawQueue.withdraw(10e18, address(stETH));
// Alice, too, initiates withdrawal of their shares
vm.startPrank(alice);
ezETH.approve(address(withdrawQueue), 90e18 - 1);
withdrawQueue.withdraw(90e18 - 1, address(stETH));
// ☢️ time passes, and an stETH negative rebasing happens, wiping
// 10% of the balance
vm.startPrank(address(withdrawQueue));
stETH.transfer(address(1), 10e18);
vm.warp(block.timestamp + 10 days);
// 🚨 now, since WithdrawQueue checked availability at withdrawal initiation
// only and didn not account for the possibility of rebases, the 10% loss
// has been completely dodged by Alice and is attributed to the last
// user exiting.
vm.startPrank(alice);
withdrawQueue.claim(0);
assertEq(90e18 - 1, stETH.balanceOf(alice));
// 🚨 not only Bob can't withdraw
vm.startPrank(bob);
vm.expectRevert();
withdrawQueue.claim(0);
// 🚨 but ezETH as a whole also became completely uncollateralized
assertEq(10e18 + 1, ezETH.totalSupply());
(, , tvl) = restakeManager.calculateTVLs();
assertEq(1, tvl);
}
}
```
### Recommended Mitigation Steps
To address the issue of unfair distribution of funds when withdrawing rebasing tokens like stETH, the `WithdrawQueue` contract should store and transfer the user’s withdrawal as stETH shares instead of a fixed stETH amount.
When a user initiates a withdrawal with stETH as the `_assetOut`, the contract should convert the calculated `amountToRedeem` to stETH shares using the `stETH.getSharesByPooledEth()` function:
```
uint256 sharesAmount = IStETH(stETHAddress).getSharesByPooledEth(amountToRedeem);
```
The resulting `sharesAmount` should be stored in the `WithdrawRequest` struct instead of the `amountToRedeem`.
When the user calls `claim()`, the contract should transfer the stETH shares directly to the user using the `stETH.transferShares()` function:
```
IStETH(stETHAddress).transferShares(msg.sender, sharesAmount);
```
By storing and transferring stETH shares instead of a fixed stETH amount, the contract ensures that each user receives their fair share of the stETH balance, regardless of any rebasing events that occur between the time of the withdrawal request and the claim.
To implement this mitigation, the contract should:
1. Check if the `_assetOut` is stETH when processing a withdrawal request.
2. If so, convert the `amountToRedeem` to stETH shares using `stETH.getSharesByPooledEth()` and store the shares amount in the `WithdrawRequest` struct.
3. Update the `claim()` function to check if the withdrawal is in stETH and, if so, transfer the shares directly using `stETH.transferShares()` instead of using the standard `IERC20.transfer()` function.
Note that this mitigation is specific to stETH and may need to be adapted for other rebasing tokens that use a similar shares-based system.
Furthermore, the `claimReserve` and `withdrawalBufferTarget` for stETH would also need to be stored in shares and converted to underlying in TVL and withdraw buffer calculations, respectively.
**[alcueca (judge) commented](https://github.com/code-423n4/2024-04-renzo-findings/issues/282#issuecomment-2133000450):**
> I’m going to sustain the high severity on the grounds that:
>
>
>
> - If the stEth balance increases, as it normally does, users lose value in comparison to non-rebasing LSTs.
> - If the stEth balance decreases, the protocol loses value in comparison to non-rebasing LSTs.
> - If the stEth balance decreases, the protocol might DoS.
>
>
>
> The users that win in a slashing event are not the same users that lose during normal operation.
**[jatinj615 (Renzo) acknowledged](https://github.com/code-423n4/2024-04-renzo-findings/issues/282#event-13024907465)**
---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 contract stores a fixed amount of a rebasing token instead of its shares, so the recorded amount does not adjust when the token's balance changes.
Impact
Users who claim after a negative rebasing event may receive more than their fair share, later claims can fail, and the protocol may become insolvent; the judge also noted that if the stETH balance increases, users lose value compared to non-rebasing tokens.
What the attacker needed
StETH is used as withdrawal asset; a negative rebasing event occurs; pending withdrawals exist
The fix
The contract should store and transfer stETH shares instead of a fixed stETH amount, converting at withdrawal and claim time.
How it was found
- Alice and Bob each deposit stETH and receive ezETH, then both request withdrawals in stETH.
- A negative rebasing event reduces the WithdrawQueue's stETH balance by 10%.
- Alice claims her withdrawal and receives the full originally recorded stETH amount.
- Bob's claim fails because the contract no longer has enough stETH.
- The total value locked drops to almost zero while ezETH supply remains unchanged, showing the protocol is uncollateralised.
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.
Some tokens, like stETH, automatically adjust each holder's balance when the underlying staked amount changes. The contract saved a fixed number of tokens for each withdrawal, so when the balance shrank, early users still got the old larger amount. That left too little for later users and made the protocol's total assets worth less than its debts.
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.