code-423n4 / 2023-02-gogopool-mitigation-contest-findings

0 stars 0 forks source link

Mitigation Confirmed for MR-Mitigation of M-10: Issue mitigated #16

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

Since no tests were added to ensure that rewardsStartTime is reset to zero when staking.getAVAXValidatingHighWater(owner) == 0 && staking.getAVAXAssigned(owner) == 0, I have added the missing assertion to improve test coverage, which is a crucial affirmation after all for the ultimate purpose of the mitigated efforts, i.e. resetting rewards start time in cancel minipool:

    function testCancelMinipool() public {
        uint256 duration = 2 weeks;
        uint256 depositAmt = 1000 ether;
        uint256 avaxAssignmentRequest = 1000 ether;
        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();

        //will fail
        vm.expectRevert(MinipoolManager.MinipoolNotFound.selector);
        minipoolMgr.cancelMinipool(address(0));

        //will fail
        vm.expectRevert(MinipoolManager.OnlyOwner.selector);
        minipoolMgr.cancelMinipool(mp1.nodeID);

        //will fail
        int256 minipoolIndex = minipoolMgr.getIndexOf(mp1.nodeID);
        store.setUint(keccak256(abi.encodePacked("minipool.item", minipoolIndex, ".status")), uint256(MinipoolStatus.Error));
        vm.prank(nodeOp);

        //will fail
        vm.expectRevert(MinipoolManager.CancellationTooEarly.selector);
        minipoolMgr.cancelMinipool(mp1.nodeID);

        skip(5 seconds); //cancellation moratorium

        vm.prank(nodeOp);
        vm.expectRevert(MinipoolManager.InvalidStateTransition.selector);
        minipoolMgr.cancelMinipool(mp1.nodeID);
        store.setUint(keccak256(abi.encodePacked("minipool.item", minipoolIndex, ".status")), uint256(MinipoolStatus.Prelaunch));

        vm.startPrank(nodeOp);
        uint256 priorBalance = nodeOp.balance;
        minipoolMgr.cancelMinipool(mp1.nodeID);

        MinipoolManager.Minipool memory mp1Updated = minipoolMgr.getMinipool(minipoolIndex);

        assertEq(mp1Updated.status, uint256(MinipoolStatus.Canceled));
        assertEq(staking.getAVAXStake(mp1Updated.owner), 0);
        assertEq(staking.getAVAXAssigned(mp1Updated.owner), 0);
        assertEq(staking.getAVAXValidating(mp1Updated.owner), 0);
+       assertEq(staking.getRewardsStartTime(mp1Updated.owner), 0);
        assertEq(nodeOp.balance - priorBalance, mp1Updated.avaxNodeOpAmt);
    }
c4-judge commented 1 year ago

GalloDaSballo marked the issue as satisfactory