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

Funding Rate Should Not Use FillPrice

Summary

When calculating funding, fillPrice should not be used as it is unfair to short traders who pay more fees for helping to balance the skew.

Vulnerability Detail

In _fillOrder, when calculating funding, fillPrice is used:

function _fillOrder() {
...
ctx.fundingFeePerUnitX18 = perpMarket.getNextFundingFeePerUnit(ctx.fundingRateX18, fillPriceX18);
...
}

fillPrice includes a premium/discount according to how the trader affected the current market skew. As a result, shorts unfairly pay more fees when they balance the market and less when they imbalance the market.

Consider this scenario:

  • index price = 1000

  • short trade (positive price impact), fill price = 1010 => more fees are paid

  • short trade (negative price impact), fill price = 990 => less fees are paid

Also applicable to getAccountMarginRequirementUsdAndUnrealizedPnlUsd where funding is calculated using fillPrice as well.

Impact

Short traders are not incentivized to balance long skew, but incentivized to worsen short skew. This leads to persistent imbalanced skew which is detrimental to all traders as fill price cannot converge with true oracle price.

Code Snippet

https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/branches/SettlementBranch.sol#L393

Tool used

Manual Review

Recommendation

Use an oracle price instead of fillPrice to calculate funding.

Updates

Lead Judging Commences

inallhonesty Lead Judge
over 1 year ago
inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Appeal created

giraffe0x Submitter
over 1 year ago
inallhonesty Lead Judge
over 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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

Give us feedback!