hats-finance / Inverter-Network-0xe47e52c4fea05e555920f1dcdcc6fb8eca103eeb

Fork of the Inverter Smart Contracts Repository
GNU Lesser General Public License v3.0
0 stars 3 forks source link

`_earned` is not needed inside `_distributeRewards` #112

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

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

Github username: @0x3b33 Twitter username: 0x3b33 Submission hash (on-chain): 0x48fb8d98a4276fd7339582a5c13a1a83e44d9a655cc98c7620e41aac43e3c645 Severity: gas saving

Description: Description\ LM_PC_Staking_v1::_distributeRewards doesn't need to call _earned because it's already called in _update, which is executed every time before _distributeRewards.

Attack Scenario\ _earned is called inside _distributeRewards. However, _update is always called before _distributeRewards to update the user rewards, which already includes a call to _earned. This makes uint amount = _earned(recipient, rewardValue) unnecessary.

It can be replaced with a simple rewards[recipient] assignment, avoiding extra calculations and saving gas.

Revised Code File

    function _distributeRewards(address recipient) internal {

-       uint amount = _earned(recipient, rewardValue);
+       uint amount = rewards[recipient];
        rewards[recipient] = 0;
FHieser commented 5 months ago

I ran it through the tests and it seems to be valid. Good gas improvement :+1: