# Missing staleness check in PythOracle can lead to forced liquidations and theft of funds from borrowers.

PythOracle uses getPriceUnsafe() without staleness check, letting attackers push old favorable Pyth prices to force liquidations and steal borrower funds.

- Payout: Audit contest
- Severity: medium
- Program: Mach Finance
- Found by: 0xRiO
- Disclosed: 2024-12-13
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-mach-finance-judging/issues/41
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-mach-finance%3AM-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:liquidation vuln:oracle-manipulation

**Target:** PythOracle price feed integration on Sonic chain
**Root cause:** PythOracle reads prices via getPriceUnsafe() and only checks price > 0, never validating the publish timestamp or falling back to a secondary oracle, so arbitrarily old prices are accepted.
**Steps:**
1. Identify that PythOracle.sol calls getPriceUnsafe() and only validates price > 0 (no timestamp check).
2. Wait until Pyth feeds for two supported assets are stale (no keeper updates for days).
3. Construct a tx calling Pyth updatePriceFeeds() with valid price components whose timestamps fall between the last update and now.
4. Set borrow asset price to an inflated historical value and collateral asset price to a deflated historical value.
5. Trigger liquidation of the victim whose shortfall now falls below 1 under the manipulated prices.
**How found:** Researcher read the PythOracle integration, noticed getPriceUnsafe() usage, and recognized that Pyth docs' claim of reverting on stale prices is false—the function returns the price with its timestamp regardless of age. Contrasted with Compound V2's Chainlink oracle reasoning (Chainlink can't be pushed by anyone, Pyth can) to establish exploitability.
**Exploitation:** Attacker submits a transaction that updates Pyth feeds with older-but-valid signed price components: inflated price for the borrowed asset and deflated price for the collateral. The protocol accepts these stale prices, the victim's health factor drops below 1, and the attacker liquidates the position, capturing the liquidation bonus and value from the borrower.
**Insight:** When integrating Pyth, getPriceUnsafe() never reverts on staleness despite docs implying otherwise—always compare publishTime against a heartbeat and add a fallback oracle; also note that on chains without sponsored feeds, anyone can push arbitrary historical signed prices, so staleness is attacker-controllable.

