Closed sherlock-admin2 closed 3 months ago
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
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/441
abdulsamijay
High
Removing Negative amounts in Stake & DelegateStake leads to chain halt
Summary
The functions
RemoveStake
&RemoveDelegateStake
do not check whether the msg.Amount is positive before proceeding with the stake removal process. This oversight allows negative amounts to be scheduled, which causes a critical error during the EndBlocker execution, resulting in a chain halt.Vulnerability Detail
The vulnerability stems from the lack of validation for positive amounts in the
RemoveDelegateStake
andRemoveStake
functions located in the following lines.x/emissions/keeper/msgserver/msg_server_stake.go#L62
- x/emissions/keeper/msgserver/msg_server_stake.go#L175
When these transactions are processed, they are scheduled for removal after a delay specified by moduleParams.RemoveStakeDelayWindow. When the EndBlocker Runs after the scheduled time stakes gets removed & it runs the following code in
[x/emissions/module/abci.go#L22-23](https://github.com/allora-network/allora-chain/blob/3a97afe7af027c96749fac7c4327ae85359a61c8/x/emissions/module/abci.go#L22-L23)
This leads to calling
SendCoinsFromModuleToAccount
with a negative amount leading to panic.Impact
Here is the simplified steps how an attacker can cause a chain halt.
creates
a topic with id 1registers
herself as a reputer in the system.adds stakes
for a topic with id 1.remove-stake
from the topic with negative amount. Now the removal is scheduled formoduleParams.RemoveStakeDelayWindow
. When the delayedWindow has passed EndBlocker will call RemoveStake function & the chain will panic.The similar attack vector applies with the delegator who wishes to delegate to a reputer.
delegator
who delegates stake to Alice.removes
delegated stake from the reputer with negative amount. After the delay, the chain halts.Code Snippet
Tool used
Manual Review
Recommendation
To prevent this issue, add a validation check to ensure that the msg.Amount is positive in both the
RemoveDelegateStake
andRemoveStake
functions.Duplicate of #21