MinipoolManager: node operator can avoid being slashed
A node operator could choose a minipool duration long enough that the GGP slashing amount exceeds their staked GGP balance, causing the slashing call to revert. This let the operator avoid being slashed and potentially withdraw their GGP stake.
HollaDieWaldfee Follow with enckrish, imare and 5 others
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee, also found by enckrish, imare, bin2chen, danyams, 0xdeadbeef0x, cozzetti, and ladboy233
When staking is done, a Rialto multisig calls MinipoolManager.recordStakingEnd (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L385-L440).
If the avaxTotalRewardAmt has the value zero, the MinipoolManager will slash the node operator’s GGP.
The issue is that the amount to slash can be greater than the GGP balance the node operator has staked.
This will cause the call to MinipoolManager.recordStakingEnd to revert because an underflow is detected.
This means a node operator can create a minipool that cannot be slashed.
A node operator must provide at least 10% of avaxAssigned as collateral by staking GGP.
It is assumed that a node operator earns AVAX at a rate of 10% per year.
So if a Minipool is created with a duration of > 365 days, the 10% collateral is not sufficient to pay the expected rewards.
This causes the function call to revert.
Another cause of the revert can be that the GGP price in AVAX changes. Specifically if the GGP price falls, there needs to be slashed more GGP.
Therefore if the GGP price drops enough it can cause the call to slash to revert.
I think it is important to say that with any collateralization ratio this can happen. The price of GGP must just drop enough or one must use a long enough duration.
The exact impact of this also depends on how the Rialto multisig handles failed calls to MinipoolManager.recordStakingEnd.
It looks like if this happens, MinipoolManager.recordStakingError (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L484-L515) is called.
This allows the node operator to withdraw his GGP stake.
So in summary a node operator can create a Minipool that cannot be slashed and probably remove his GGP stake when it should have been slashed.
Proof of Concept
When calling MinipoolManager.recordStakingEnd (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L385-L440) and the avaxTotalRewardAmt parameter is zero, the node operator is slashed:
// No rewards means validation period failed, must slash node ops GGP.
if (avaxTotalRewardAmt == 0) {
slash(minipoolIndex);
}
The MinipoolManager.slash function (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/MinipoolManager.sol#L670-L683) then calculates expectedAVAXRewardsAmt and from this slashGGPAmt:
uint256 avaxLiquidStakerAmt = getUint(keccak256(abi.encodePacked("minipool.item", index, ".avaxLiquidStakerAmt")));
uint256 expectedAVAXRewardsAmt = getExpectedAVAXRewardsAmt(duration, avaxLiquidStakerAmt);
uint256 slashGGPAmt = calculateGGPSlashAmt(expectedAVAXRewardsAmt);
Downstream there is then a revert due to underflow because of the following line in Staking.decreaseGGPStake (https://github.com/code-423n4/2022-12-gogopool/blob/aec9928d8bdce8a5a4efe45f54c39d4fc7313731/contracts/contract/Staking.sol#L94-L97):
subUint(keccak256(abi.encodePacked("staker.item", stakerIndex, ".ggpStaked")), amount);
You can add the following foundry test to MinipoolManager.t.sol:
function testRecordStakingEndWithSlashFail() public {
uint256 duration = 366 days;
uint256 depositAmt = 1000 ether;
uint256 avaxAssignmentRequest = 1000 ether;
uint256 validationAmt = depositAmt + avaxAssignmentRequest;
uint128 ggpStakeAmt = 100 ether;
vm.startPrank(nodeOp);
ggp.approve(address(staking), MAX_AMT);
staking.stakeGGP(ggpStakeAmt);
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}();
vm.prank(address(rialto));
minipoolMgr.claimAndInitiateStaking(mp1.nodeID);
bytes32 txID = keccak256("txid");
vm.prank(address(rialto));
minipoolMgr.recordStakingStart(mp1.nodeID, txID, block.timestamp);
vm.startPrank(address(rialto));
skip(duration);
minipoolMgr.recordStakingEnd{value: validationAmt}(mp1.nodeID, block.timestamp, 0 ether);
}
See that it runs successfully with duration = 365 days and fails with duration = 366 days.
The similar issue occurs when the GGP price drops. I chose to implement the test with duration as the cause for the underflow because your tests use a fixed AVAX/GGP price.
Tools Used
VSCode, Foundry
Recommended Mitigation Steps
You should check if the amount to be slashed is greater than the node operator’s GGP balance. If this is the case, the amount to be slashed should be set to the node operator’s GGP balance.
I believe this check can be implemented within the MinipoolManager.slash function without breaking any of the existing accounting logic.
function slash(int256 index) private {
address nodeID = getAddress(keccak256(abi.encodePacked("minipool.item", index, ".nodeID")));
address owner = getAddress(keccak256(abi.encodePacked("minipool.item", index, ".owner")));
uint256 duration = getUint(keccak256(abi.encodePacked("minipool.item", index, ".duration")));
uint256 avaxLiquidStakerAmt = getUint(keccak256(abi.encodePacked("minipool.item", index, ".avaxLiquidStakerAmt")));
uint256 expectedAVAXRewardsAmt = getExpectedAVAXRewardsAmt(duration, avaxLiquidStakerAmt);
uint256 slashGGPAmt = calculateGGPSlashAmt(expectedAVAXRewardsAmt);
setUint(keccak256(abi.encodePacked("minipool.item", index, ".ggpSlashAmt")), slashGGPAmt);
emit GGPSlashed(nodeID, slashGGPAmt);
Staking staking = Staking(getContractAddress("Staking"));
if (slashGGPAmt > staking.getGGPStake(owner)) {
slashGGPAmt = staking.getGGPStake(owner);
}
staking.slashGGP(owner, slashGGPAmt);
}
emersoncloud (GoGoPool) confirmed, but commented:
This is a combination of two other issues from other wardens
- Slash amount shouldn’t depend on duration: https://github.com/code-423n4/2022-12-gogopool-findings/issues/694
- GGP Slash shouldn’t revert: https://github.com/code-423n4/2022-12-gogopool-findings/issues/743
Alex the Entreprenerd (judge) commented:
This finding combines 2 issues:
- If price drops Slash can revert -> Medium
- Attacker can set Duration to too high to cause a revert -> High
Am going to dedupe this and the rest, but ultimately I think these are different findings, that should have been filed separately.
Alex the Entreprenerd (judge) commented:
The Warden has shown how a malicious staker could bypass slashing, by inputting a duration that is beyond the intended amount.
Other reports have shown how to sidestep the slash or reduce it, however, this report shows how the bypass can be enacted maliciously to break the protocol functionality, to the attacker’s potential gain.
Because slashing is sidestepped in it’s entirety, I believe this finding to be of High Severity.
emersoncloud (GoGoPool) mitigated:
If staked GGP doesn’t cover slash amount, slash it all: multisig-labs/gogopool#41
Status: Original finding mitigated, but a medium severity economical risk is still present. Full details in reports from RaymondFam, ladboy233 and hansfriese. Also included in Mitigation Review section below.
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
The slashing amount is calculated from the minipool duration and the GGP price without checking it against the operator's actual GGP balance, so an underflow reverts the slash.
Impact
A node operator could avoid slashing and potentially withdraw their GGP stake when it should have been slashed; the exact impact depends on how the Rialto multisig handles failed calls.
What the attacker needed
Be a node operator; stake GGP collateral; create minipool with long duration
The fix
The slash amount should be capped at the node operator's GGP balance before calling the staking contract.
How it was found
- Stake GGP as collateral and create a minipool with a duration longer than 365 days.
- Have a liquid staker deposit AVAX and have Rialto initiate and start staking.
- After the duration, call recordStakingEnd with zero rewards to trigger slashing.
- The slash amount exceeds the GGP balance, causing an underflow revert.
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 put up GGP tokens as collateral that can be taken away (slashed) if they fail to earn rewards. The amount to slash grows with the length of the staking period, so by picking a very long period the required slash became larger than the collateral, making the slash transaction fail. The operator could then avoid the penalty.
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.