{"record":{"id":"fc3f5d0e3637b484","repo":"nautechsystems/nautilus_trader","slug":"decimal-exponent-exponent-exceeds-supported-maxi","errorCode":null,"errorMessage":"Decimal exponent {exponent} exceeds supported maximum {DECIMAL_EXPONENT_MAX}","messagePattern":"Decimal exponent (.+?) exceeds supported maximum (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/tick_map/full_math.rs","lineNumber":142,"sourceCode":"        let mut quotient = Self::mul_div(a, b, denominator)?;\n        let mut remainder = a.mul_mod(b, denominator);\n\n        for &scale in scales {\n            let scaled_quotient = quotient\n                .checked_mul(scale)\n                .ok_or_else(|| anyhow::anyhow!(\"Scaled result exceeds 256-bit range\"))?;\n            let scaled_remainder = Self::mul_div(remainder, scale, denominator)?;\n            quotient = scaled_quotient\n                .checked_add(scaled_remainder)\n                .ok_or_else(|| anyhow::anyhow!(\"Scaled result exceeds 256-bit range\"))?;\n            remainder = remainder.mul_mod(scale, denominator);\n        }\n\n        Ok(quotient)\n    }\n\n    pub(crate) fn check_decimal_exponent(exponent: u8) -> anyhow::Result<()> {\n        anyhow::ensure!(\n            exponent <= DECIMAL_EXPONENT_MAX,\n            \"Decimal exponent {exponent} exceeds supported maximum {DECIMAL_EXPONENT_MAX}\"\n        );\n        Ok(())\n    }\n\n    pub(crate) fn pow10(exponent: u8) -> anyhow::Result<U256> {\n        Self::check_decimal_exponent(exponent)?;\n        U256::from(10)\n            .checked_pow(U256::from(exponent))\n            .ok_or_else(|| anyhow::anyhow!(\"Decimal exponent {exponent} exceeds U256 range\"))\n    }\n\n    /// Calculates ceil(a×b÷denominator) with full precision\n    /// Returns `Ok` with the rounded result or an error when rounding cannot be performed safely.\n    ///\n    /// # Errors\n    ///","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/tick_map/full_math.rs#L124-L160","documentation":"`check_decimal_exponent` validates that a decimal exponent (number of fractional digits to represent) does not exceed `DECIMAL_EXPONENT_MAX`, the largest power of ten the tick-map math supports. The library throws this when a token's decimals or a requested exponent exceeds that cap.","triggerScenarios":"Calling `check_decimal_exponent` or its callers (`pow10`, price decoding paths) with an exponent greater than DECIMAL_EXPONENT_MAX — e.g. tokens with unusually high decimal counts or misparsed decimals metadata.","commonSituations":"Token metadata from an unknown/nonstandard chain reporting decimals above the supported maximum; a config value or ABI-decoded field containing garbage that lands in the exponent slot.","solutions":["Cap or reject the token: check `decimals <= DECIMAL_EXPONENT_MAX` when loading token metadata.","Re-fetch correct token decimals from a trusted source (on-chain call, token list).","If the exponent comes from config, validate/clamp it at load time.","Extend DECIMAL_EXPONENT_MAX only if the surrounding math is proven safe."],"exampleFix":"// before\nlet factor = pow10(token.decimals)?;\n// after\nensure!(token.decimals <= DECIMAL_EXPONENT_MAX, \"unsupported token decimals {}\", token.decimals);\nlet factor = pow10(token.decimals)?;","handlingStrategy":"validation","validationCode":"fn valid_decimals(d: u8) -> bool { d <= DECIMAL_EXPONENT_MAX }","typeGuard":"fn is_supported_exponent(e: u8) -> bool { e <= DECIMAL_EXPONENT_MAX }","tryCatchPattern":"match pow10(exponent) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"exceeds supported maximum\") => {\n        log::warn!(\"unsupported decimal exponent {exponent}\"); U256::one()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate token decimals when loading token metadata, rejecting unsupported tokens early","Sanitize ABI-decoded decimals fields (cap at 36 for standard EVM tokens)","Keep DECIMAL_EXPONENT_MAX visible in config validation messages"],"tags":["math","validation","decimals","tick-map"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}