Skip to content
Business logic Audit finding Intermediate

Use of incorrect index leads to incorrect updation of funding rates

The updateFundingRate function incorrectly calculates the cumulative funding rate by always adding the instant rate to zero instead of the previous cumulative value, due to using the current funding index instead of the previous one. This causes incorrect funding rates and affects account settlement across the protocol, potentially leading to user fund loss and protocol shutdown.

0xRajeev Follow

Originally disclosed on Code4rena

Submitted by 0xRajeev

The updateFundingRate() function updates the funding rate and insurance funding rate. While the instant/new funding rates are calculated correctly, the cumulative funding rate calculation is incorrect because it is always adding the instant to 0, not the previous value. This is due to the use of [currentFundingIndex] which has been updated since the previous call to this function while it should really be using [currentFundingIndex-1] to reference the previous funding rate.

The impact of this, is that the cumulative funding rate and insurance funding rates are calculated incorrectly without considering the correct previous values. This affects the settling of accounts across the entire protocol. The protocol logic is significantly impacted, accounts will not be settled as expected, protocol shutdown and contracts will need to be redeployed. Users may lose funds and the protocol takes a reputation hit.

Recommend using [currentFundingIndex-1] for non-zero values of currentFundingIndex to get the value updated in the previous call on lines L155 and L159 of Pricing.sol.

raymogg (Tracer) confirmed:

Confirmed as an index issue with funding rate 👍

The original report as published on Code4rena, by 0xRajeev. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code uses the current funding index instead of the previous one when reading the previous cumulative funding rate, so it always adds to zero.

Impact

The cumulative funding rate and insurance funding rates are calculated incorrectly, affecting account settlement across the protocol, potentially causing user fund loss and requiring contract redeployment.

What the attacker needed

None

The fix

The code should be fixed by using the previous index (currentFundingIndex-1) for non-zero values of currentFundingIndex on lines L155 and L159 of Pricing.sol.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract function that updates funding rates mistakenly uses the wrong index to look up the previous cumulative rate, so it always starts from zero. This means the cumulative rate is wrong, which can mess up account balances and cause financial losses for users.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0xRajeev

View all

61 more disclosed reports, best first.

More from Tracer contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.