Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users can receive creditRewards even when they are slashed #759

Closed
c4-bot-7 opened this issue Dec 27, 2023 · 5 comments
Closed

Users can receive creditRewards even when they are slashed #759

c4-bot-7 opened this issue Dec 27, 2023 · 5 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-262 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sufficient quality report This report is of sufficient quality

Comments

@c4-bot-7
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L249-L269

Vulnerability details

Impact

Whenever a term suffers a loss, the users(guild holders) of that term are slashed. Basically, they will not receive anything.
However, users are still able to receive creditRewards even when they are slashed.

In the contract SurplusGuildMinter, the function getRewards() is called whenever a user stakes or unstakes his credit tokens. i.e.
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L249-L269

function getRewards(address user,address term) public
        returns (uint256 lastGaugeLoss, UserStake memory userStake, bool slashed)
    {
 if (_profitIndex == 0) _profitIndex = 1e18;
        if (_userProfitIndex == 0) _userProfitIndex = 1e18;
        uint256 deltaIndex = _profitIndex - _userProfitIndex;     
        if (deltaIndex != 0) {
            uint256 creditReward = (uint256(userStake.guild) * deltaIndex) /
                1e18;
            uint256 guildReward = (creditReward * rewardRatio) / 1e18;   
            if (slashed) {
                guildReward = 0;
            }
            // forward rewards to user
            if (guildReward != 0) {
                RateLimitedMinter(rlgm).mint(user, guildReward);  
                emit GuildReward(block.timestamp, user, guildReward);  
            }
            if (creditReward != 0) {
                CreditToken(credit).transfer(user, creditReward); 
            }

If the user has been slashed, then guildReward are set to zero i.e.

if (slashed) {
guildReward = 0;
}

However, we did not account for creditReward(when users are slashed), therefore, the creditRewards would be sent to the user whenever guildReward function is called i.e.

 if (deltaIndex != 0) {
         uint256 creditReward = (uint256(userStake.guild) * deltaIndex) / 1e18;

if (creditReward != 0) {
    CreditToken(credit).transfer(user, creditReward); 
    }

This is an undesired behavior, and leads to loss of funds as the user is not supposed to receive the creditReward.

Proof of Concept

https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/SurplusGuildMinter.sol#L249-L269

Tools Used

Manual Review

Recommended Mitigation Steps

Consider updating the variable creditReward to zero in if the statement. i.e.

if (slashed) {
guildReward = 0;
creditReward = 0;   // DO THIS 
}

Assessed type

Math

@c4-bot-7 c4-bot-7 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 27, 2023
c4-bot-4 added a commit that referenced this issue Dec 27, 2023
@c4-pre-sort
Copy link

0xSorryNotSorry marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Jan 4, 2024
@c4-pre-sort
Copy link

0xSorryNotSorry marked the issue as duplicate of #956

@c4-judge
Copy link
Contributor

Trumpero marked the issue as duplicate of #262

@c4-judge
Copy link
Contributor

Trumpero changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 28, 2024
@c4-judge
Copy link
Contributor

Trumpero marked the issue as grade-b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-262 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

3 participants