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

Incorrect share accounting as totalAmountBefore is miscalculated inside mint()

Description & Impact

When there's a 1x Long open position, totalAmountBefore is calculated inside _mint() in the following manner:

File: contracts/PerpetualVault.sol
762: function _mint(uint256 depositId, uint256 amount, bool refundFee, MarketPrices memory prices) internal {
763: uint256 _shares;
764: if (totalShares == 0) {
765: _shares = depositInfo[depositId].amount * 1e8;
766: } else {
767: uint256 totalAmountBefore;
768:@---> if (positionIsClosed == false && _isLongOneLeverage(beenLong)) {
769:@---> totalAmountBefore = IERC20(indexToken).balanceOf(address(this)) - amount;
770: } else {
771: totalAmountBefore = _totalAmount(prices) - amount;
772: }
773: if (totalAmountBefore == 0) totalAmountBefore = 1;
774:@---> _shares = amount * totalShares / totalAmountBefore;
775: }
// ... Rest of the code

However the vault could also be holding some collateral tokens at the time which should contribute to this calculation. These collateral tokens could have arrived due to:

  • Fees

  • ADL (Auto deleveraging) by GMX

  • Partial Liquidations

These need to be accounted for, else the depositor receives a greater share ratio than intended.

Recommendation

if (positionIsClosed == false && _isLongOneLeverage(beenLong)) {
- totalAmountBefore = IERC20(indexToken).balanceOf(address(this)) - amount;
+ totalAmountBefore = _totalAmount(prices) * prices.shortTokenPrice.min / prices.indexTokenPrice.min - amount;
}
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.