Part 2

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

Lack of Grace Period in Perpetual Market Funding Rate Initialization Leads to Premature Rate Calculations

Summary

The perpetual market contract lacks a grace period mechanism for funding rate calculations when new markets are created. This design flaw exposes the protocol to potential manipulation and unfair funding distributions during the critical market establishment phase.

In PerpMarket.sol, the market creation sets lastFundingTime to the current block timestamp:

function create(CreateParams memory params) internal {
Data storage self = load(params.marketId);
// ...
self.lastFundingTime = block.timestamp;
// ...
}

Funding calculations immediately use this timestamp:

function getProportionalElapsedSinceLastFunding(Data storage self) internal view returns (UD60x18) {
return ud60x18Convert(block.timestamp - self.lastFundingTime).div(
ud60x18Convert(Constants.PROPORTIONAL_FUNDING_PERIOD)
);
}

Related Functions Affected

  • getCurrentFundingRate()

  • getCurrentFundingVelocity()

  • getNextFundingFeePerUnit()

  • getPendingFundingFeePerUnit()

Reproduction

  1. Create a new perpetual market

  2. Immediately execute trades

  3. Observe funding rate calculations occurring without proper market establishment

Impact

The absence of a grace period creates a cascading effect of risks:

The immediate activation of funding calculations after market creation leads to unstable and potentially manipulatable funding rates. During the initial period when liquidity is low and price discovery is still establishing, these premature funding calculations can create adverse incentives for market participants.

Early traders may face distorted funding payments due to these inaccurate rates, as the market hasn't achieved sufficient depth for meaningful funding rate calculations. This can particularly impact large position holders who might incur substantial funding costs or gains based on these non-representative rates.

Furthermore, sophisticated actors could exploit this initialization period to manipulate funding rates through strategic positioning, taking advantage of the low liquidity and immature market dynamics to extract value from other participants.

This vulnerability ultimately undermines the market's price discovery process and could deter legitimate market participants from engaging during the crucial early stages of market formation.

Fix Recommendations

  1. Implement a grace period:

uint256 public constant FUNDING_GRACE_PERIOD = 1 days;
function getProportionalElapsedSinceLastFunding(Data storage self) internal view returns (UD60x18) {
if (block.timestamp < self.lastFundingTime + FUNDING_GRACE_PERIOD) {
return UD60x18_ZERO;
}
// ... existing calculation
}
  1. Alternative: Initialize with future timestamp:

function create(CreateParams memory params) internal {
// ...
self.lastFundingTime = block.timestamp + FUNDING_GRACE_PERIOD;
// ...
}
  1. Or add initialization period handling:

function getCurrentFundingRate(Data storage self) internal view returns (SD59x18) {
if (block.timestamp < self.lastFundingTime + FUNDING_GRACE_PERIOD) {
return SD59x18_ZERO;
}
// ... existing calculation
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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