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

Market with id = 0 can be created.

Summary

Market with ID = 0 can be created. Market with zero id is a special input passed to getAccountMarginRequirementUsdAndUnrealizedPnlUsd to get that account's required margin and P&L.

Root Cause

https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/leaves/PerpMarket.sol#L394-L428

function create(CreateParams memory params) internal {
Data storage self = load(params.marketId);
if (self.id != 0) {
revert Errors.MarketAlreadyExists(params.marketId);
}
self.id = params.marketId;
self.initialized = true;
self.configuration.update(
MarketConfiguration.Data({
name: params.name,
symbol: params.symbol,
priceAdapter: params.priceAdapter,
initialMarginRateX18: params.initialMarginRateX18,
maintenanceMarginRateX18: params.maintenanceMarginRateX18,
maxOpenInterest: params.maxOpenInterest,
maxSkew: params.maxSkew,
maxFundingVelocity: params.maxFundingVelocity,
minTradeSizeX18: params.minTradeSizeX18,
skewScale: params.skewScale,
orderFees: params.orderFees,
priceFeedHeartbeatSeconds: params.priceFeedHeartbeatSeconds
})
);
SettlementConfiguration.update(
params.marketId, SettlementConfiguration.MARKET_ORDER_CONFIGURATION_ID, params.marketOrderConfiguration
);
SettlementConfiguration.update(
params.marketId,
SettlementConfiguration.OFFCHAIN_ORDERS_CONFIGURATION_ID,
params.offchainOrdersConfiguration
);
}

Vulnerability details

As we can see while creating a new market the set id must be 0. It means that market was not created before. However there is no check that params.marketId is not zero. Without the knowladge of how the id is being generated and whether the market is created via a script or manual transaction there is a scenario where admin creates a market with zero id.

Impact

When market with id = 0 is created it will create incompatibilities in calculations or transaction flow. As this issue is caused by admin input, I think, that low is a reasonable severity.

Recommended Mitigation Steps

Do not allow a market with zero id to be created. Ensure that params.marketId != 0.

Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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