MinipoolManager: recordStakingError function does not decrease minipoolCount leading to too high GGP rewards for staker
The recordStakingError function fails to decrease the staker's minipoolCount, so after a minipool error the count never reaches zero. This prevents the rewardsStartTime from being reset, allowing the staker to become immediately eligible for rewards when creating a new minipool, instead of waiting the required 14 days.
HollaDieWaldfee Follow with Aymen0909, minhtrng and 11 others
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee, also found by Aymen0909, minhtrng, adriro, sces60107, wagmi, sk8erboy, SmartSek, bin2chen, Allarious, cccz, kaliberpoziomka8552, rvierdiiev, and Saintcode_
The MinipoolManager.recordStakingError function (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L484-L515) does not decrease the minipoolCount of the staker.
This means that if a staker has a minipool that encounters an error, his minipoolCount can never go to zero again.
This is bad because the minipoolCount is used in ClaimNodeOp.calculateAndDistributeRewards to determine if the rewardsStartTime of the staker should be reset (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ClaimNodeOp.sol#L81-L84).
Since the minipoolCount cannot go to zero, the rewardsStartTime will never be reset.
This means that the staker is immediately eligible for rewards when he creates a minipool again whereas he should have to wait rewardsEligibilityMinSeconds before he is eligible (which is 14 days at the moment) (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ClaimNodeOp.sol#L51).
To conclude, failing to decrease the minipoolCount allows the staker to earn higher rewards because he is eligible for staking right after he creates a new minipool and does not have to wait again.
Proof of Concept
I have created the following test that you can add to the MinipoolManager.t.sol file that logs the minipoolCount in the Staking, Error and Finished state.
The minipoolCount is always 1 although it should decrease to 0 when recordStakingError is called.
function testRecordStakingErrorWrongMinipoolCount() public {
uint256 duration = 2 weeks;
uint256 depositAmt = 1000 ether;
uint256 avaxAssignmentRequest = 1000 ether;
uint256 validationAmt = depositAmt + avaxAssignmentRequest;
uint128 ggpStakeAmt = 200 ether;
vm.startPrank(nodeOp);
ggp.approve(address(staking), MAX_AMT);
staking.stakeGGP(ggpStakeAmt);
MinipoolManager.Minipool memory mp1 = createMinipool(depositAmt, avaxAssignmentRequest, duration);
vm.stopPrank();
address liqStaker1 = getActorWithTokens("liqStaker1", MAX_AMT, MAX_AMT);
vm.prank(liqStaker1);
ggAVAX.depositAVAX{value: MAX_AMT}();
vm.prank(address(rialto));
minipoolMgr.claimAndInitiateStaking(mp1.nodeID);
bytes32 txID = keccak256("txid");
vm.prank(address(rialto));
minipoolMgr.recordStakingStart(mp1.nodeID, txID, block.timestamp);
bytes32 errorCode = "INVALID_NODEID";
int256 minipoolIndex = minipoolMgr.getIndexOf(mp1.nodeID);
vm.prank(nodeOp);
// minipool count when in "Staking" state: 1
console.log(staking.getMinipoolCount(nodeOp));
vm.prank(address(rialto));
minipoolMgr.recordStakingError{value: validationAmt}(mp1.nodeID, errorCode);
vm.prank(nodeOp);
// minipool count when in "Error" state: 1
console.log(staking.getMinipoolCount(nodeOp));
vm.prank(address(rialto));
assertEq(vault.balanceOf("MinipoolManager"), depositAmt);
MinipoolManager.Minipool memory mp1Updated = minipoolMgr.getMinipool(minipoolIndex);
vm.prank(address(rialto));
minipoolMgr.finishFailedMinipoolByMultisig(mp1Updated.nodeID);
MinipoolManager.Minipool memory mp1finished = minipoolMgr.getMinipool(minipoolIndex);
vm.prank(nodeOp);
// minipool count when in "Finished" state: 1
console.log(staking.getMinipoolCount(nodeOp));
}
Tools Used
VSCode
Recommended Mitigation Steps
You need to simply add the line staking.decreaseMinipoolCount(owner); to the MinipoolManager.recordStakingError function.
Alex the Entreprenerd (judge) commented:
The Warden has shown how, calling
recordStakingErrorwill not decrease theminipoolCount.This will not only impact view functions but also impact Yield calculations.
For this reason, I agree with Medium Severity.
emersoncloud (GoGoPool) mitigated:
We removed minipool count entirely: multisig-labs/gogopool#42
Status: Mitigation confirmed by RaymondFam and hansfriese.
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 recordStakingError function omits a call to decrease the minipool count, unlike other functions that handle minipool state changes.
Impact
The staker could earn higher rewards because they become eligible for staking rewards immediately after creating a new minipool, without waiting the required 14 days.
What the attacker needed
Staker has a minipool that encounters an error
The fix
The fix was to add a call to decrease the minipool count in recordStakingError, and later the minipool count was removed entirely.
How it was found
- Create a minipool and stake GGP.
- Initiate staking and record staking start.
- Record a staking error for the minipool.
- Observe that the minipool count remains 1 instead of decreasing to 0.
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.
In this staking system, a counter tracks how many minipools a staker has. When a minipool fails, the counter should go down, but it doesn't. Because the counter never reaches zero, the system thinks the staker is still active and lets them earn rewards right away instead of waiting two weeks.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.