Functions cancelMinipool() doesn’t reset the value of the RewardsStartTime for user when user’s minipoolcount is zero
The cancelMinipool function does not reset the RewardsStartTime for a node runner when their minipool count reaches zero, allowing a node runner to cancel a minipool and later create a new one near the end of a reward cycle while still being eligible for rewards. This can lead to incorrect reward distribution, as the node runner may not have run a validation node for the required minimum time.
unforgiven Follow with caventa and rvierdiiev
Originally disclosed on Code4rena
Submitted by unforgiven, also found by caventa and rvierdiiev
https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L271-L283 https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L642-L665
The value of RewardsStartTime shows when node runner started the minipool and validation rewards are generated by node runner. it is used to see if node runners are eligible for ggp rewards or not and node runners should run their node for minimum amount of time during the rewarding cycle to be eligible for rewards. but right now node runner can create a mimipool and cancel it (after waiting time) and even so the minipool generated no rewards and cancelled the value of RewardsStartTime won’t get reset for node runner and in the end of the cycle node runner would be eligible for rewards (node runner can create another minipool near the end of cycle). so this issue would cause wrong reward distribution between node runners and code doesn’t correctly track RewardsStartTime for node runners and malicious node runners can use this issue and receive rewards without running validation nodes for the minimum amount of required time.
Proof of Concept
This is cancelMinipool() and _cancelMinipoolAndReturnFunds() code:
function cancelMinipool(address nodeID) external nonReentrant {
Staking staking = Staking(getContractAddress("Staking"));
ProtocolDAO dao = ProtocolDAO(getContractAddress("ProtocolDAO"));
int256 index = requireValidMinipool(nodeID);
onlyOwner(index);
// make sure they meet the wait period requirement
if (block.timestamp - staking.getRewardsStartTime(msg.sender) < dao.getMinipoolCancelMoratoriumSeconds()) {
revert CancellationTooEarly();
}
_cancelMinipoolAndReturnFunds(nodeID, index);
}
function _cancelMinipoolAndReturnFunds(address nodeID, int256 index) private {
requireValidStateTransition(index, MinipoolStatus.Canceled);
setUint(keccak256(abi.encodePacked("minipool.item", index, ".status")), uint256(MinipoolStatus.Canceled));
address owner = getAddress(keccak256(abi.encodePacked("minipool.item", index, ".owner")));
uint256 avaxNodeOpAmt = getUint(keccak256(abi.encodePacked("minipool.item", index, ".avaxNodeOpAmt")));
uint256 avaxLiquidStakerAmt = getUint(keccak256(abi.encodePacked("minipool.item", index, ".avaxLiquidStakerAmt")));
Staking staking = Staking(getContractAddress("Staking"));
staking.decreaseAVAXStake(owner, avaxNodeOpAmt);
staking.decreaseAVAXAssigned(owner, avaxLiquidStakerAmt);
staking.decreaseMinipoolCount(owner);
emit MinipoolStatusChanged(nodeID, MinipoolStatus.Canceled);
Vault vault = Vault(getContractAddress("Vault"));
vault.withdrawAVAX(avaxNodeOpAmt);
owner.safeTransferETH(avaxNodeOpAmt);
}
As you can see there is no check that user’s minipool count is zero and if it is to reset the value of RewardsStartTime for user so if a user creates a minipool in the start of the cycle and then cancel it after 5 days and wait for end of the cycle and start another minipool and increase his staking AVAX he would be eligible for ggp rewards (ClaimNodeOp.isEligible() would return true for that user even so the user didn’t run node for the required amount of time in the cycle). these are the steps to exploit this:
- node runner would create a minipool near start time of the ggp rewarding cycle and the value of
RewardsStartTimewould set for node runner. - after 5 days that node runner’s minipool has not been launched by multisig (for any reason) node runner would call
cancelMinipool()and code would cancel his minipool but won’t resetRewardsStartTimefor node runner. - after 20 days and near end of the gpp reward cycle node runner would create another minipool and start running node.
- in the end even so node runner only start running node and earning reward near end of the reward cycle but code would count node runner as eligible for rewards because
RewardsStartTimefor node runner shows wrong value.
This bug would cause rewards to be distributed wrongly between node runners and malicious node runners can bypass required time for running nodes during reward cycle to be eligible for rewards.
Tools Used
VIM
Recommended Mitigation Steps
Set the value of RewardsStartTime based on successfully finished minipools or when minipool is launched and user can’t cancel minipool.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The Warden has shown how, due to
cancelMinipoolnot resettingrewardsStartTimea pool owner could receive rewards for time in which they did not have any activePool.Because this is contingent on the Multisig not cancelling the pool and because it would limit the attack to rewards, I believe Medium Severity to be the most appropriate.
emersoncloud (GoGoPool) mitigated:
Reset rewards start time in cancel minipool: multisig-labs/gogopool#51
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 cancelMinipool function does not reset the RewardsStartTime when a node runner's minipool count becomes zero, so the timestamp from a previous minipool persists.
Impact
This could cause rewards to be distributed incorrectly, allowing a malicious node runner to receive rewards without running a validation node for the minimum required time; the attack is contingent on the multisig not cancelling the pool.
What the attacker needed
Node runner with a minipool; multisig does not launch the minipool; wait for cancellation moratorium
The fix
The RewardsStartTime should be reset when a minipool is cancelled and the node runner's minipool count becomes zero, or set based on successfully finished minipools or when the minipool is launched.
How it was found
- Create a minipool near the start of the reward cycle, which sets RewardsStartTime.
- After 5 days, cancel the minipool; RewardsStartTime is not reset.
- After 20 days, near the end of the cycle, create another minipool and start running a node.
- At the end of the cycle, the node runner is considered eligible for rewards despite not running a node for the required time.
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 node runner is someone who runs a computer to validate transactions on a blockchain. They can earn rewards for doing this, but only if they run their node for a minimum amount of time. The code tracks when they started running a node using a timestamp called RewardsStartTime. The bug is that if a node runner cancels their node, this timestamp is not reset, so they can later start a new node and still get rewards as if they had been running the whole time.
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.