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

Incorrect calculated fee reward for ERC20Quest #407

Closed
code423n4 opened this issue Jan 30, 2023 · 2 comments
Closed

Incorrect calculated fee reward for ERC20Quest #407

code423n4 opened this issue Jan 30, 2023 · 2 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-605 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L96-L98
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L89-L93
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/Erc20Quest.sol#L100-L104

Vulnerability details

Impact

More than enough funds might be redeemed from ERC20Quest.

Proof of Concept

  1. Quest finished.
  2. Only one user withdrawn their funds.
  3. Function withdrawFee has been executed.
  4. Another one user withdrawn their funds.
  5. Function withdrawFee has been executed. -- But here protocolFeeRecipient will receive fees for TWO users, Although it should has received only for one.

Tools Used

Manual audit

Recommended Mitigation Steps

As I mentioned early add possibility to call withdrawFee() only once.

And in protocolFee() instead of calculating fees only for redeemed users calculates fee over all users.

    function protocolFee() public view returns (uint256) {
        return (maxTotalRewards() * rewardAmountInWeiOrTokenId * questFee) / 10_000;
    }

But your idea may be to send commissions only for those users who participated.
In this case, you need to allow withdrawFee() to be called as many times as you want, but at the same time maintain the number of commissions already withdrawn and the number of participants who have collected their awards.
Like this:

uint256 receivedFeesFoUsers;


function withdrawFee() public onlyAdminWithdrawAfterEnd { // TODO DON'T FORGET ADD REENTRANCY GUARD
    uint256 newUsers = receiptRedeemers() - receivedFeesFoUsers;
    receivedFeesFoUsers = receiptRedeemers(); 
    uint256 fee = (newUsers * rewardAmountInWeiOrTokenId * questFee) / 10_000;
    IERC20(rewardToken).safeTransfer(protocolFeeRecipient, fee);
}
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 30, 2023
code423n4 added a commit that referenced this issue Jan 30, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 5, 2023

kirk-baird marked the issue as duplicate of #23

@c4-judge c4-judge closed this as completed Feb 5, 2023
@c4-judge c4-judge added duplicate-587 satisfactory satisfies C4 submission criteria; eligible for awards and removed duplicate-23 labels Feb 14, 2023
@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-605 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants