Adversary can arbitrarily trigger a chain halt by sending `MsgRemove{Delegate}Stake` with negative amount
The stake removal functions accept a negative amount without validation, and when the removal matures, creating a coin with that negative amount causes a panic that halts the chain. An attacker can trigger this at will by sending a message with a negative amount.
Kow Follow with LZ_security, abdulsamijay and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/21
Found by
Kow, LZ_security, abdulsamijay, imsrybr0, volodya
Summary
Adversary can trigger chain halt arbitrarily by sending MsgRemoveStake or MsgRemoveDelegateStake with negative amount.
Vulnerability Detail
In msg_server_stake.go, RemoveStake and RemoveDelegateStake contain the logic for starting the stake removal process for reputers and delegators respectively. After RemoveStakeDelayWindow blocks have passed, the stake removal is processed at the start of the emissions module EndBlocker. To send the removed stake amount to the reputer/delegator, a new coins structure is created using the amount unstaked.
https://github.com/sherlock-audit/2024-06-allora/blob/4e1bc73db32873476f8b0a88945815d3978d931c/allora-chain/x/emissions/module/stake_removals.go#L13-L35
func RemoveStakes(
sdkCtx sdk.Context,
currentBlock int64,
k emissionskeeper.Keeper,
) {
removals, err := k.GetStakeRemovalsForBlock(sdkCtx, currentBlock)
...
for _, stakeRemoval := range removals {
...
coins := sdk.NewCoins(sdk.NewCoin(chainParams.DefaultBondDenom, stakeRemoval.Amount))
(RemoveDelegateStakes follows similar logic)
Note that sdk.NewCoin will panic if the amount specified is negative.
https://github.com/cosmos/cosmos-sdk/blob/a32186608aab0bd436049377ddb34f90006fcbf7/types/coin.go#L25-L27
https://github.com/cosmos/cosmos-sdk/blob/a32186608aab0bd436049377ddb34f90006fcbf7/types/coin.go#L54-L56
The issue is the Amount parameter for the corresponding messages are integers and there is no validation that they are non-negative. Additionally, a negative amount to always passes the staked balance check. Consequently, anyone can send either MsgRemoveStake or MsgRemoveDelegateStake with a negative amount at any time and cause a chain halt when the stake removal matures.
func (s *MsgServerTestSuite) TestRemoveStakeDoS() {
ctx := s.ctx
require := s.Require()
keeper := s.emissionsKeeper
senderAddr := sdk.AccAddress(PKS[0].Address())
msg := &types.MsgRemoveStake{
Sender: senderAddr.String(),
TopicId: uint64(123),
Amount: cosmosMath.NewInt(-1),
}
response, err := s.msgServer.RemoveStake(ctx, msg)
require.NoError(err)
require.NotNil(response)
params, err := keeper.GetParams(ctx)
require.NoError(err)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + params.RemoveStakeDelayWindow)
_ = s.appModule.EndBlock(ctx)
}
Impact
Chain halt after RemovalStakeDelayWindow blocks due to negative coin amount in EndBlocker.
Code Snippet
https://github.com/sherlock-audit/2024-06-allora/blob/4e1bc73db32873476f8b0a88945815d3978d931c/allora-chain/x/emissions/module/stake_removals.go#L13-L35 https://github.com/sherlock-audit/2024-06-allora/blob/4e1bc73db32873476f8b0a88945815d3978d931c/allora-chain/x/emissions/module/stake_removals.go#L66-L89
Tool used
Manual Review
Recommendation
Validate that Amount is non-negative in RemoveStake and RemoveDelegateStake.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Negative value in stake-specific functions causes
panic()which permanently halts chain
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/441
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 message handlers for removing stake did not validate that the amount is non-negative, and the later coin creation panics on negative amounts.
Impact
The chain halts after the removal delay window due to the panic from the negative coin amount.
What the attacker needed
Ability to send a transaction to the chain
The fix
The protocol team fixed this issue by validating that the amount is non-negative in the stake removal functions.
How it was found
- Send a MsgRemoveStake or MsgRemoveDelegateStake message with a negative amount.
- Wait for the RemoveStakeDelayWindow blocks to pass.
- The EndBlocker processes the removal and panics when creating a coin with the negative amount, halting the chain.
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 blockchain lets people stake tokens and later remove them. The code that removes the stake did not check that the amount was positive, so someone could ask to remove a negative amount. When the system later tried to create a coin with that negative number, it crashed, and because this happens in a core part of the chain, the whole chain stopped working.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.