Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Valid

Incorrect credit delegation weight update in `updateVaultAndCreditDelegationWeight()`

Summary

The updateVaultAndCreditDelegationWeight() function incorrectly sets the same weight value for all connected markets, causing market's totalDelegatedCreditUsd to be overestimated.

Vulnerability Details

The issue occurs in updateVaultAndCreditDelegationWeight() where it assigns the same newWeight value to all connected markets:

File: Vault.sol
508: function updateVaultAndCreditDelegationWeight(
509: Data storage self,
510: uint128[] memory connectedMarketsIdsCache
511: )
512: internal
513: {
514: // cache the connected markets length
515: uint256 connectedMarketsConfigLength = self.connectedMarkets.length;
516:
517: // loads the connected markets storage pointer by taking the last configured market ids uint set
518: EnumerableSet.UintSet storage connectedMarkets = self.connectedMarkets[connectedMarketsConfigLength - 1];
519:
520: // get the total of shares
521: uint128 newWeight = uint128(IERC4626(self.indexToken).totalAssets());
522:
523: for (uint256 i; i < connectedMarketsIdsCache.length; i++) {
524: // load the credit delegation to the given market id
525: CreditDelegation.Data storage creditDelegation =
526: CreditDelegation.load(self.id, connectedMarkets.at(i).toUint128());
527:
528: // update the credit delegation weight
529: creditDelegation.weight = newWeight;
530: }
531:
532: // update the vault weight
533: self.totalCreditDelegationWeight = newWeight; //@audit incorrect
534: }

This leads to creditDelegationShareX18 always evaluating to 1 in _updateCreditDelegations(), causing each market to receive the full credit amount:

File: Vault.sol
587: // get the latest credit delegation share of the vault's credit capacity
588: UD60x18 creditDelegationShareX18 =
589: ud60x18(creditDelegation.weight).div(ud60x18(totalCreditDelegationWeightCache));

Impact

Markets receive more delegated credit than intended since totalDelegatedCreditUsd is overestimated, affecting withdrawal limits and profit calculations.

Recommendations

Modify updateVaultAndCreditDelegationWeight() to properly distribute weights among connected markets based on their individual credit delegation shares.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Market Credit Delegation Weights Are Incorrectly Distributed

Support

FAQs

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