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

Distribution of tokens in recordKeyPurchase #230

Open
code423n4 opened this issue Nov 24, 2021 · 3 comments
Open

Distribution of tokens in recordKeyPurchase #230

code423n4 opened this issue Nov 24, 2021 · 3 comments
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working

Comments

@code423n4
Copy link
Contributor

Handle

pauliax

Vulnerability details

Impact

function recordKeyPurchas does not distribute the tokens on chainId > 1 when the balance is not sufficient:

  uint balance = IMintableERC20(udt).balanceOf(address(this));
  if (balance > tokensToDistribute) {
    // Only distribute if there are enough tokens
    IMintableERC20(udt).transfer(_referrer, tokensToDistribute - devReward);
    IMintableERC20(udt).transfer(owner(), devReward);
  }

I see at least 2 problems here. First, the check should be inclusive >=, because now when balance = tokensToDistribute, it will still skip the distribution.
Another problem, I think it is not fair when only a small fraction is missing, you should consider distributing the whole balance in this case.

Recommended Mitigation Steps

Here is my prosposed solution:

  uint balance = IMintableERC20(udt).balanceOf(address(this));
  if (balance >= tokensToDistribute) {
    IMintableERC20(udt).transfer(_referrer, tokensToDistribute - devReward);
    IMintableERC20(udt).transfer(owner(), devReward);
  } else {
    devReward = balance * 20 / 100;
    IMintableERC20(udt).transfer(_referrer, balance - devReward);
    IMintableERC20(udt).transfer(owner(), devReward);
  }
@code423n4 code423n4 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 Nov 24, 2021
code423n4 added a commit that referenced this issue Nov 24, 2021
@julien51
Copy link
Collaborator

I see at least 2 problems here. First, the check should be inclusive >=, because now when balance = tokensToDistribute, it will still skip the distribution.

It is a good point, but also almost impossible to achieve = because :

  1. If the number of tokens to be distributed is based on gas, the gas price + token price would have to be exactly aligned with what is left on the contract (which seems practically impossible given the precision!)
  2. if the number of tokens to be distributed is based on actual GDP contribution, the only way to make that true is to have a "Infinite" contribution which is itself impossible.

@julien51
Copy link
Collaborator

Another problem, I think it is not fair when only a small fraction is missing, you should consider distributing the whole balance in this case.

I am not sure I understand this comment. What is "missing"?

@julien51 julien51 added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Dec 11, 2021
@julien51 julien51 added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Jan 3, 2022
@0xleastwood
Copy link
Collaborator

I think the warden has provided useful information, however, it is more in line with a low severity issue.

1 — Low (L): vulns that have a risk of 1 are considered “Low” severity when assets are not at risk. Includes state handling, function incorrect as to spec, and issues with comments.

@0xleastwood 0xleastwood added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 16, 2022
@0xleastwood 0xleastwood removed disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue labels Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants