Open sherlock-admin3 opened 4 months ago
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
Topic funding amount is incorrectly accounted for twice
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/505
zigtur
High
Funding amount is accounted twice leading to activating topic before reaching the global minimum
Summary
The amount deposited through
FundTopic
is accounted twice during the topic activation calculation, leading to activating the topic too early (before reaching the minimum).Vulnerability Detail
During the funding of a topic through
FundTopic
, the funded amount will be added to the topic fee revenue. It will then check if the topic has enough weight to become active.However, during the check to see if enough weight is met, the funded amount will be accounted and added to the topic fee revenue. This is problematic because the topic fee revenue was already modified to account for this funded amount.
This leads the funded amount to be accounted twice.
Then, this double accounting leads to overestimate the weight of a topic. So a topic may be activate without reaching the expected minimum weight.
Impact
Topics will be activated before reaching the expected minimum weight.
Code Snippet
The
FundTopic
function callsAddTopicFeeRevenue
to add the amount to theTopicFeeRevenue
. It then calls theactivateTopicIfWeightAtLeastGlobalMin
function, which will read theTopicFeeRevenue
but will also add the amount.See msg_server_demand.go#L44-L52
First accounting
First, the funded amount is added through a call to
AddTopicFeeRevenue
. This function will modifyk.topicFeeRevenue
.See keeper.go#L1681.
Second accounting
Then, the
activateTopicIfWeightAtLeastGlobalMin
function will callGetCurrentTopicWeight
with the funded amount as argument. See msg_server_util_topic_activation.go#L28-L47Finally, the issue lies in
GetCurrentTopicWeight
which will do the addition of the funded amount tok.topicFeeRevenue
. However,k.topicFeeRevenue
was already increased by this amount (see previous section). See topic_weight.go#L61-L68.Proof of Concept
The following patch should be applied to import the PoC. Then, go in
allora-chain/x/emissions
and run the PoC withgo test ./keeper/msgserver/... -v -run "TestMsgServerTestSuite/TestPocDoubleAccounting"
.PoC results
The PoC will output the following:
Tool used
Manual Review
Recommendation
FundTopic
should callactivateTopicIfWeightAtLeastGlobalMin
with an amount of zero.The following patch applies this recommendation.