`DripTopicFeeRevenue` drips the internal `topicFeeRevenue` and not the one provided by `GetCurrentTopicWeight`
The function DripTopicFeeRevenue reads the stored topicFeeRevenue instead of using the value calculated by GetCurrentTopicWeight, which may include a bonus. As a result, the bonus is never dripped, so the dripped amount can be less than the total revenue reported.
Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/114
Found by
0x3b
Summary
DripTopicFeeRevenue drips the topicFeeRevenue storage value instead of the value provided by the calculations inside GetCurrentTopicWeight. This can lead to different drip amounts than the ones calculated.
Vulnerability Detail
When GetAndUpdateActiveTopicWeights calls DripTopicFeeRevenue, it doesn't take the previously calculated topicFeeRevenue from GetCurrentTopicWeight.
weight, topicFeeRevenue, err := k.GetCurrentTopicWeight(
ctx,
topic.Id,
topic.EpochLength,
moduleParams.TopicRewardAlpha,
moduleParams.TopicRewardStakeImportance,
moduleParams.TopicRewardFeeRevenueImportance,
cosmosMath.ZeroInt(),
)
Instead, DripTopicFeeRevenue extracts the revenue from storage and drips that.
func (k *Keeper) DripTopicFeeRevenue(ctx context.Context, topicId TopicId, block BlockHeight) error {
topicFeeRevenue, err := k.GetTopicFeeRevenue(ctx, topicId)
if err != nil {
return err
}
However, if GetCurrentTopicWeight calculates a larger revenue because it includes a bonus, that bonus will never be dripped. The bonus is calculated here inside GetCurrentTopicWeight:
newFeeRevenue := additionalRevenue.Add(topicFeeRevenue)
feeRevenue, err := alloraMath.NewDecFromSdkInt(newFeeRevenue)
if err != nil {
return alloraMath.Dec{}, cosmosMath.Int{}, errors.Wrapf(err, "failed to convert topic fee revenue to dec")
}
Impact
DripTopicFeeRevenue may drip less than what is reported in totalRevenue.
Code Snippet
weight, topicFeeRevenue, err := k.GetCurrentTopicWeight(
ctx,
topic.Id,
topic.EpochLength,
moduleParams.TopicRewardAlpha,
moduleParams.TopicRewardStakeImportance,
moduleParams.TopicRewardFeeRevenueImportance,
cosmosMath.ZeroInt(),
)
if err != nil {
return errors.Wrapf(err, "failed to get current topic weight")
}
err = k.SetPreviousTopicWeight(ctx, topic.Id, weight)
if err != nil {
return errors.Wrapf(err, "failed to set previous topic weight")
}
//@audit doesn't take `topicFeeRevenue` as an input, but calculates its own revenue
err = k.DripTopicFeeRevenue(ctx, topic.Id, block)
if err != nil {
return errors.Wrapf(err, "failed to reset topic fee revenue")
}
Tool Used
Manual Review
Recommendation
Make DripTopicFeeRevenue take a parameter topicFeeRevenue and drip that amount.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/505
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, DripTopicFeeRevenue does not accept the calculated topicFeeRevenue as a parameter and instead fetches the stored value, ignoring any additional revenue computed by GetCurrentTopicWeight.
What the attacker needed
None
The fix
DripTopicFeeRevenue should be modified to take a topicFeeRevenue parameter and drip that amount.
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, a function calculates how much fee revenue a topic has earned, including a possible bonus. Another function is supposed to distribute (drip) that calculated amount, but instead it reads an older stored value. This means the bonus is never paid out, so users may receive less than they should.
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.