SetDelegateStakePlacement error is not handled in RewardDelegateStake
The RewardDelegateStake function does not handle errors from SetDelegateStakePlacement, so if that call fails, the RewardDebt is not updated. A delegate staker could then claim the same rewards multiple times, potentially draining the reward pool.
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/30
Found by
imsrybr0
Summary
SetDelegateStakePlacement error is not handled in RewardDelegateStake.
Vulnerability Detail
If SetDelegateStakePlacement fails in RewardDelegateStake, the RewardDebt will not be saved and it would allow a delegate staker to claim the same rewards more than once.
Impact
Rewards being distributed more than once can lead to insolvency (.i.e : others delegate stakers not being able to claim their rewards) and the drainage of the AlloraPendingReward module account.
Code Snippet
func (ms msgServer) RewardDelegateStake(ctx context.Context, msg *types.MsgRewardDelegateStake) (*types.MsgRewardDelegateStakeResponse, error) {
// Check the target reputer exists and is registered
isRegistered, err := ms.k.IsReputerRegisteredInTopic(ctx, msg.TopicId, msg.Reputer)
if err != nil {
return nil, err
}
if !isRegistered {
return nil, types.ErrAddressIsNotRegisteredInThisTopic
}
delegateInfo, err := ms.k.GetDelegateStakePlacement(ctx, msg.TopicId, msg.Sender, msg.Reputer)
if err != nil {
return nil, err
}
share, err := ms.k.GetDelegateRewardPerShare(ctx, msg.TopicId, msg.Reputer)
if err != nil {
return nil, err
}
pendingReward, err := delegateInfo.Amount.Mul(share)
if err != nil {
return nil, err
}
pendingReward, err = pendingReward.Sub(delegateInfo.RewardDebt) // <===== Audit
if err != nil {
return nil, err
}
if pendingReward.Gt(alloraMath.NewDecFromInt64(0)) {
coins := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, pendingReward.SdkIntTrim()))
err = ms.k.SendCoinsFromModuleToAccount(ctx, types.AlloraPendingRewardForDelegatorAccountName, msg.Sender, coins)
if err != nil {
return nil, err
}
delegateInfo.RewardDebt, err = delegateInfo.Amount.Mul(share)
if err != nil {
return nil, err
}
ms.k.SetDelegateStakePlacement(ctx, msg.TopicId, msg.Sender, msg.Reputer, delegateInfo) // <====== Audit
}
return &types.MsgRewardDelegateStakeResponse{}, nil
}
Tool used
Manual Review
Recommendation
Handle theSetDelegateStakePlacement error.
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Error SetDelegateStakePlacement is not handled correctly in RewardDelegateStake
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/463
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
Impact
A delegate staker could claim the same rewards multiple times, potentially making the system insolvent and draining the AlloraPendingReward module account.
What the attacker needed
A delegate staker account; SetDelegateStakePlacement fails
The fix
The error from SetDelegateStakePlacement should be handled, and the protocol team fixed this issue.
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 reward system, when a user claims rewards, the system must record that they have been paid so they cannot claim again. Here, the code that saves this record can fail, but the failure is ignored, so the user can keep claiming the same rewards. This could empty the reward pool and prevent others from getting their rewards.
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.