RemoveDelegateStake silently handles the error when checking for existing removals
The RemoveDelegateStake function ignores errors when checking for existing stake removals, unlike RemoveStake which returns the error. This could allow a delegate stake removal to be created even if the check fails.
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/84
The protocol has acknowledged this issue.
Found by
imsrybr0
Summary
RemoveDelegateStake silently handles the error when checking for existing removals
Vulnerability Detail
RemoveDelegateStake silently handles the error when checking for existing removals while RemoveStake blocks further processing and returns the error.
Impact
Delegate stake removal will be created even if an error happens when checking for existing removals.
Code Snippet
func (ms msgServer) RemoveDelegateStake(ctx context.Context, msg *types.MsgRemoveDelegateStake) (*types.MsgRemoveDelegateStakeResponse, error) {
// ...
removal, found, err := ms.k.GetDelegateStakeRemovalForDelegatorReputerAndTopicId(
sdkCtx, msg.Sender, msg.Reputer, msg.TopicId,
)
if err != nil {
errorsmod.Wrap(err, "error during finding delegate stake removal") // <===== Audit : Not returned
}
// ...
}
func (ms msgServer) RemoveStake(ctx context.Context, msg *types.MsgRemoveStake) (*types.MsgRemoveStakeResponse, error) {
// ...
removal, found, err := ms.k.GetStakeRemovalForReputerAndTopicId(sdkCtx, msg.Sender, msg.TopicId)
if err != nil {
return nil, errorsmod.Wrap(err, "error while searching previous stake removal") // <===== Audit : Returned
}
// ...
}
Tool used
Manual Review
Recommendation
Return the error from RemoveDelegateStake
Discussion
sherlock-admin3
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Error is silently handled in
RemoveDelegateStake
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 error returned from the check for existing delegate stake removals is not propagated, so the function proceeds as if no error occurred.
What the attacker needed
None
The fix
The error should be returned from RemoveDelegateStake, as it is in RemoveStake.
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 a blockchain smart contract, when a function checks for something and encounters an error, it should stop and report the error. Here, one function ignores the error and continues, which might cause unexpected behaviour.
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.