Part 2

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

Missing recalculate in depositCreditForMarket

Summary

In the current implementation of depositCreditForMarket, there is a missing call to recalculateVaultsCreditCapacity. This omission results in stale values for totalDelegatedCreditUsd, leading to incorrect calculations of usdcCreditPerVaultShare. Since the vaults of a market can accumulate more or less delegated credit over time, failing to update totalDelegatedCreditUsd before using it introduces inaccuracies.

Vulnerability Details

Scenario:

  1. A user calls depositCreditForMarket with USDC as the deposit asset.

  2. The function attempts to calculate usdcCreditPerVaultShare based on totalDelegatedCreditUsd.

  3. However, totalDelegatedCreditUsd has not been updated—it may not reflect the latest state of the vaults.

  4. This results in an incorrect credit per share calculation, which can impact credit distribution logic.

Impact

  • Incorrect Credit Accounting: Since usdcCreditPerVaultShare relies on totalDelegatedCreditUsd, using stale values can distort credit distribution across vaults.

  • Potential Financial Imbalance: Some vaults may receive more or less credit than they should

Tools Used

Manual review

Recommendations

To ensure totalDelegatedCreditUsd is up to date before computing usdcCreditPerVaultShare, insert a call to Vault.recalculateVaultsCreditCapacity() at the beginning of depositCreditForMarket:

function depositCreditForMarket(
uint128 marketId,
address collateralAddr,
uint256 amount
)
external
onlyRegisteredEngine(marketId)
{
if (amount == 0) revert Errors.ZeroInput("amount");
+. Vault.recalculateVaultsCreditCapacity(Market.loadLive(marketId).getConnectedVaultsIds());
// loads the collateral's data storage pointer, must be enabled
Collateral.Data storage collateral = Collateral.load(collateralAddr);
collateral.verifyIsEnabled();

This change ensures that totalDelegatedCreditUsd always reflects the latest vault state, preventing incorrect credit calculations.

Updates

Lead Judging Commences

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

Credit capacity calculation uses stale total assets in VaultRouterBranch::deposit by updating before the actual deposit, causing DOS in depositCreditForMarket

Support

FAQs

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