Users can fail to unstake and lose their deserved ETH because malfunctioning or untrusted derivative cannot be removed
The protocol has no way to remove a derivative, only to set its weight to zero. If a derivative's external dependency fails or is compromised, unstaking reverts for all users because the unstake loop calls every derivative's withdraw function.
Submitted by rbserver, also found by tnevler, kaden, 0xAgro, Parad0x, bytes032, lukris02, lukris02, P7N8ZK, IgorZuk, DeStinE21, Stiglitz, DadeKuma, J4de, rvierdiiev, koxuan, dec3ntraliz3d, carrotsmuggler, HollaDieWaldfee, and csanuragjain
Calling the following SafEth.adjustWeight function can update the weight for an existing derivative to 0. However, there is no way to remove an existing derivative. If the external contracts that an existing derivative depends on malfunction or get hacked, this protocol’s functionalities that need to loop through the existing derivatives can behave unexpectedly. Users can fail to unstake and lose their deserved ETH as one of the severest consequences.
https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L165-L175
function adjustWeight(
uint256 _derivativeIndex,
uint256 _weight
) external onlyOwner {
weights[_derivativeIndex] = _weight;
uint256 localTotalWeight = 0;
for (uint256 i = 0; i < derivativeCount; i++)
localTotalWeight += weights[i];
totalWeight = localTotalWeight;
emit WeightChange(_derivativeIndex, _weight);
}
For example, calling the following SafEth.unstake function would loop through all of the existing derivatives and call the corresponding derivative’s withdraw function. When the WstEth contract is one of these derivatives, the WstEth.withdraw function would be called, which further calls IStEthEthPool(LIDO_CRV_POOL).exchange(1, 0, stEthBal, minOut). If self.is_killed in the stETH-ETH pool contract corresponding to LIDO_CRV_POOL becomes true, especially after such pool contract becomes compromised or hacked, calling such exchange function would always revert. In this case, calling the SafEth.unstake function reverts even though all other derivatives that are not the WstEth contract are still working fine. Because the SafEth.unstake function is DOS’ed, users cannot unstake and withdraw ETH that they are entitled to.
https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L108-L129
function unstake(uint256 _safEthAmount) external {
require(pauseUnstaking == false, "unstaking is paused");
uint256 safEthTotalSupply = totalSupply();
uint256 ethAmountBefore = address(this).balance;
for (uint256 i = 0; i < derivativeCount; i++) {
// withdraw a percentage of each asset based on the amount of safETH
uint256 derivativeAmount = (derivatives[i].balance() *
_safEthAmount) / safEthTotalSupply;
if (derivativeAmount == 0) continue; // if derivative empty ignore
derivatives[i].withdraw(derivativeAmount);
}
...
}
function withdraw(uint256 _amount) external onlyOwner {
IWStETH(WST_ETH).unwrap(_amount);
uint256 stEthBal = IERC20(STETH_TOKEN).balanceOf(address(this));
IERC20(STETH_TOKEN).approve(LIDO_CRV_POOL, stEthBal);
uint256 minOut = (stEthBal * (10 ** 18 - maxSlippage)) / 10 ** 18;
IStEthEthPool(LIDO_CRV_POOL).exchange(1, 0, stEthBal, minOut);
...
}
https://etherscan.io/address/0xDC24316b9AE028F1497c275EB9192a3Ea0f67022#code#L441
def exchange(i: int128, j: int128, dx: uint256, min_dy: uint256) -> uint256:
...
assert not self.is_killed # dev: is killed
Proof of Concept
The following steps can occur for the described scenario.
- The
WstEthcontract is one of the existing derivatives. For theWstEthcontract, the stETH-ETH pool contract corresponding toLIDO_CRV_POOLhas been hacked in which itsself.is_killedhas been set to true. - Alice calls the
SafEth.unstakefunction but such function call reverts because calling the stETH-ETH pool contract’sexchangefunction reverts for theWstEthderivative. - Although all other derivatives that are not the
WstEthcontract are still working fine, Alice is unable to unstake. As a result, she cannot withdraw and loses her deserved ETH.
Tools Used
VSCode
Recommended Mitigation Steps
The SafEth contract can be updated to add a function, which would be only callable by the trusted admin, for removing an existing derivative that already malfunctions or is untrusted.
toshiSat (Asymmetry) confirmed
Enable/Disable Derivatives.
Status: Mitigation confirmed with comments. Full details in reports from d3e4 (here and here), 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
Likely the design only allows adjusting weights and lacks a function to remove a derivative, so a failing derivative cannot be excluded from the unstake loop.
Impact
Users could be unable to unstake and lose their deserved ETH if a derivative's external dependency is killed or compromised.
What the attacker needed
A derivative's external dependency fails or is hacked; the derivative cannot be removed
The fix
The SafEth contract should add an admin-only function to remove a malfunctioning or untrusted derivative; the project later mitigated this by enabling and disabling derivatives.
How it was found
- The WstEth derivative depends on a stETH-ETH pool whose kill switch is set to true after the pool is hacked.
- Alice calls the unstake function, which loops through all derivatives and calls each withdraw.
- The WstEth withdraw calls the pool's exchange function, which reverts because the pool is killed.
- The whole unstake call reverts, so Alice cannot withdraw her ETH even though other derivatives work.
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.
A derivative is a contract that holds part of the users' money in another token. When users unstake, the protocol asks every derivative to give back its share. If one derivative's outside service breaks, that request fails and the whole unstake fails, so nobody can get their money out.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.