DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

When the position is 1x long, the shares calculation of the `mint` function is incorrect

Summary

When the position is 1x long, the shares calculation of the mint function is incorrect.

Vulnerability Details

In the mint function of PerpetulVault.sol, the user's shares are calculated by calculating the proportion of the amount of collateral deposited to the total amount (totalAmountBefore).

But in the case of a 1x long position, the totalAmountBefore is the balance of the indexToken, not the **collateralToken. **This will result in incorrect calculation of _shares.

function _mint(uint256 depositId, uint256 amount, bool refundFee, MarketPrices memory prices) internal {
uint256 _shares;
if (totalShares == 0) {
_shares = depositInfo[depositId].amount * 1e8;
} else {
uint256 totalAmountBefore;
if (positionIsClosed == false && _isLongOneLeverage(beenLong)) {
// @audit indexToken?
totalAmountBefore = IERC20(indexToken).balanceOf(address(this)) - amount;
} else {
totalAmountBefore = _totalAmount(prices) - amount;
}
if (totalAmountBefore == 0) totalAmountBefore = 1;
_shares = amount * totalShares / totalAmountBefore;
}
...
}

Impact

The protocol function cannot run correctly.

Tools Used

vs code

Recommendations

After obtaining the balance of IndexToken, it needs to be multiplied by the exchange rate between indexToken and collateralToken.

Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.