State Transition: Minipools can be created using other operator’s AVAX deposit via recreateMinipool
The recreateMinipool function allowed a minipool to be recreated without the node operator's AVAX deposit, because the deposit had already been withdrawn in the Finished state. This could let a minipool be launched using AVAX from other minipools, preventing those other minipools from launching.
hansfriese Follow with bin2chen, 0xdeadbeef0x and 20 others
Originally disclosed on Code4rena
Submitted by hansfriese, also found by bin2chen, 0xdeadbeef0x, Aymen0909, datapunk, Allarious, RaymondFam, adriro, peritoflores, wagmi, Jeiwan, SmartSek, betweenETHlines, immeas, Franfran, Nyx, Ch_301, 0xdeadbeef0x, HollaDieWaldfee, RaymondFam, cccz, 0Kage, and kaliberpoziomka8552
This issue is related to state transition of Minipools. According to the implementation, the possible states and transitions are as below.
The Rialto may call recreateMinipool when the minipool is in states of Withdrawable, Finished, Error, Canceled.
The problem is that these four states are not the same in the sense of holding the node operator’s AVAX.
If the state flow has followed Prelaunch->Launched->Staking->Error, all the AVAX are still in the vault.
If the state flow has followed Prelaunch->Launched->Staking->Error->Finished (last transition by withdrawMinipoolFunds), all the AVAX are sent back to the node operator.
So if the Rialto calls recreateMinipool for the second case, there are no AVAX deposited from the node operator at that point but there can be AVAX from other mini pools in the state of Prelaunch.
Because there are AVAX in the vault (and these are not managed per staker base), recreatePool results in a new mini pool in Prelaunch state and it is further possible to go through the normal flow Prelaunch->Launched->Staking->Withdrawable->Finished.
And the other minipool that was waiting for launch will not be able to launch because the vault is lack of AVAX.
Below is a test case written to show an example.
function testAudit() public {
uint256 duration = 2 weeks;
uint256 depositAmt = 1000 ether;
uint256 avaxAssignmentRequest = 1000 ether;
uint256 validationAmt = depositAmt + avaxAssignmentRequest;
uint128 ggpStakeAmt = 200 ether;
// Node Op 1
vm.startPrank(nodeOp);
ggp.approve(address(staking), MAX_AMT);
staking.stakeGGP(ggpStakeAmt);
MinipoolManager.Minipool memory mp1 = createMinipool(
depositAmt,
avaxAssignmentRequest,
duration
);
vm.stopPrank();
// Node Op 2
address nodeOp2 = getActorWithTokens("nodeOp2", MAX_AMT, MAX_AMT);
vm.startPrank(nodeOp2);
ggp.approve(address(staking), MAX_AMT);
staking.stakeGGP(ggpStakeAmt);
MinipoolManager.Minipool memory mp2 = createMinipool(
depositAmt,
avaxAssignmentRequest,
duration
);
vm.stopPrank();
int256 minipoolIndex = minipoolMgr.getIndexOf(mp1.nodeID);
address liqStaker1 = getActorWithTokens("liqStaker1", MAX_AMT, MAX_AMT);
vm.prank(liqStaker1);
ggAVAX.depositAVAX{ value: MAX_AMT }();
// Node Op 1: Prelaunch->Launched
vm.prank(address(rialto));
minipoolMgr.claimAndInitiateStaking(mp1.nodeID);
bytes32 txID = keccak256("txid");
vm.prank(address(rialto));
// Node Op 1: Launched->Staking
minipoolMgr.recordStakingStart(mp1.nodeID, txID, block.timestamp);
vm.prank(address(rialto));
// Node Op 1: Staking->Error
bytes32 errorCode = "INVALID_NODEID";
minipoolMgr.recordStakingError{ value: validationAmt }(mp1.nodeID, errorCode);
// There are 2*depositAmt AVAX in the pool manager
assertEq(vault.balanceOf("MinipoolManager"), depositAmt * 2);
// Node Op 1: Staking->Finished withdrawing funds
vm.prank(nodeOp);
minipoolMgr.withdrawMinipoolFunds(mp1.nodeID);
assertEq(staking.getAVAXStake(nodeOp), 0);
mp1 = minipoolMgr.getMinipool(minipoolIndex);
assertEq(mp1.status, uint256(MinipoolStatus.Finished));
// Rialto recreate a minipool for the mp1
vm.prank(address(rialto));
// Node Op 1: Finished -> Prelaunch
minipoolMgr.recreateMinipool(mp1.nodeID);
assertEq(vault.balanceOf("MinipoolManager"), depositAmt);
// Node Op 1: Prelaunch -> Launched
vm.prank(address(rialto));
minipoolMgr.claimAndInitiateStaking(mp1.nodeID);
// Node Op 1: Launched -> Staking
vm.prank(address(rialto));
minipoolMgr.recordStakingStart(mp1.nodeID, txID, block.timestamp);
assertEq(staking.getAVAXStake(nodeOp), 0);
assertEq(staking.getAVAXAssigned(nodeOp), depositAmt);
assertEq(staking.getAVAXAssignedHighWater(nodeOp), depositAmt);
// now try to launch the second operator's pool, it will fail with InsufficientContractBalance
vm.prank(address(rialto));
vm.expectRevert(Vault.InsufficientContractBalance.selector);
minipoolMgr.claimAndInitiateStaking(mp2.nodeID);
}
Tools Used
Manual Review, Foundry
Recommended Mitigation Steps
Make sure to keep the node operator’s deposit status the same for all states that can lead to the same state.
For example, for all states that can transition to Prelaunch, make sure to send the AVAX back to the user and get them back on the call recreateMiniPool().
emersoncloud (GoGoPool) confirmed
I think #213 might be a better primary. This one primarily depends on minipools going to staking->error which wouldn’t actually happen unless Rialto made a mistake.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The Warden has shown an issue with the FSM, Pools are allowed to perform the following transition
Prelaunch->Launched->Staking->Error->Finished->Prelaunchwhich allows to spin up the pool without funds.This could only happen if Rialto performs a mistake, so the finding is limited to highlighting the issue with the State Transition.
For this reason, I believe Medium to be the most appropriate severity.
@Alex the Entreprenerd - Please note that the issue is not limited to Rialto doing a mistake, but it’s actually possible to trick it by frontrunning the Rialto transaction as outlined in my finding: #484 (comment) That’s why the high severity was chosen initially.
emersoncloud (GoGoPool) mitigated:
Atomically recreate minipool so a node operator can’t withdraw inbetween: multisig-labs/gogopool#23
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 recreateMinipool function did not ensure the node operator's deposit was still held, allowing a minipool to be recreated after the deposit had been withdrawn.
Impact
A minipool could be launched without the operator's own deposit, using AVAX from other minipools, which could prevent those other minipools from launching; the judge noted this could only happen if Rialto made a mistake, though a warden argued it could be triggered by frontrunning.
What the attacker needed
Rialto calls recreateMinipool on a Finished minipool; Another minipool is in Prelaunch with AVAX in the vault
The fix
The mitigation made the recreate operation atomic so a node operator cannot withdraw funds in between.
How it was found
- Create two minipools with deposits from two different node operators.
- Move the first minipool through Prelaunch, Launched, Staking, and Error states.
- Withdraw the first node operator's funds, moving the minipool to Finished.
- Call recreateMinipool on the first minipool, moving it back to Prelaunch.
- Launch the first minipool again; it uses AVAX from the vault that was meant for the second minipool.
- Attempt to launch the second minipool; it fails due to insufficient contract balance.
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 minipool is a staking pool where a node operator deposits some AVAX and other users lend the rest. The contract tracks states like Prelaunch, Staking, and Finished. The bug is that a minipool could be reset to Prelaunch after the operator had already taken their deposit back, so the pool could start again without the operator's own money, using funds that belonged to other pools.
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.