# ETHOracle.getLatestPrice needs to convert to 18 decimals

ETHOracle reports Chainlink's 8-decimal ETH/USD price as 18-decimal precision, inflating collateral valuation in StrategyLeverage and enabling overborrowing.

- Payout: Audit contest
- Severity: high
- Program: BakerFi
- Found by: bin2chen
- Disclosed: 2024-06-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-bakerfi-findings/issues/47
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-bakerfi%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:** ETHOracle / StrategyLeverage price feed integration
**Root cause:** ETHOracle.getLatestPrice returns the raw Chainlink answer (8 decimals) while getPrecision() claims 10**18, so ETH price is understated by 10^10 relative to collateral price used in totalCollateralInEth.
**Steps:**
1. Read ETHOracle.sol: _PRECISION = 10**18 but _ethPriceFeed is the Arbitrum ETH/USD Chainlink feed with 8 decimals.
2. getLatestPrice returns price.price = uint256(answer) with no scaling.
3. In StrategyLeverage._getPosition, totalCollateralInEth = (collateralBalance * collateralPrice.price) / ethPrice.price.
4. Because ethPrice.price is 10^10 too small, totalCollateralInEth is inflated by 10^10.
5. Borrowing/health checks use the inflated collateral value, permitting overborrowing.
**How found:** Code reading: noticed getPrecision() declares 18 decimals while the referenced Chainlink feed is documented as 8 decimals, then traced the raw answer into the collateral/debt ratio math.
**Exploitation:** Attacker opens a leveraged position; the inflated totalCollateralInEth lets them borrow far beyond the intended collateral ratio, extracting excess debt value from the protocol.
**Insight:** When an oracle wrapper hardcodes a precision constant, cross-check it against the actual feed's decimals (Chainlink ETH/USD is 8) and trace every downstream division/multiplication for scale mismatch.

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

**ETHOracle getLatestPrice returns raw 8-decimal answer**

```
function getLatestPrice() public view override returns (IOracle.Price memory price) {
        (, int256 answer, uint256 startedAt, uint256 updatedAt,) = _ethPriceFeed.latestRoundData();
        if ( answer<= 0 ) revert InvalidPriceFromOracle();        
        if ( startedAt ==0 || updatedAt == 0 ) revert InvalidPriceUpdatedAt();    

@>      price.price = uint256(answer);  //@audit 8 decimals
        price.lastUpdate = updatedAt;
```

**totalCollateralInEth divides by 8-decimal ethPrice**

```
totalCollateralInEth = (collateralBalance * collateralPrice.price) / ethPrice.price;
```

