BringUnusedETHBackIntoGiantPool can cause stuck ether funds in Giant Pool
The function that returns unused ETH from a vault to the Giant Pool does not update the pool's idleETH accounting variable. As a result, the returned ETH becomes permanently stuck because later withdrawals and staking deposits revert due to an underflow in idleETH.
Submitted by koxuan, also found by hihen
https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/GiantMevAndFeesPool.sol#L126-L138 https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/GiantSavETHVaultPool.sol#L137-L158
withdrawUnusedETHToGiantPool will withdraw any eth from the vault if staking has not commenced(knot status is INITIALS_REGISTERED), the eth will be drawn successful to the giant pool. However, idleETH variable is not updated. idleETH is the available ETH for withdrawing and depositing eth for staking. Since there is no other places that updates idleETH other than depositing eth for staking and withdrawing eth, the eth withdrawn from the vault will be stuck forever.
Proof of Concept
Place poc in GiantPools.t.sol with import { MockStakingFundsVault } from "../../contracts/testing/liquid-staking/MockStakingFundsVault.sol";
function testStuckFundsInGiantMEV() public {
stakingFundsVault = MockStakingFundsVault(payable(manager.stakingFundsVault()));
address nodeRunner = accountOne; vm.deal(nodeRunner, 4 ether);
//address feesAndMevUser = accountTwo; vm.deal(feesAndMevUser, 4 ether);
//address savETHUser = accountThree; vm.deal(savETHUser, 24 ether);
address victim = accountFour; vm.deal(victim, 1 ether);
registerSingleBLSPubKey(nodeRunner, blsPubKeyOne, accountFour);
emit log_address(address(giantFeesAndMevPool));
vm.startPrank(victim);
emit log_uint(victim.balance);
giantFeesAndMevPool.depositETH{value: 1 ether}(1 ether);
bytes[][] memory blsKeysForVaults = new bytes[][](1);
blsKeysForVaults[0] = getBytesArrayFromBytes(blsPubKeyOne);
uint256[][] memory stakeAmountsForVaults = new uint256[][](1);
stakeAmountsForVaults[0] = getUint256ArrayFromValues(1 ether);
giantFeesAndMevPool.batchDepositETHForStaking(getAddressArrayFromValues(address(stakingFundsVault)),getUint256ArrayFromValues(1 ether) , blsKeysForVaults, stakeAmountsForVaults);
emit log_uint(victim.balance);
vm.warp(block.timestamp + 60 minutes);
LPToken lp = (stakingFundsVault.lpTokenForKnot(blsKeysForVaults[0][0]));
LPToken [][] memory lpToken = new LPToken[][](1);
LPToken[] memory temp = new LPToken[](1);
temp[0] = lp;
lpToken[0] = temp;
emit log_uint(address(giantFeesAndMevPool).balance);
giantFeesAndMevPool.bringUnusedETHBackIntoGiantPool(getAddressArrayFromValues(address(stakingFundsVault)),lpToken, stakeAmountsForVaults);
emit log_uint(address(giantFeesAndMevPool).balance);
vm.expectRevert();
giantFeesAndMevPool.batchDepositETHForStaking(getAddressArrayFromValues(address(stakingFundsVault)),getUint256ArrayFromValues(1 ether) , blsKeysForVaults, stakeAmountsForVaults);
vm.expectRevert();
giantSavETHPool.withdrawETH(1 ether);
vm.stopPrank();
}
Both withdrawing eth for user and depositing eth to stake fails and reverts as shown in the poc due to underflow in idleETH.
Note that the same problem also exists in GiantSavETHVaultPool, however a poc cannot be done for it as another bug exist in GiantSavETHVaultPool which prevents it from receiving funds as it lacks a receive() or fallback() implementation.
Tools Used
Foundry
Recommended Mitigation Steps
Update idleETH in withdrawUnusedETHToGiantPool
vince0656 (Stakehouse) confirmed
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 withdrawUnusedETHToGiantPool function transfers ETH into the Giant Pool without incrementing the idleETH accounting variable.
Impact
The ETH returned to the Giant Pool becomes stuck forever, and users cannot withdraw or stake ETH from that pool; the same flaw exists in GiantSavETHVaultPool but is currently masked by a separate bug that prevents it from receiving funds.
What the attacker needed
A user deposits ETH into the Giant Pool; the user stakes ETH through the pool; the user calls bringUnusedETHBackIntoGiantPool
The fix
The withdrawUnusedETHToGiantPool function should update idleETH when ETH is returned to the Giant Pool.
How it was found
- A user deposits ETH into the Giant MEV and Fees Pool.
- The user stakes that ETH through the pool into a staking funds vault.
- After some time, the user calls bringUnusedETHBackIntoGiantPool to return the unused ETH to the Giant Pool.
- The ETH arrives in the Giant Pool but idleETH is not updated.
- Attempts to deposit ETH for staking or withdraw ETH then revert due to underflow in idleETH.
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 smart contract keeps a running total of how much ether it thinks it has available, called idleETH. When ether is moved back into the contract from another place, that total is not increased, so the contract's records no longer match reality. Later, when someone tries to take ether out or use it for staking, the contract subtracts from the too-small total, the maths goes negative, and the transaction fails, leaving the ether stuck.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.