{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":2290,"sourceCode":"        plan.instrument_id,\n        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 == OrderSide::Sell,\n        \"Finalized Swap side {} does not match Sell order\",\n        trade.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(());\n    }\n\n    emitter.emit_order_filled(\n        &plan.order,\n        VenueOrderId::new_checked(included.tx_hash.to_string())?,\n        None,","sourceCodeStart":2272,"sourceCodeEnd":2308,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/execution/client.rs#L2272-L2308","documentation":"Gas commission arithmetic guard in emit_finalized_swap_fill: effective_gas_price * gas_used (both U256 from the receipt) is computed with checked_mul and this error fires on overflow. Well-formed receipts can never overflow U256, so in practice this signals malformed or hostile RPC data.","triggerScenarios":"A receipt whose effective_gas_price or gas_used is an absurd value (near U256::MAX) returned by a broken proxy, a malicious endpoint, or a deserialization bug mapping the wrong JSON field.","commonSituations":"Custom RPC middleware or test stubs fabricating receipts without realistic bounds; endpoints that return null-ish defaults coerced to huge integers.","solutions":["Fetch the receipt directly and inspect gasUsed and effectiveGasPrice: gasUsed should be within the block gas limit and the price near current network fees.","Use a trusted, canonical RPC endpoint for execution.","If a stub produced the receipt, generate realistic bounded values.","Report persistently malformed receipts to the provider."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn receipt_gas_is_plausible(gas_used: u128, price: U256) -> bool {\n    gas_used < 50_000_000 && price < U256::from(10u128).pow(U256::from(15)) // 1e15 wei ~= absurd ceiling\n}","typeGuard":"fn receipt_gas_fields_plausible(receipt: &RpcTransactionReceipt) -> bool {\n    receipt_gas_is_plausible(receipt.gas_used, receipt.effective_gas_price)\n}","tryCatchPattern":"Catch the overflow, dump the raw receipt JSON for diagnosis, and quarantine the endpoint that produced it; a compliant node cannot trigger this path.","preventionTips":["Bound-check gas_used and effective_gas_price before arithmetic.","Use trusted RPC endpoints and validate receipt shape in tests."],"tags":["blockchain","gas","arithmetic-overflow","rpc"],"backgroundTag":"arithmetic-overflow","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}