Skip to content
Business logic Audit finding Intermediate

Stale prices can cause inaccurate validation of funding ticks in funding_tick()

The funding tick validation uses the synthetic asset price without checking whether it is stale, so an outdated price can let invalid funding rate changes pass or valid ones fail. This can lead to incorrect collateral balances and health checks.

alexxander Follow with 0xNirix, dystopia and 4 others

Originally disclosed on Code4rena

Submitted by alexxander, also found by 0xNirix, dystopia, kanra, m4k2, montecristo, and SBSecurity

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/components/assets/assets.cairo#L288-L323

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/components/assets/assets.cairo#L633-L649

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/components/assets/assets.cairo#L508-L516

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/types/funding.cairo#L103-L117

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/components/positions/positions.cairo#L445-L448

https://github.com/code-423n4/2025-03-starknet/blob/512889bd5956243c00fc3291a69c3479008a1c8a/workspace/apps/perpetuals/contracts/src/core/components/positions/positions.cairo#L534-L544

Finding description and impact

The function assets.funding_tick() updates the funding index for all active synthetic assets. This helps ensure that long and short positions are economically balanced over time. The function can be called only by the operator and takes as an input the parameter funding_ticks which is a list of FundingTick structs, each specifying an asset_id and its new funding_index. The number of funding_ticks provided matches the number of active synthetic assets and each active asset receives a funding tick update. For every funding tick in funding_ticks, the function `assets.

_process_funding_tick() is executed with the new funding tick for the asset and the storage read max_funding_rate where downstream the function funding.validate_funding_rate() is executed. This function validates that the change in the old and new funding index doesn’t violate the max_funding_rate, however, the function relies on the price of the synthetic asset fetched through get_synthetic_price().

However, get_synthetic_price() retrieves the asset price from self.synthetic_timely_data but does not check if the price is up to date. This can result in the use of stale prices, which can cause incorrect validation of the funding rate. As a result, invalid funding rate changes might incorrectly pass validation, or valid funding rate updates could be wrongly rejected. The more severe case is invalid funding rate changes passing validation since the funding tick directly affects the collateral balance of positions and can lead to erroneously updated balances - modification to the collateral balance based on the funding index happens in `positions.

_update_synthetic_balance_and_funding() and the funding index is also considered in health validations that use positions.get_collateral_provisional_balance().

Recommended mitigation steps

Validate that the price is up to date upon retrieving the price through get_synthetic_price(). A call to assets.validate_assets_integrity() would not work properly since the function also performs a check whether the funding indexes are up to date, however, funding_tick() must be successful when the funding indexes are out of date.

oded (Starknet Perpetual) confirmed

Code4rena judging staff adjusted the severity of Finding [M-01], after reviewing additional context provided by the sponsor.


The original report as published on Code4rena, by alexxander. 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

Likely the price retrieval function does not verify the timestamp or freshness of the stored synthetic price before using it in funding rate validation.

Impact

Invalid funding rate changes could pass validation, leading to erroneously updated collateral balances and incorrect health checks.

What the attacker needed

Operator calls funding_tick(); stale synthetic price exists

The fix

The price should be validated as up to date when retrieved through get_synthetic_price(), without requiring funding indexes to be current.

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 funding tick is a periodic update that adjusts balances between traders. The contract checks the size of the change using the asset's price, but it never checks how old that price is, so a very old price can make the check wrong.

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 alexxander

View all

10 more disclosed reports, best first.

More from Starknet Perpetual

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.