In the current implementation, when updatePerpMarketConfiguration is called and the value for scewScale or maxFundingVelocity is changed, the fundingRate and the fundingFeePerUnit are not updated before the change. This means the new values for scewScale and maxFundingVelocity are used the next time the fundingRate and the fundingFeePerUnit are calculated. This messes up the accruedFunding of the market and can lead to significant financial loss for users.
The fundingRate is an indicator of how much a holder of a long/ short position must pay/earns for holding his position. If the funding rate is positive, meaning that the marketPrice is above the assets price, holders of long positions need to pay a fee to holders of short positions and vice versa. The fees that need to be paid per unit of position size are tracked in the variable fundingFeePerUnit.
To calculate the market's value of fundingFeePerUnit first the currentFundingRate needs to be calculated. For the calculation of the currentFundingRate, the values for scewScale and maxFundingVelocity are used. This means a change in any of the market's values for scewScale and maxFundingVelocity directly impacts the fees that users earn/have to pay for holding positions in the market.
The issue arises from the fact that when updatePerpMarketConfiguration is called and the value for scewScale or maxFundingVelocity is changed, the values for fundingFeePerUnit and currentFundingRate are not updated to reflect the fees accrued until the change. The result is that the new values for scewScale an maxFundingVelocity are used next time fundingFeePerUnit and currentFundingRate are updated which can result in a significant shift in fees that need to be payed/were earned by the users.
When updatePerpMarketConfiguration is called, check if the value for scewScale and/or maxFundingVelocity is changed. If this is the case, make sure to update fundingFeePerUnit and currentFundingRate of the market before setting the new values. This ensures that the fees accumulated until the change are represented correctly.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.