Skip to content
Audit finding Advanced

`AlloraPendingRewardForDelegator` module account could have insufficient rewards due to truncation

The reward calculation for delegators in the Allora blockchain truncated the amount sent to the pending reward module account while recording a higher share, causing the module account to hold fewer tokens than owed. Over time, delegators could be unable to withdraw their full rewards.

Kow Follow with imsrybr0

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/74

Found by

Kow, imsrybr0

Summary

AlloraPendingRewardForDelegator module account could have insufficient rewards due to truncation.

Vulnerability Detail

In GetRewardForReputerFromTotalReward, the delegator reward for a reputer is calculated and set to AlloraPendingRewardForDelegator. https://github.com/sherlock-audit/2024-06-allora/blob/4e1bc73db32873476f8b0a88945815d3978d931c/allora-chain/x/emissions/module/rewards/reputer_rewards.go#L182-L214

Go
		if delegatorReward.Gt(alloraMath.NewDecFromInt64(0)) {
			// update reward share
			// new_share = current_share + (reward / total_stake)
			totalDelegatorStakeAmountDec, err := alloraMath.NewDecFromSdkInt(totalDelegatorStakeAmount)
			if err != nil {
				return nil, err
			}
			addShare, err := delegatorReward.Quo(totalDelegatorStakeAmountDec)
			if err != nil {
				return nil, err
			}
			currentShare, err := keeper.GetDelegateRewardPerShare(ctx, topicId, reputer)
			if err != nil {
				return nil, err
			}
			newShare, err := currentShare.Add(addShare)
			if err != nil {
				return nil, err
			}
			err = keeper.SetDelegateRewardPerShare(ctx, topicId, reputer, newShare)
			if err != nil {
				return nil, err
			}
			err = keeper.SendCoinsFromModuleToModule(
				ctx,
				types.AlloraRewardsAccountName,
				types.AlloraPendingRewardForDelegatorAccountName,
				sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, delegatorReward.SdkIntTrim())),
			)
			if err != nil {
				return nil, errors.Wrapf(err, "failed to send coins to allora pend reward account")
			}
		}

Notice that addShare = delegatorReward / totalDelegatorStakeAmountDec with full precision (ie. no truncation) and is added to DelegateRewardPerShare, while delegatorReward.SdkIntTrim() <= addShare * totalDelegatorStakeAmountDec = delegatorReward is sent to AlloraPendingRewardForDelegator. This means the recorded total reward for delegators would exceed the amount held by the reward module account, potentially leading to delegators being unable to withdraw their rewards (and breaking an invariant in the README). The chance of this happening is somewhat offset by the fact that the pending reward calculated and sent to the delegator in RewardDelegateStake is also truncated, but the repeated increase in delegator reward relative to the funds in the reward account over multiple blocks would heavily increase the discrepancy.

Impact

Rewards account may have insufficient funds to pay out to delegators.

Code Snippet

https://github.com/sherlock-audit/2024-06-allora/blob/4e1bc73db32873476f8b0a88945815d3978d931c/allora-chain/x/emissions/module/rewards/reputer_rewards.go#L182-L214

Tool used

Manual Review

Recommendation

Truncate addShare before adding to newShare.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/424

The original report as published on Sherlock, by Kow. 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

The code adds a high-precision share to the reward-per-share value but sends a truncated integer amount to the reward account, creating a discrepancy between recorded and actual funds.

Impact

The rewards account may have insufficient funds to pay delegators, potentially preventing withdrawals.

What the attacker needed

Delegators stake rewards; multiple reward distributions occur

The fix

The issue was fixed by truncating the share before adding it to the reward-per-share value.

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.

When rewards are split among many people, the code sometimes rounds down the amount it actually moves into a holding account, but it records the full amount owed. This mismatch means the holding account can run out of tokens, so people cannot withdraw what they are owed.

More by Kow

View all

8 more disclosed reports, best first.

More from Allora

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.