x_last_price uses global timestamp incorrectly
The x_last_price function uses the global latest timestamp to compute a cross-price, but if only one asset was updated at that timestamp, it returns None even though a valid cross-price exists at an earlier timestamp. This can cause consumers to see no price and potentially halt trading.
Originally disclosed on Code4rena
Submitted by HUNTERRRRRRR
price_oracle.rs #L218
x_last_price looks up the global latest timestamp and tries to compute a cross-price at that exact tick:
pub fn x_last_price(e: &Env, base_asset: Asset, quote_asset: Asset) -> Option<PriceData> {
let timestamp = prices::obtain_last_record_timestamp(&e); // global last tick
if timestamp == 0 {
return None;
}
let decimals = settings::get_decimals(e);
let asset_pair_indexes = assets::resolve_asset_pair_indexes(e, base_asset, quote_asset)?;
prices::load_cross_price(&e, asset_pair_indexes, timestamp, decimals)
}
If the most recent snapshot updated only one of the two assets (partial update), one side of the pair may have no record at that timestamp, so load_cross_price returns None even though a valid cross-price does exist at the previous timestamp; where both assets were present.
In effect, x_last_price can intermittently return None (or fail upstream logic) right after a partial update. This is a critical logic flaw for consumers that rely on a “latest” cross-price.
- Availability/DoS risk: A price publisher that posts a partial snapshot (only base or quote) causes
x_last_priceto report “no price,” potentially halting trading or causing fallbacks. - Inconsistency: Other functions (
x_prices,x_twap) correctly scan backward over history viaprices::load_prices, so the “latest” behavior differs depending on which API is called.
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 function uses the global latest timestamp instead of finding the most recent timestamp where both assets have records.
Impact
A price publisher posting a partial snapshot could cause x_last_price to report no price, potentially halting trading or causing fallbacks.
What the attacker needed
A price publisher posts a partial snapshot
The fix
The function should scan backward over history to find the most recent timestamp where both assets have records, similar to x_prices and x_twap.
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.
This is a bug in a price oracle that gives the latest price for a pair of assets. When only one asset gets a new price, the function looks for both at that same moment and finds nothing, so it says there is no price even though an older valid price exists.
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.