nautechsystems/nautilus_trader · error
Price overflow: {price_raw} exceeds maximum valid raw price
Error message
Price overflow: {price_raw} exceeds maximum valid raw price {PRICE_RAW_MAX} What it means
price_from_u256 converts the decoded raw fixed-point price (U256) into the library's Price type. It first checks the value against PRICE_RAW_MAX; the decoded price exceeded that maximum, so it cannot be represented as a Price with FIXED_PRECISION. The library throws this rather than silently saturating, to preserve exactness of price values.
Source
Thrown at crates/model/src/defi/tick_map/sqrt_price_math.rs:444
.ok_or_else(|| anyhow::anyhow!("Inverted price exceeds U256 range"))?
}
} else if decimal_diff >= 0 {
FullMath::mul_div_scaled(
sqrt_price,
sqrt_price,
divisor_base,
&[fixed_scalar, decimal_adjustment],
)?
} else {
FullMath::mul_div_scaled(sqrt_price, sqrt_price, divisor_base, &[fixed_scalar])?
/ decimal_adjustment
};
price_from_u256(price_raw)
}
pub(crate) fn price_from_u256(price_raw: U256) -> anyhow::Result<Price> {
anyhow::ensure!(
price_raw <= U256::from(PRICE_RAW_MAX as u128),
"Price overflow: {price_raw} exceeds maximum valid raw price {PRICE_RAW_MAX}"
);
let price_raw: i128 = price_raw
.try_into()
.map_err(|_| anyhow::anyhow!("Price overflow: {price_raw} exceeds PriceRaw range"))?;
Price::from_raw_checked(price_raw, FIXED_PRECISION).map_err(Into::into)
}
#[cfg(test)]
mod tests {
// Most of the tests are based on https://github.com/Uniswap/v3-core/blob/main/test/SqrtPriceMath.spec.ts
use rstest::*;
use super::*;
use crate::defi::tick_map::{
full_math::{DECIMAL_EXPONENT_MAX, Q96_U160},View on GitHub (pinned to 18893faf8b)
Solutions
- Verify token decimals are correct for the pair; wrong decimals inflate the decoded price.
- Check the sqrt_price_x96 source data for corruption; extreme prices may indicate a misconfigured or malicious pool.
- Clamp at the caller: catch the error and cap the price at the maximum representable value, or skip the pool.
- Use a wider custom representation if your application genuinely needs prices beyond PRICE_RAW_MAX.
Example fix
// before
let price = decode_sqrt_price_x96_to_price(sqrt_price_x96)?;
// after
let price = match decode_sqrt_price_x96_to_price(sqrt_price_x96) {
Ok(p) => p,
Err(e) if e.to_string().contains("Price overflow") => {
// pool price beyond representable range; treat as extreme
return Ok(Price::max(FIXED_PRECISION));
}
Err(e) => return Err(e),
}; Defensive patterns
Strategy: try-catch
Validate before calling
fn raw_price_fits(price_raw: U256) -> bool {
price_raw <= U256::from(PRICE_RAW_MAX as u128)
} Try / catch
match decode_sqrt_price_x96_to_price(sp) {
Ok(p) => p,
Err(e) if e.to_string().contains("exceeds maximum valid raw price") => {
tracing::warn!("pool price beyond representable range");
Price::max(FIXED_PRECISION)
}
Err(e) => return Err(e),
} Prevention
- Verify token decimals before decoding — the top cause of price overflow
- Treat extreme decoded prices as a data-quality signal for the pool
- Saturate to Price::max/zero at the application boundary instead of propagating
When it happens
Trigger: Any decode path (decode_sqrt_price_x96_to_price or decode_sqrt_price_x96_to_price_tokens_adjusted, called by execution_price/spot_price) where the computed price_raw exceeds PRICE_RAW_MAX (i.e. does not fit i128), typically with extreme sqrt_price_x96 values or huge decimal adjustments.
Common situations: Decoding slot0 prices for pools with extreme prices (nearly all one token); misconfigured token decimals inflating the decimal adjustment; corrupted or malicious on-chain sqrt price data.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Cannot calculate price impact, the spot price before is not
- Cannot calculate execution price with zero amounts
- invalid price `{value}` at precision {precision}: {e}
- Inverted price numerator exceeds U512 range
- Inverted price exceeds U256 range
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/e87c5327c63c14c8.
Report an issue: GitHub.