{"record":{"id":"5f4094df20ae438f","repo":"nautechsystems/nautilus_trader","slug":"finalized-transaction-gas-commission-overflow","errorCode":null,"errorMessage":"Finalized transaction gas commission overflow","messagePattern":"Finalized transaction gas commission overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":4834,"sourceCode":"        plan.pool.pool_identifier,\n        UnixNanos::from(timestamp_ns),\n    );\n    swap.calculate_trade_info(&plan.pool.token0, &plan.pool.token1, None)?;\n    let trade = swap\n        .trade_info\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized Swap has no calculated trade information\"))?;\n    anyhow::ensure!(\n        trade.order_side == plan.order.order_side(),\n        \"Finalized Swap side {} does not match {} order\",\n        trade.order_side,\n        plan.order.order_side()\n    );\n    let gas_cost = included\n        .receipt\n        .effective_gas_price\n        .checked_mul(U256::from(included.receipt.gas_used))\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized transaction gas commission overflow\"))?;\n    let commission = Money::from_u256(gas_cost, plan.pool.chain.native_currency())?;\n    let trade_digest = keccak256(format!(\"{}:{}\", included.tx_hash, swap.log_index));\n    let trade_digest = trade_digest.to_string();\n    let trade_id = TradeId::new_checked(&trade_digest[2..38])?;\n\n    if plan\n        .order\n        .trade_ids()\n        .iter()\n        .any(|existing| **existing == trade_id)\n    {\n        return Ok(None);\n    }\n\n    let venue_order_id = VenueOrderId::new_checked(included.tx_hash.to_string())?;\n    let ts_event = UnixNanos::from(timestamp_ns);\n    let last_px = match plan.order.order_side() {\n        OrderSide::Buy => fill_price_from_quote(last_qty, plan.amount_in, plan.quote_currency)?,","sourceCodeStart":4816,"sourceCodeEnd":4852,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L4816-L4852","documentation":"When computing the realized gas commission, the adapter multiplies the receipt's `effective_gas_price` by `gas_used` using checked U256 arithmetic. This error is thrown when that multiplication overflows U256, so the gas cost cannot be represented and the commission cannot be computed safely. It is a defensive arithmetic guard preventing an silently-wrapped gas value.","triggerScenarios":"A transaction receipt with an absurdly large `effective_gas_price` (e.g. post-EIP-1559 fields misparsed, or a chain reporting wei-scale values in a wrong unit) combined with `gas_used` such that `effective_gas_price * gas_used >= 2^256`.","commonSituations":"Adapter connected to a non-standard or misconfigured RPC whose receipt fields are malformed; chains with inflated base fees during extreme congestion producing very large prices combined with huge gas usage; parsing receipts from an incompatible chain (different units or field semantics).","solutions":["Verify the RPC endpoint returns standard-conforming receipt fields (effective_gas_price, gas_used) for the connected chain","Re-fetch the receipt from a trusted node to rule out malformed data","Check the chain is one supported by the adapter (gas unit semantics match)","If legitimate values are truly huge, restructure to compute commission with checked per-component math or a wider type before converting to Money"],"exampleFix":"// before\nlet gas_cost = effective_gas_price.checked_mul(U256::from(gas_used))\n    .ok_or_else(|| anyhow::anyhow!(\"Finalized transaction gas commission overflow\"))?;\n// after: sanity-check inputs first\nanyhow::ensure!(gas_used <= 30_000_000, \"implausible gas_used {}\", gas_used);\nanyhow::ensure!(effective_gas_price <= U256::from(1_000_000_000_000_000_000u64), \"implausible gas price\");\nlet gas_cost = effective_gas_price.checked_mul(U256::from(gas_used))\n    .ok_or_else(|| anyhow::anyhow!(\"Finalized transaction gas commission overflow\"))?;","handlingStrategy":"validation","validationCode":"// before trusting receipt values\nensure!(included.receipt.gas_used > 0 && included.receipt.gas_used <= 30_000_000, \"implausible gas_used\");\nensure!(included.receipt.effective_gas_price <= U256::from(1_000_000_000_000_000_000u64), \"implausible gas price\");","typeGuard":"fn plausible_receipt(r: &TransactionReceipt) -> bool {\n    r.gas_used > 0 && r.gas_used <= 30_000_000 && r.effective_gas_price <= U256::from(1_000_000_000_000_000_000u64)\n}","tryCatchPattern":"let gas_cost = match effective_gas_price.checked_mul(U256::from(gas_used)) {\n    Some(c) => c,\n    None => {\n        log::error!(\"gas commission overflow: verify receipt from a trusted RPC\");\n        return Err(anyhow::anyhow!(\"gas commission overflow\"));\n    }\n};","preventionTips":["Use a reputable RPC endpoint that returns standards-compliant receipts","Sanity-check receipt gas fields against block gas limits before arithmetic","Only connect the adapter to chains whose gas unit semantics it supports"],"tags":["rust","blockchain","gas","overflow"],"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-23T08:17:48.524Z"}