GetCurrentTopicWeight returns topicFeeRevenue without accounting additionalRevenue
Summary
GetCurrentTopicWeight calculates the topic's weight using the sum of topicFeeRevenue and additionalRevenue, but it returns topicFeeRevenue without adding additionalRevenue.
Vulnerability Detail
GetCurrentTopicWeight is used to calculate the weight of each topic and return it's weight and topicFeeRevenue.
The function uses the topic revenue and combines it with additionalRevenue to get the total feeRevenue and after that it uses it to calculate it's weight.
// Take EMA of target weight with previous weight
previousTopicWeight, noPrior, err := k.GetPreviousTopicWeight(ctx, topicId)
if err != nil {
return alloraMath.Dec{}, cosmosMath.Int{}, errors.Wrapf(err, "failed to get previous topic weight")
}
weight, err = alloraMath.CalcEma(topicRewardAlpha, targetWeight, previousTopicWeight, noPrior)
if err != nil {
return alloraMath.Dec{}, cosmosMath.Int{}, errors.Wrapf(err, "failed to calculate EMA")
}
// weight = targetWeight * 50% + prev weight * 50%
return weight, topicFeeRevenue, nil
However the issue we face here is that our weight is calculated from the sum of topicFeeRevenue and additionalRevenue, but the returned revenue is only topicFeeRevenue. Causing a discrepancy that will:
Increase weight - as we are calculating it with a bigger revenue
Decrease revenue - as we are returning only the initial revenue
This function is used inside activateTopicIfWeightAtLeastGlobalMin to check if a topic can be activated, GetAndUpdateActiveTopicWeights to update topic weights and activate any that need be and in GetTopic to be queried by outside entities.
Impact
Returning the wrong revenue will cause internal accounting errors.
0x3b
Medium
GetCurrentTopicWeight
returnstopicFeeRevenue
without accountingadditionalRevenue
Summary
GetCurrentTopicWeight
calculates the topic's weight using the sum oftopicFeeRevenue
andadditionalRevenue
, but it returnstopicFeeRevenue
without addingadditionalRevenue
.Vulnerability Detail
GetCurrentTopicWeight
is used to calculate the weight of each topic and return it'sweight
andtopicFeeRevenue
.The function uses the topic revenue and combines it with
additionalRevenue
to get the totalfeeRevenue
and after that it uses it to calculate it's weight.https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/keeper/topic_weight.go#L61
Later it returns it's estimated average weight (
targetWeight * 50% + previous weight * 50%
) and the total revenue.https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/keeper/topic_weight.go#L86
However the issue we face here is that our weight is calculated from the sum of
topicFeeRevenue
andadditionalRevenue
, but the returned revenue is onlytopicFeeRevenue
. Causing a discrepancy that will:This function is used inside
activateTopicIfWeightAtLeastGlobalMin
to check if a topic can be activated,GetAndUpdateActiveTopicWeights
to update topic weights and activate any that need be and inGetTopic
to be queried by outside entities.Impact
Returning the wrong revenue will cause internal accounting errors.
Code Snippet
Tool used
Manual Review
Recommendation
Return
newFeeRevenue
instead oftopicFeeRevenue
.Duplicate of #46