{"record":{"id":"a6184764bb3b1ce4","repo":"nautechsystems/nautilus_trader","slug":"maximum-gas-cost-overflow","errorCode":null,"errorMessage":"Maximum gas cost overflow","messagePattern":"Maximum gas cost overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":2374,"sourceCode":"            u128::from(self.max_fee_per_gas_wei),\n        )?;\n        let gas_estimate_verification = required_verification(\n            self.verification\n                .verify_gas_estimate(\n                    &self.wallet_address,\n                    &to,\n                    value,\n                    &input,\n                    decision_header.number,\n                )\n                .await,\n            \"pre-sign gas estimate\",\n        )?;\n        let gas_estimate = gas_estimate_verification.value;\n        let gas_limit = derive_gas_limit(gas_estimate, self.gas_buffer_bps, self.gas_limit)?;\n        let max_gas_cost = U256::from(gas_limit)\n            .checked_mul(U256::from(max_fee_per_gas))\n            .ok_or_else(|| anyhow::anyhow!(\"Maximum gas cost overflow\"))?;\n        let max_transaction_cost = value\n            .checked_add(max_gas_cost)\n            .ok_or_else(|| anyhow::anyhow!(\"Maximum transaction cost overflow\"))?;\n        let native_balance_verification = required_verification(\n            self.verification\n                .verify_balance(&self.wallet_address, decision_header.number)\n                .await,\n            \"pre-sign native balance\",\n        )?;\n        let native_balance = native_balance_verification.value;\n\n        if native_balance < max_transaction_cost {\n            anyhow::bail!(\n                \"Native currency balance {native_balance} wei is below maximum transaction cost {max_transaction_cost} wei\"\n            );\n        }\n        let decision_height = Some(decision_header.number);\n        let mut decisions = vec![","sourceCodeStart":2356,"sourceCodeEnd":2392,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L2356-L2392","documentation":"During pre-sign cost accounting the client computes max gas cost as `gas_limit * max_fee_per_gas` using checked U256 arithmetic. If that product exceeds U256, the multiplication returns None and the client fails fast rather than computing a bogus maximum cost for the balance check.","triggerScenarios":"Calling the sign path with an extremely large `gas_limit` (huge configured gas_limit or gas_buffer_bps inflating the estimate) combined with an enormous `max_fee_per_gas` derived from extreme base/priority fee values, such that the product overflows U256.","commonSituations":"Operator sets an absurdly high `gas_limit` or `max_fee_per_gas_wei` config; a misbehaving fee feed returns astronomic priority fees; spikes in base fee on a congested chain combined with generous buffers.","solutions":["Lower the configured `gas_limit` and `gas_buffer_bps` to realistic values for the transaction type.","Cap `max_fee_per_gas_wei` configuration to a sane ceiling (gwei-scale, not wei-scale mistakes).","Sanity-check the priority fee source; a bad fee oracle returning huge values inflates max_fee_per_gas.","Verify units: gas price must be in wei per gas, not gwei or whole ether."],"exampleFix":"// before\ngas_limit: 10_000_000_000_000, // absurd config value\n// after\ngas_limit: 1_000_000, // realistic ceiling for the tx type","handlingStrategy":"validation","validationCode":"pub fn gas_cost_fits(gas_limit: u64, max_fee_per_gas: u128) -> bool {\n    U256::from(gas_limit).checked_mul(U256::from(max_fee_per_gas)).is_some()\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.prepare_and_sign(...).await {\n    if e.to_string().contains(\"Maximum gas cost overflow\") { alert_config_out_of_range(); }\n    return Err(e.into());\n}","preventionTips":["Bound gas_limit and gas_buffer_bps in config validation at startup.","Cap max_fee_per_gas_wei to a realistic ceiling.","Sanity-check fee oracle outputs before use."],"tags":["blockchain","arithmetic-overflow","gas","u256"],"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"}