Reth.sol : Withdrawals are unreliable and depend on excess RocketDepositPool balance which can brick the whole protocol
The Reth derivative's withdraw function relies on Rocket Pool's burn, which only works when the RocketDepositPool has enough excess ETH. If that excess balance is insufficient, withdrawals fail, so SafEth.unstake and rebalanceToWeights cannot be executed.
HollaDieWaldfee Follow with MiloTruck, d3e4 and 9 others
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee, also found by MiloTruck, d3e4, HHK, 0Kage, 0xRobocop, 0x52, adriro, igingu, Cryptor, carrotsmuggler, and ToonVH
The Asymmetry protocol promises that a user can call SafETH.unstake at all times. What I mean by that is that a user should be able at all times to burn his SafETH tokens and receive ETH in return. This requires that the derivatives held by the protocol can at all times be withdrawn (i.e. converted to ETH).
Also the rebalanceToWeights functionality requires that the derivatives can be withdrawn at all times. If a derivative cannot be withdrawn then the rebalanceToWeights function cannot be executed which means that the protocol cannot be adjusted to use different derivatives.
For the WstEth and SfrxEth derivatives this is achieved by swapping the derivative in a Curve pool for ETH. The liquidity in the respective Curve pool ensures that withdrawals can be processed at all times.
The Reth derivative works differently.
Withdrawals are made by calling the RocketTokenRETH.burn function:
function withdraw(uint256 amount) external onlyOwner {
// @audit this is how rETH is converted to ETH
RocketTokenRETHInterface(rethAddress()).burn(amount);
// solhint-disable-next-line
(bool sent, ) = address(msg.sender).call{value: address(this).balance}(
""
);
require(sent, "Failed to send Ether");
}
The issue with this is that the RocketTokenRETH.burn function only allows for excess balance to be withdrawn. I.e. ETH that has been deposited by stakers but that is not yet staked on the Ethereum beacon chain. So Rocketpool allows users to burn rETH and withdraw ETH as long as the excess balance is sufficient.
The issue is obvious now: If there is no excess balance because enough users burn rETH or the Minipool capacity increases, the Asymmetry protocol is bascially unable to operate.
Withdrawals are then impossible which bricks SafEth.unstake and SafEth.rebalanceToWeights.
Proof of Concept
I show in this section how the current withdrawal flow for the Reth derivative is dependend on there being excess balance in the RocketDepositPool.
The current withdrawal flow calls RocketTokenRETH.burn which executes this code:
function burn(uint256 _rethAmount) override external {
// Check rETH amount
require(_rethAmount > 0, "Invalid token burn amount");
require(balanceOf(msg.sender) >= _rethAmount, "Insufficient rETH balance");
// Get ETH amount
uint256 ethAmount = getEthValue(_rethAmount);
// Get & check ETH balance
uint256 ethBalance = getTotalCollateral();
require(ethBalance >= ethAmount, "Insufficient ETH balance for exchange");
// Update balance & supply
_burn(msg.sender, _rethAmount);
// Withdraw ETH from deposit pool if required
withdrawDepositCollateral(ethAmount);
// Transfer ETH to sender
msg.sender.transfer(ethAmount);
// Emit tokens burned event
emit TokensBurned(msg.sender, _rethAmount, ethAmount, block.timestamp);
}
This executes withdrawDepositCollateral(ethAmount):
function withdrawDepositCollateral(uint256 _ethRequired) private {
// Check rETH contract balance
uint256 ethBalance = address(this).balance;
if (ethBalance >= _ethRequired) { return; }
// Withdraw
RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool"));
rocketDepositPool.withdrawExcessBalance(_ethRequired.sub(ethBalance));
}
This then calls rocketDepositPool.withdrawExcessBalance(_ethRequired.sub(ethBalance)) to get the ETH from the excess balance:
function withdrawExcessBalance(uint256 _amount) override external onlyThisLatestContract onlyLatestContract("rocketTokenRETH", msg.sender) {
// Load contracts
RocketTokenRETHInterface rocketTokenRETH = RocketTokenRETHInterface(getContractAddress("rocketTokenRETH"));
RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault"));
// Check amount
require(_amount <= getExcessBalance(), "Insufficient excess balance for withdrawal");
// Withdraw ETH from vault
rocketVault.withdrawEther(_amount);
// Transfer to rETH contract
rocketTokenRETH.depositExcess{value: _amount}();
// Emit excess withdrawn event
emit ExcessWithdrawn(msg.sender, _amount, block.timestamp);
}
And this function reverts if the excess balance is insufficient which you can see in the require(_amount <= getExcessBalance(), "Insufficient excess balance for withdrawal"); check.
Tools Used
VSCode
Recommended Mitigation Steps
The solution for this issue is to have an alternative withdrawal mechanism in case the excess balance in the RocketDepositPool is insufficient to handle the withdrawal.
The alternative withdrawal mechanism is to sell the rETH tokens via the Uniswap pool.
You can use the RocketDepositPool.getExcessBalance to check if there is sufficient excess ETH to withdraw from Rocketpool or if the withdrawal must be made via Uniswap.
The pseudocode of the new withdraw flow looks like this:
function withdraw(uint256 amount) external onlyOwner {
if (rocketDepositPool excess balance is sufficient) {
RocketTokenRETHInterface(rethAddress()).burn(amount);
// solhint-disable-next-line
(bool sent, ) = address(msg.sender).call{value: address(this).balance}(
""
);
require(sent, "Failed to send Ether");
} else {
// swap rETH for ETH via Uniswap pool
}
}
I also wrote the code for the changes that I suggest:
diff --git a/contracts/SafEth/derivatives/Reth.sol b/contracts/SafEth/derivatives/Reth.sol
index b6e0694..b699d5c 100644
--- a/contracts/SafEth/derivatives/Reth.sol
+++ b/contracts/SafEth/derivatives/Reth.sol
@@ -105,11 +105,24 @@ contract Reth is IDerivative, Initializable, OwnableUpgradeable {
@notice - Convert derivative into ETH
*/
function withdraw(uint256 amount) external onlyOwner {
- RocketTokenRETHInterface(rethAddress()).burn(amount);
- // solhint-disable-next-line
- (bool sent, ) = address(msg.sender).call{value: address(this).balance}(
- ""
- );
+ if (canWithdrawFromRocketPool(amount)) {
+ RocketTokenRETHInterface(rethAddress()).burn(amount);
+ // solhint-disable-next-line
+ } else {
+
+ uint256 minOut = ((((poolPrice() * amount) / 10 ** 18) *
+ ((10 ** 18 - maxSlippage))) / 10 ** 18);
+
+ IWETH(W_ETH_ADDRESS).deposit{value: msg.value}();
+ swapExactInputSingleHop(
+ rethAddress(),
+ W_ETH_ADDRESS,
+ 500,
+ amount,
+ minOut
+ );
+ }
+ (bool sent, ) = address(msg.sender).call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
}
@@ -149,6 +162,21 @@ contract Reth is IDerivative, Initializable, OwnableUpgradeable {
_amount >= rocketDAOProtocolSettingsDeposit.getMinimumDeposit();
}
+ function canWithdrawFromRocketPool(uint256 _amount) private view returns (bool) {
+ address rocketDepositPoolAddress = RocketStorageInterface(
+ ROCKET_STORAGE_ADDRESS
+ ).getAddress(
+ keccak256(
+ abi.encodePacked("contract.address", "rocketDepositPool")
+ )
+ );
+ RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(
+ rocketDepositPoolAddress
+ );
+ uint256 _ethAmount = RocketTokenRETHInterface(rethAddress()).getEthValue(_amount);
+ return rocketDepositPool.getExcessBalance() >= _ethAmount;
+ }
+
toshiSat (Asymmetry) confirmed, but disagreed with severity and commented:
The deposit pool is mostly always full, but the warden does have a point and we should allow for multiple options.
Check if withdraw from deposit contract possible.
Status: Sub-optimally mitigated. Full details in reports from d3e4, adriro, and 0x52.
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 withdraw function only uses Rocket Pool's burn mechanism, which depends on the RocketDepositPool having sufficient excess balance, with no fallback to another liquidity source.
Impact
Withdrawals could become impossible, which would brick SafEth.unstake and SafEth.rebalanceToWeights; the protocol team noted the deposit pool is mostly always full, so the condition may be rare.
What the attacker needed
RocketDepositPool excess balance is insufficient
The fix
The withdrawal flow should check whether Rocket Pool has enough excess balance and, if not, sell the rETH via a Uniswap pool instead; the team later added such a check but the mitigation was judged sub-optimal.
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 unstake, the protocol must turn its rETH tokens back into ETH. It does this by asking Rocket Pool to burn the rETH, but Rocket Pool only pays out from ETH that is sitting idle and not yet staked. If that idle pool is empty, the burn fails and users cannot get their ETH back.
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.