code-423n4 / 2023-06-lybra-findings

8 stars 7 forks source link

If `ProtocolRewardsPool` is insufficient in EUSD, users will not be able to calim any rewards #223

Open code423n4 opened 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/miner/ProtocolRewardsPool.sol#L196

Vulnerability details

Impact

If ProtocolRewardsPool is insufficient in EUSD, but has enough PeUSD to give rewards it still reverts, due to wrong if() statement, thus it is unable to send the rewards to users.

Proof of Concept

Users have just emptied ProtocolRewardsPool out of EUSD, by claiming rewards with getReward. Now the protocol has a new distribution of PeUSD tokens, with LybraConfigurator.distributeRewards, but when users try to claim their rewards getReward reverts because of this:

   function getReward() external updateReward(msg.sender) {
        uint reward = rewards[msg.sender];
        if (reward > 0) {
            rewards[msg.sender] = 0;
            IEUSD EUSD = IEUSD(configurator.getEUSDAddress());//get the address
            uint256 balance = EUSD.sharesOf(address(this));//get the balance == 
//@aduit here eUSDShare = balance >= reward-false => reward - balance => rewards - 0 | eUSDShare = reward
            uint256 eUSDShare = balance >= reward ? reward : reward - balance;
//here it tries to send the rewards amount, but it reverts since it has not tokens 
            EUSD.transferShares(msg.sender, eUSDShare);

Because of the constant revert users are not able to claim their rewards and need to wait for EUSD distribution. The other bad thing is that the PeUSD is uncalimable to most extent.Again because of the line bellow, if:

Recommended Mitigation Steps

update the if as:

-  uint256 eUSDShare = balance >= reward ? reward : reward - balance;
+  uint256 eUSDShare = balance >= reward ? reward : balance;

Assessed type

Math

c4-pre-sort commented 1 year ago

JeffCX marked the issue as duplicate of #161

c4-judge commented 1 year ago

0xean marked the issue as satisfactory

c4-judge commented 1 year ago

0xean changed the severity to 2 (Med Risk)

c4-judge commented 1 year ago

0xean marked the issue as selected for report

c4-sponsor commented 1 year ago

LybraFinance marked the issue as sponsor acknowledged