Steadefi

Steadefi
DeFiHardhatFoundryOracle
35,000 USDC
View results
Submission Details
Severity: medium
Invalid

The additionalCapacity function may have an overflow.

Summary

The additionalCapacity function may have overflow in some cases. e.g: 3x Neutral ETH-USDC with weight of ETH being 55%, USDC 45%

Vulnerability Details

Consider the following scenario:
E.g: 3x Neutral ETH-USDC with weight of ETH being 80%, USDC 20%

A $1 equity deposit should result in a $2 borrow for a total of $3 assets

Amount of ETH to borrow would be $3 x 80% = $2.4 worth of ETH

Amount of USDC to borrow would be $3 (asset) - $2.4 (ETH borrowed) - 0.4

if (self.delta == GMXTypes.Delta.Neutral) {
(uint256 _tokenAWeight, ) = tokenWeights(self);
uint256 _maxTokenALending = convertToUsdValue(
self,
address(self.tokenA),
self.tokenALendingVault.totalAvailableAsset()
) * SAFE_MULTIPLIER
/ (self.leverage * _tokenAWeight / SAFE_MULTIPLIER);
uint256 _maxTokenBLending = convertToUsdValue(
self,
address(self.tokenB),
self.tokenBLendingVault.totalAvailableAsset()
) * SAFE_MULTIPLIER
/ (self.leverage * _tokenAWeight / SAFE_MULTIPLIER)
- 1e18; //@audit
_additionalCapacity = _maxTokenALending > _maxTokenBLending ? _maxTokenBLending : _maxTokenALending;
}

Obviously there is an overflow in the calculation of _maxTokenBLending.This affects the user deposit. and does not generate the correct error message.

Impact

This affects the user deposit. and does not generate the correct error message.

Tools Used

manual

Recommendations

It is recommended to take into account overflow cases and modify them accordingly, e.g. by throwing correct error warnings after an overflow.

Updates

Lead Judging Commences

hans Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality
drynooo Submitter
over 1 year ago
hans Auditor
over 1 year ago
hans Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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