{"record":{"id":"92b9baab8e6502d9","repo":"nautechsystems/nautilus_trader","slug":"executed-amount-scaling-overflow","errorCode":null,"errorMessage":"Executed amount scaling overflow","messagePattern":"Executed amount scaling overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":5256,"sourceCode":"\nfn fill_price_from_quote(\n    last_qty: Quantity,\n    quote_amount: U256,\n    quote_currency: Currency,\n) -> anyhow::Result<Price> {\n    let quote = Money::from_u256(quote_amount, quote_currency)?;\n    Price::from_decimal_dp(quote.as_decimal() / last_qty.as_decimal(), FIXED_PRECISION)\n        .map_err(anyhow::Error::from)\n}\n\nfn raw_amount_to_quantity(amount: U256, decimals: u8) -> anyhow::Result<Quantity> {\n    if amount.is_zero() {\n        anyhow::bail!(\"Executed amount must be positive\");\n    }\n    let quantity = if decimals >= FIXED_PRECISION {\n        let scale = U256::from(10u64)\n            .checked_pow(U256::from(decimals - FIXED_PRECISION))\n            .ok_or_else(|| anyhow::anyhow!(\"Executed amount scaling overflow\"))?;\n        Quantity::from_u256(amount / scale, FIXED_PRECISION).map_err(anyhow::Error::from)?\n    } else {\n        Quantity::from_u256(amount, decimals).map_err(anyhow::Error::from)?\n    };\n\n    if quantity.is_zero() {\n        anyhow::bail!(\n            \"Executed amount {amount} is below representable quantity precision {FIXED_PRECISION}\"\n        );\n    }\n    Ok(quantity)\n}\n\nfn exact_output_amount(quote: &SwapQuote, zero_for_one: bool) -> anyhow::Result<U256> {\n    let amount = if zero_for_one {\n        quote.amount1\n    } else {\n        quote.amount0","sourceCodeStart":5238,"sourceCodeEnd":5274,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L5238-L5274","documentation":"When mapping an executed (filled) raw on-chain amount back to a Quantity, if token decimals exceed FIXED_PRECISION the client divides by 10^(decimals - FIXED_PRECISION). This error is thrown when that scale power overflows U256, so the executed amount cannot be reduced to fixed precision.","triggerScenarios":"Processing a fill/execution event for a token whose decimals - FIXED_PRECISION exponent makes 10^(decimals - FIXED_PRECISION) exceed U256::MAX (implausibly large decimals on the token metadata).","commonSituations":"Reconciling execution reports for a token with misreported decimals; indexing events from an unvetted token contract with corrupt decimals.","solutions":["Correct the token decimals in the instrument/chain metadata to the contract's actual value","Skip or quarantine executions for tokens with implausible decimals until metadata is verified","Validate decimals bounds when registering the token with the execution client"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn assert_exec_amount_decodable(decimals: u32) -> Result<(), String> {\n    if decimals.saturating_sub(FIXED_PRECISION) > 78 {\n        Err(format!(\"decimals {decimals} too large to reduce executed amount\".into()))\n    } else { Ok(()) }\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Executed amount scaling overflow\") => { /* quarantine token, fix metadata */ }\n    other => other?,\n}","preventionTips":["Verify decimals in token metadata before accepting fills for that token","Quarantine unknown tokens until their metadata is validated","Monitor decimal deltas when ingesting new token listings"],"tags":["overflow","u256","arithmetic","blockchain","fill-processing"],"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-14T00:17:10.932Z"}