Closed sherlock-admin2 closed 3 months ago
The delegator reward is a fraction of the total reward for that reputer and all their delegators combined (reputerDelegatorRewards
)
it doesn't re-calculate the delegator reward. It takes a fraction off of the total reward for that reputer and all their delegates, and then sends off the delegators share
Delegator rewards are correctly calculated
Minato7namikazi
High
Inconsistent Reward Calculation and Distribution in reputer_rewards.go
Vulnerability Detail
The issue arises in the interaction between
GetRewardPerReputer
andGetRewardForReputerFromTotalReward
.GetRewardPerReputer
: This function calculates rewards for both reputers and their delegators using thereputerFraction
andtotalReputerRewards
. It createsTaskReward
entries whereReward
contains the combined reward for both the reputer and their delegators.GetRewardForReputerFromTotalReward
: This function is meant to separate the delegator's reward and send it to a pending account. However, it takes thereputerDelegatorRewards
(which contain the combined rewards) and tries to calculate the delegator's portion again. This can lead to the delegator being over-rewarded.Consequences:
GetRewardPerReputer
and again inGetRewardForReputerFromTotalReward
). This can lead to a significant discrepancy in the reward distribution, as delegators will receive more than their fair share.Code Snippet
https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/module/rewards/reputer_rewards.go#L233
Tool used
Manual Review
Recommendation
Separate Reward Calculation**
The solution is to separate the reward calculation for reputers and delegators in
GetRewardPerReputer
. Here's the improved code:Key Changes:
GetRewardPerReputer
. The first calculates the reputer's rewards and the second calculates the delegator's rewards.reputerRewards
have a type ofReputerRewardType
.delegatorRewards
(calculated in the second loop) would have a type ofDelegatorRewardType
.GetRewardForReputerFromTotalReward
is removed as it's no longer needed.Benefits:
The reward calculation and distribution logic is now correct and fair to both reputers and delegators.
PoC
Explanation
decimal
library for precision.Output: The bug becomes evident in the output:
You'll notice that in the second output, the values are 80% of the original combined rewards. This means the delegator's portion was applied twice.
test_suite integration