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

Dapper Chartreuse Wolf - There is loss of funds in EthosBouch::calcFee #720

Open
sherlock-admin2 opened this issue Dec 5, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

Dapper Chartreuse Wolf

High

There is loss of funds in EthosBouch::calcFee

Impact

Calculating Fee as Floor makes huge funds loss for the protocol. EthosVouch::calcFee

Because if the calculation becomes 1.5 then it will be floor to 1
If we consider this for a lot of calls then it makes a huge impact on the protocol.

PoC

Here is the code
EthosVouch::calcFee

function calcFee(uint256 total, uint256 feeBasisPoints) internal pure returns (uint256 fee) {
    /*
     * Formula derivation:
     * 1. total = deposit + fee
     * 2. fee = deposit * (feeBasisPoints/10000)
     * 3. total = deposit + deposit * (feeBasisPoints/10000)
     * 4. total = deposit * (1 + feeBasisPoints/10000)
     * 5. deposit = total / (1 + feeBasisPoints/10000)
     * 6. fee = total - deposit
     * 7. fee = total - (total * 10000 / (10000 + feeBasisPoints))
     */
    return
      total -
      (total.mulDiv(BASIS_POINT_SCALE, (BASIS_POINT_SCALE + feeBasisPoints), Math.Rounding.Floor));  <@
  }

Mitigation

Make Floor to Ceil

function calcFee(uint256 total, uint256 feeBasisPoints) internal pure returns (uint256 fee) {
    /*
     * Formula derivation:
     * 1. total = deposit + fee
     * 2. fee = deposit * (feeBasisPoints/10000)
     * 3. total = deposit + deposit * (feeBasisPoints/10000)
     * 4. total = deposit * (1 + feeBasisPoints/10000)
     * 5. deposit = total / (1 + feeBasisPoints/10000)
     * 6. fee = total - deposit
     * 7. fee = total - (total * 10000 / (10000 + feeBasisPoints))
     */
-    return
-     total -
-    (total.mulDiv(BASIS_POINT_SCALE, (BASIS_POINT_SCALE + feeBasisPoints), Math.Rounding.Floor));

+      return
+      total -
+      (total.mulDiv(BASIS_POINT_SCALE, (BASIS_POINT_SCALE + feeBasisPoints), Math.Rounding.Ceil));
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant