hats-finance / Fenix-Finance-0x83dbe5aa378f3ce160ed084daf85f621289fb92f

0 stars 0 forks source link

Reviving a gauge will lead to overdistribution of rewards #5

Open hats-bug-reporter[bot] opened 6 months ago

hats-bug-reporter[bot] commented 6 months ago

Github username: @deadrosesxyz Twitter username: @deadrosesxyz Submission hash (on-chain): 0xd3c3c88c5cb6a55fdf0ed49567f63c287f9f3a3da257529eda012a8ffbfd64c9 Severity: medium

Description: Description\ Reviving a gauge will lead to overdistribution of rewards

Attack Scenario\ Within the Voter contract, gauges get rewards based on their relative voted balance. In certain scenarios, the protocol can decide to kill a certain Gauge. By doing so, the gauge will lose their rewards.

    function killGauge(address _gauge) external Governance {
        require(isAlive[_gauge], "killed");
        isAlive[_gauge] = false;
        claimable[_gauge] = 0;

        uint _time = _epochTimestamp();
        totalWeightsPerEpoch[_time] -= weightsPerEpoch[_time][poolForGauge[_gauge]];

        emit GaugeKilled(_gauge);
    }
    function reviveGauge(address _gauge) external Governance {
        require(!isAlive[_gauge], "alive");
        require(isGauge[_gauge], "killed");
        isAlive[_gauge] = true;
        emit GaugeRevived(_gauge);
    }

However, there comes a problem if a gauge is killed and revived

As it can be seen, when the gauge is killed, totalWeightsPerEpoch is decreased. It is not increased back up when reviving the gauge. This would mean that after reviving the gauge, the sum of all gauge weights will be higher than the total weight for that said epoch.

Impact:

  1. Overdistribution of rewards.
  2. Last gauge to claim their rewards will not be able to do so as there will not be enough funds in the contract

Attachments

  1. Proof of Concept (PoC) File

  2. Revised Code File (Optional)

BohdanHrytsak commented 6 months ago

Thank you for the submission.

The view refers to the part of the code that is in the OOS. Therefore, to accept this problem as valid, it must be high.

It is true that if the gauge is destroyed and then restored within the same epoch and one of the users does not change his vote, this will lead to these consequences, but this is not critical, OOS due to inheritance from the Thena & Chronos code