How to prove a priceUpdate is the latest available?

uint fee = oracle.getUpdateFee(priceUpdate);
oracle.updatePriceFeeds{ value: fee }(priceUpdate);
PythStructs.Price memory price = oracle.getPriceNoOlderThan(priceFeedId, 30);

The price only has publishTime and no other time guarantees. How can I prove a price update is the most recent (or at least within TTL of the expiry). If the price is from an asset that doesn’t trade 24/7, the publishTime will be the time the last price change happened before markets closed. Is there anyway I can prove no updates happened after this up to current time - TTL?

Latest price response from Hermes API has metadata with slot and proof_available_time, for example:

{
  "binary": {
    "encoding": "hex",
    "data": [
      "…"
    ]
  },
  "parsed": [
    {
      "id": "b1073854ed24cbc755dc527418f52b7d271f6cc967bbf8d8129112b18860a593",
      "price": {
        "price": "18187100",
        "conf": "17266",
        "expo": -5,
        "publish_time": 1759176019
      },
      "ema_price": {
        "price": "18154805",
        "conf": "11032",
        "expo": -5,
        "publish_time": 1759176019
      },
      "metadata": {
        "slot": 245773653,
        "proof_available_time": 1759190658,
        "prev_publish_time": 1759176019
      }
    }
  ]
}

Is there any way to prove this?

function getPriceNoOlderThan(
    bytes32 id,
    uint age
) public view virtual override returns (PythStructs.Price memory price) {
    price = getPriceUnsafe(id);

    if (diff(block.timestamp, price.publishTime) > age)
        revert PythErrors.StalePrice();

    return price;
}

I assume what I’m asking is not possible? its based on publishedTime which will not update if market is closed?

1 Like

That’s true.
When you fetch from hermes v2/update/price/latest , it will return the latest price which was published & aggregated on pythnet(oracle infra).

Right, so if any proof is submitted onchain, you can only prove that the data is newer than the last known price. But no idea if there are more proofs more recent or the one submitted was the most recent within a time range

Eg last price onchain is from now-1hr, user submits a proof of an update with timestamp of now-30min, no way to prove there are no available proofs since now-30min and now

You are absolutely right.

On the other hand, all crypto are reference rates price feeds are being updated every 400ms 24x7.
There are some exception that you can find in our market hours page.

This is an issue for tradfi markets though. Does Laser have any better guarantees about data?

That’s why we recommend folks to use getPriceNoOlderThan with a threshold(age) as per your need. We see alot of users use 30~60 seconds.

API Reference for getPriceNoOlderThan.

If this fails, you can update with the latest price, hence making sure that you are getting the latest price.

Yes but the lack of no new price updates could be from many things.
Market hours, emergency circuit breaker, pythnet being down, or users not supplying a fresh price update onchain. There is no way to differentiate between no new price available or no new price provided afaik

@0xjimmy this is a great question. Unfortunately we don’t have an easy way to do it as each price has it’s own timestamp. However, if you feel a bit hacky, there are ways to proof it by making some assumptions on how the data is generated.

What you can do, is to bundle your asset with a 24/7 asset like Bitcoin and check the timestamp of Bitcoin as an estimate of the time this data was published. You need to ensure the updateData.length == 1 to have a guarantee that both your asset and Bitcoin are generated from the same block (hence same time) on Pythnet.

If you read about Pyth message format (for instance from here) you see all prices form a merkle tree and the root of merkle tree authenticity is verified for cross-chain usage along the merkle proofs for the given prices. In an updateData you see an array of bytes, and if there’s only one element it means the price updates have the same merkle root and that single element (updateData[0]) contains merkle proofs for all of them.

Please note that this is relying on the internals of the system, they rarely change but if they change, they’ll be posted in this forum. So if you use it, please check the forum regularly.