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

Missing Overflow Protection On the DeployedCapital #238

Open
code423n4 opened this issue Dec 1, 2021 · 2 comments
Open

Missing Overflow Protection On the DeployedCapital #238

code423n4 opened this issue Dec 1, 2021 · 2 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 sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

defsec

Vulnerability details

Impact

An overflow/underflow happens when an arithmetic operation reaches the maximum or minimum size of a type. For instance if a number is stored in the uint8 type, it means that the number is stored in a 8 bits unsigned number ranging from 0 to 2^8-1. In computer programming, an integer overflow occurs when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of bits – either larger than the maximum or lower than the minimum representable value.

On the SwingTrader.sol contract, Some of the internal variables doesn't have overflow protection although the safemath library has been used.

Proof of Concept

  1. Navigate to the following contract.
  function buyMalt(uint256 maxCapital)
    external
    onlyRole(STABILIZER_NODE_ROLE, "Must have stabilizer node privs")
    returns (uint256 capitalUsed)
  {
    if (maxCapital == 0) {
      return 0;
    }

    uint256 balance = collateralToken.balanceOf(address(this));

    if (balance == 0) {
      return 0;
    }

    if (maxCapital < balance) {
      balance = maxCapital;
    }

    collateralToken.safeTransfer(address(dexHandler), balance);
    dexHandler.buyMalt();

    deployedCapital = deployedCapital + balance;

    return balance;
  }


  1. DeployedCapital can be overflowed via balance add operation.

Tools Used

None

Recommended Mitigation Steps

Consider to use the following statement.

    deployedCapital = deployedCapital.add(balance);


@code423n4 code423n4 added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working labels Dec 1, 2021
code423n4 added a commit that referenced this issue Dec 1, 2021
@0xScotch 0xScotch added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Dec 6, 2021
@0xScotch
Copy link
Collaborator

0xScotch commented Dec 6, 2021

If deployedCapital here overflows a uint256 then there are many other issues for the blockchain as the DAI supply has overflowed

@GalloDaSballo
Copy link
Collaborator

The sponsor acknowledges, but in their reply they show that they don't need the overflow check.
I'd recommend the sponsor to add a comment on the decision and be done with it.
Will mark as valid, but if the sponsor disputed i would have sided with them

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 sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

3 participants