Skip to content
Business logic Audit finding Intermediate

NodeOp funds may be trapped by a invalid state transition

The MinipoolManager contract allows a multisig to move a minipool from an error state to a finished state, after which the node operator cannot withdraw their funds because the withdraw function rejects the state transition. An attacker with multisig access could intentionally trap node operators' funds.

0xbepresent Follow with cozzetti, wagmi and 12 others

Originally disclosed on Code4rena

Submitted by 0xbepresent, also found by cozzetti, wagmi, datapunk, sces60107, peritoflores, unforgiven, yixxas, immeas, Ch_301, 0Kage, kaliberpoziomka8552, rvierdiiev, Atarpara, and Manboy

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/MinipoolManager.sol#L528 https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L287

The Multisig can call MinipoolManager.sol::recordStakingError() if there is an error while registering the node as a validator. Also the Multisig can call MinipoolManager.sol::finishFailedMinipoolByMultisig() in order to “finish” the NodeOp’s minipool proccess.

If the Multisig accidentally/intentionally calls recordStakingError() then finishFailedMinipoolByMultisig() the NodeOp funds may be trapped in the protocol.

The finishFailedMinipoolByMultisig() has the next comment: Multisig can move a minipool from the error state to the finished state after a human review of the error but the NodeOp should be able to withdraw his funds after a finished minipool.

Proof of Concept

I created a test for this situation in MinipoolManager.t.sol. At the end you can observe that the withdrawMinipoolFunds() reverts with InvalidStateTransition error:

  1. NodeOp creates the minipool
  2. Rialto calls claimAndInitiateStaking
  3. Something goes wrong and Rialto calls recordStakingError()
  4. Rialto accidentally/intentionally calls finishFailedMinipoolByMultisig() in order to finish the NodeOp’s minipool
  5. The NodeOp can not withdraw his funds. The withdraw function reverts with InvalidStateTransition() error
function testUserFundsStuckErrorFinished() public {
    // NodeOp funds may be trapped by a invalid state transition
    // 1. NodeOp creates the minipool
    // 2. Rialto calls claimAndInitiateStaking
    // 3. Something goes wrong and Rialto calls recordStakingError()
    // 4. Rialto accidentally/intentionally calls finishFailedMinipoolByMultisig() in order
    // to finish the NodeOp's minipool
    // 5. The NodeOp can not withdraw his funds. The withdraw function reverts with
    // InvalidStateTransition() error
    //
    // 1. Create the minipool by the NodeOp
    //
    address liqStaker1 = getActorWithTokens("liqStaker1", MAX_AMT, MAX_AMT);
    vm.prank(liqStaker1);
    ggAVAX.depositAVAX{value: MAX_AMT}();
    assertEq(liqStaker1.balance, 0);
    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), ggpStakeAmt);
    staking.stakeGGP(ggpStakeAmt);
    MinipoolManager.Minipool memory mp = createMinipool(depositAmt, avaxAssignmentRequest, duration);
    vm.stopPrank();
    assertEq(vault.balanceOf("MinipoolManager"), depositAmt);
    //
    // 2. Rialto calls claimAndInitiateStaking
    //
    vm.startPrank(address(rialto));
    minipoolMgr.claimAndInitiateStaking(mp.nodeID);
    assertEq(vault.balanceOf("MinipoolManager"), 0);
    //
    // 3. Something goes wrong and Rialto calls recordStakingError()
    //
    bytes32 errorCode = "INVALID_NODEID";
    minipoolMgr.recordStakingError{value: validationAmt}(mp.nodeID, errorCode);
    // NodeOps funds should be back in vault
    assertEq(vault.balanceOf("MinipoolManager"), depositAmt);
    // 4. Rialto accidentally/intentionally calls finishFailedMinipoolByMultisig() in order
    // to finish the NodeOp's minipool
    minipoolMgr.finishFailedMinipoolByMultisig(mp.nodeID);
    vm.stopPrank();
    // 5. The NodeOp can not withdraw his funds. The withdraw function reverts with
    // InvalidStateTransition() error
    vm.startPrank(nodeOp);
    vm.expectRevert(MinipoolManager.InvalidStateTransition.selector);
    minipoolMgr.withdrawMinipoolFunds(mp.nodeID);
    vm.stopPrank();
}

Tools used

Foundry/Vscode

Recommended Mitigation Steps

The withdrawMinipoolFunds could add another requireValidStateTransition in order to allow the withdraw after the finished minipoool.

emersoncloud (GoGoPool) confirmed

0xju1ie (GoGoPool) disagreed with severity and commented:

I think this should be the primary for the finishFailedMinipoolByMultisig() problem.

Medium feels like a more appropriate severity. This issue depends on rialto multisig improperly functioning but we do intend to fix the finishFailedMinipoolByMultisig method to not lock users out of their funds.

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

The Warden has shown a potential issues with the FSM of the system, per the Audit Scope, the transition should not happen on the deployed system, however, the Warden has shown an issue with the state transition check and has detailed the consequences of it.

For this reason, I agree with Medium Severity.

emersoncloud (GoGoPool) mitigated:

Remove method that trapped Node Operator’s funds: multisig-labs/gogopool#20

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

Impact

Node operators' funds could be permanently trapped in the protocol if the multisig calls the finish function after an error, though this requires the multisig to act improperly.

What the attacker needed

Multisig calls recordStakingError; multisig calls finishFailedMinipoolByMultisig

The fix

The withdrawMinipoolFunds function should be modified to allow withdrawal from the finished state, or the finishFailedMinipoolByMultisig method should be removed; the report states the method was removed as a mitigation.

How it was found

  1. NodeOp creates the minipool
  2. Rialto calls claimAndInitiateStaking
  3. Something goes wrong and Rialto calls recordStakingError()
  4. Rialto accidentally/intentionally calls finishFailedMinipoolByMultisig() in order to finish the NodeOp’s minipool
  5. The NodeOp can not withdraw his funds. The withdraw function reverts with InvalidStateTransition() error

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 operator deposits funds into a minipool. If something goes wrong, a privileged group (the multisig) can mark the minipool as finished. But after that, the operator's withdrawal attempt fails because the contract only allows withdrawals from certain states, and 'finished' is not one of them. So the operator's money stays stuck in the contract.

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.