# Value of asset token can be incorrect when usage of ETH/USD Chainlink oracle is needed

ChainlinkOracleConnector.getValue returns ETH-decimals (18) instead of USD-decimals (8) when routing token→ETH→USD, inflating asset values ~10^10x.

- Payout: Audit contest
- Severity: high
- Program: NOYA
- Found by: rbserver
- Disclosed: 2025-02-17
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-noya-findings/issues/1509
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:oracle-manipulation

**Target:** NoyaValueOracle / ChainlinkOracleConnector price conversion
**Root cause:** getValue treats ETH/USD feed as 8-decimal source (source.decimal()) when decimalsSource is ETH/USD, but the intermediate amount is in ETH's 18 decimals, so the final USD value is off by 10^10.
**Steps:**
1. Configure price route USDC→USD via [ETH] using USDC/ETH and ETH/USD feeds.
2. Call `noyaOracle.getValue(USDC, USD, 1e6)`; observe result 998152930103816659 (18 decimals) vs direct USDC/USD result 99998495 (8 decimals).
3. Ratio valueIndirect/valueDirect = 9981679525 confirms 10-decimal inflation.
**How found:** Code reading of getValue's decimalsSource selection: noticed ETH/USD feed's own decimals (8) used as sourceTokenUnit while amountIn is in ETH's 18 decimals, producing unit mismatch.
**Exploitation:** Any protocol logic relying on getValue for tokens lacking token/USD oracles (collateral valuation, share pricing, liquidation thresholds) receives values inflated by ~10^10, enabling over-borrowing or mispriced withdrawals.
**Insight:** When chaining oracle routes, verify the intermediate amount's decimals match the feed's assumed source unit; feeds for pseudo-assets (ETH/USD) report their own decimals, not the intermediate token's.

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

**Foundry test proving ETH/USD oracle decimal bug**

```
function test_assetTokenValueIsIncorrectWhenETHUSDChainlinkOracleIsNeeded() public {
        // Some tokens do not have token/USD oracle so token/ETH and ETH/USD oracles need to be used.
        // Following code compares method using token/ETH and ETH/USD oracles indirectly to method using token/USD oracle directly.

        address ETH_USD_FEED = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;

        vm.startPrank(owner);

        addTokenToChainlinkOracle(address(USDC), address(840), address(USDC_USD_FEED));
        addTokenToChainlinkOracle(address(USDC), address(0), address(USDC_ETH_FEED));
        addTokenToChainlinkOracle(address(0), address(840), address(ETH_USD_FEED));

        addTokenToNoyaOracle(address(USDC), address(chainlinkOracle));
        addTokenToNoyaOracle(address(0), address(chainlinkOracle));
        addTokenToNoyaOracle(address(840), address(chainlinkOracle));

        uint256 valueDirect = noyaOracle.getValue(address(USDC), address(840), 1e6);

        // when using USDC/USD oracle directly, 1e6 wei USDC is equivalent to 99998495 wei USD, which is in USD's decimals that is 8
        assertEq(valueDirect, 99998495);

        address[] memory assets = new address[](1);
        assets[0] = address(0);
        noyaOracle.updatePriceRoute(address(USDC), address(840), assets);

        uint256 valueIndirect = noyaOracle.getValue(address(USDC), address(840), 1e6);

        // when using USDC/ETH and ETH/USD oracles indirectly, 1e6 wei USDC is equivalent to 998152930103816659 wei USD, which is in ETH's decimals that is 18
        assertEq(valueIndirect, 998152930103816659);

        // value of 1e6 wei USDC is incorrectly much higher when using USDC/ETH and ETH/USD oracles indirectly comparing to using USDC/USD oracle directly
        assertEq(valueIndirect / valueDirect, 9981679525);

        vm.stopPrank();
    }
```

