# RedStone oracle is vulnerable because ```updatePrice``` is not called during the ```getEthValue``` function.

RedStone oracle's updatePrice is never called by getValueInEth, letting borrowers keep stale favorable prices to inflate collateral and borrow against wrong ETH values.

- Payout: Audit contest
- Severity: medium
- Program: Sentiment
- Found by: ZeroTrust
- Disclosed: 2024-08-07
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-sentiment-v2-judging/issues/161
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-sentiment-v2%3AM-7
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:oracle-manipulation

**Target:** RedstoneOracle price feed contract (getValueInEth/updatePrice)
**Root cause:** getValueInEth reads assetUsdPrice/ethUsdPrice state variables but never calls updatePrice(), so prices stay stale until someone externally pushes them; priceTimestamp is set to block.timestamp - 3 minutes, giving a 3-minute liveness window.
**Steps:**
1. Observe RedstoneOracle.getValueInEth is `view` and only checks priceTimestamp against STALE_PRICE_THRESHOLD, never refreshing prices.
2. Note updatePrice() is external and permissionless, pulling values via getOracleNumericValuesFromTxMsg.
3. Borrower calls updatePrice() when collateral price is high, then refrains from calling it when price drops.
4. Borrower takes a loan valued at the stale inflated collateral price, repays after real price moves, extracting value.
**How found:** Code reading of RedstoneOracle: noticed getValueInEth is view and reads state prices, then grepped for callers of updatePrice() and found none, hypothesizing stale-price manipulation.
**Exploitation:** A borrower selectively calls the permissionless updatePrice() only when the oracle price favors them, leaving stale high collateral valuations in place to borrow more than the true collateral value supports, then repays at the correct lower price.
**Insight:** When an oracle exposes a permissionless push function separate from the read path, check whether the read path ever refreshes; if not, a borrower can cherry-pick when to push, so stale-price windows become user-controlled rather than bot-controlled.

## Proof of concept (copied exactly from the original report)

**getValueInEth reads stale price without updatePrice**

```
function getValueInEth(address, uint256 amt) external view returns (uint256) {
        if (priceTimestamp < block.timestamp - STALE_PRICE_THRESHOLD) revert RedstoneCoreOracle_StalePrice(ASSET);

        // scale amt to 18 decimals
        if (ASSET_DECIMALS <= 18) amt = amt * 10 ** (18 - ASSET_DECIMALS);
        else amt = amt / 10 ** (ASSET_DECIMALS - 18);

        // [ROUND] price is rounded down
        return amt.mulDiv(assetUsdPrice, ethUsdPrice);
    }
```

**updatePrice external function setting prices**

```
function updatePrice() external {
        // values[0] -> price of ASSET/USD
        // values[1] -> price of ETH/USD
        // values are scaled to 8 decimals
        uint256[] memory values = getOracleNumericValuesFromTxMsg(dataFeedIds);

        assetUsdPrice = values[0];
        ethUsdPrice = values[1];

        // RedstoneDefaultLibs.sol enforces that prices are not older than 3 mins. since it is not
        // possible to retrieve timestamps for individual prices being passed, we consider the worst
        // case and assume both prices are 3 mins old
        priceTimestamp = block.timestamp - THREE_MINUTES;
    }
```

