# IOracle.queryExchangeRate returns incorrect blockTimeMs

Nibiru's Oracle precompile returned current block time instead of last price-update time, so downstream staleness checks always passed on stale prices.

- Payout: Audit contest
- Severity: medium
- Program: Nibiru
- Found by: 3docSec
- Disclosed: 2025-02-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-11-nibiru-findings/issues/2
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AM-10
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:oracle-manipulation

**Target:** EVM Oracle precompile queryExchangeRate
**Root cause:** queryExchangeRate packs the blockTime from GetDatedExchangeRate, which is the current block time, not the timestamp when the price was last updated.
**Steps:**
1. Call `queryExchangeRate("unibi:uusd")` via the Oracle precompile at a block later than the price update
2. Observe returned blockTimeMs equals current block time, not the update time
3. Modify TestOracle_HappyPath to query 10s after SetPrice; assertion on blockTime fails
**How found:** Compared the precompile's documented semantics (Chainlink-style last-update timestamp for staleness checks) against the implementation, noticing GetDatedExchangeRate supplies current block time.
**Insight:** When a precompile/oracle wrapper mimics Chainlink's updatedAt, verify the keeper actually stores per-price timestamps rather than passing ctx.BlockTime() through.

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

**Modified Go test querying 10 seconds after price update**

```
func (s *OracleSuite) TestOracle_HappyPath() {
58: 	deps := evmtest.NewTestDeps()
59: 
60: 	s.T().Log("Query exchange rate")
61: 	{
62: 		deps.Ctx = deps.Ctx.WithBlockTime(time.Unix(69, 420)).WithBlockHeight(69)
63: 		deps.App.OracleKeeper.SetPrice(deps.Ctx, "unibi:uusd", sdk.MustNewDecFromStr("0.067"))
64: 
65: 		resp, err := deps.EvmKeeper.CallContract(
66: 			deps.Ctx.WithBlockTime(deps.Ctx.BlockTime().Add(10*time.Second)), //  @audit query 10 seconds later
67: 			embeds.SmartContract_Oracle.ABI,
68: 			deps.Sender.EthAddr,
69: 			&precompile.PrecompileAddr_Oracle,
70: 			false,
71: 			OracleGasLimitQuery,
72: 			"queryExchangeRate",
73: 			"unibi:uusd",
74: 		)
75: 		s.NoError(err)
76: 
77: 		// Check the response
78: 		out, err := embeds.SmartContract_Oracle.ABI.Unpack(string(precompile.OracleMethod_queryExchangeRate), resp.Ret)
79: 		s.NoError(err)
80: 
81: 		// Check the response
82: 		s.Equal(out[0].(*big.Int), big.NewInt(67000000000000000))
83: 		s.Equal(out[1].(uint64), uint64(69000))
84: 		s.Equal(out[2].(uint64), uint64(69))
```

