GiantMevAndFeesPool.previewAccumulatedETH function: “accumulated” variable is not updated correctly in for loop leading to result that is too low
Submitted by aphak5010, also found by datapunk, Trust, Aymen0909, and zaskoh
https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantMevAndFeesPool.sol#L82 https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantMevAndFeesPool.sol#L91
The GiantMevAndFeesPool.previewAccumulatedETH function (https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantMevAndFeesPool.sol#L82) allows to view the ETH that is accumulated by an address.
However the formula is not correct.
In each iteration of the foor loop, accumulated is assigned a new value (https://github.com/code-423n4/2022-11-stakehouse/blob/4b6828e9c807f2f7c569e6d721ca1289f7cf7112/contracts/liquid-staking/GiantMevAndFeesPool.sol#L91) when actually the value should be updated like this:
accumulated += StakingFundsVault(payable(_stakingFundsVaults[i])).batchPreviewAccumulatedETH(
address(this),
_lpTokens[i]
);
Obviously the accumulated value must be calculated for all stakingFundVaults not only for one stakingFundsVault.
While this calculation is not used internally by the contract, it will cause any third-party contract that relies on this calculation to behave incorrectly.
For example a third party smart contract might only allow users to withdraw once the value returned by previewAccumulatedETH reaches a certain threshold. Because of the issue however the accumulated ETH value that is returned will always be too low.
Tools Used
VSCode
Recommended Mitigation Steps
Fix:
@@ -88,7 +88,7 @@ contract GiantMevAndFeesPool is ITransferHookProcessor, GiantPoolBase, Syndicate
uint256 accumulated;
for (uint256 i; i < _stakingFundsVaults.length; ++i) {
- accumulated = StakingFundsVault(payable(_stakingFundsVaults[i])).batchPreviewAccumulatedETH(
+ accumulated += StakingFundsVault(payable(_stakingFundsVaults[i])).batchPreviewAccumulatedETH(
address(this),
_lpTokens[i]
);
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.
What is known
A medium-severity smart contracts bug in LSD Network - Stakehouse contest. Code4rena made it public on 20 January 2023. Found in the 2022-11-stakehouse audit contest (finding M-15), also found by 4 other wardens.
About Smart contracts
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.