Skip to content
Business logic Audit finding Intermediate

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.

imsrybr0 Follow

Originally disclosed on Sherlock

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

RemoveDelegateStake

GOLANG
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
	}
        // ...
}

RemoveStake

GOLANG
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

The original report as published on Sherlock, by imsrybr0. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by imsrybr0

View all

12 more disclosed reports, best first.

More from Allora

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.