{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":1478,"sourceCode":"        let latest_block = self.http_rpc_client.latest_block().await?;\n        let base_fee_per_gas_wei = latest_block.base_fee_per_gas.ok_or_else(|| {\n            anyhow::anyhow!(\"Latest block {} has no base fee\", latest_block.number)\n        })?;\n        let priority_fee_per_gas_wei = self.http_rpc_client.max_priority_fee_per_gas().await?;\n        let (max_fee_per_gas, max_priority_fee_per_gas) = derive_fees(\n            base_fee_per_gas_wei,\n            priority_fee_per_gas_wei,\n            self.base_fee_buffer_bps,\n            u128::from(self.max_fee_per_gas_wei),\n        )?;\n        let gas_estimate = self\n            .http_rpc_client\n            .estimate_gas(&self.wallet_address, &to, value, &input)\n            .await?;\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 = self\n            .http_rpc_client\n            .get_balance_with_timeout(&self.wallet_address, None, Some(EXECUTION_RPC_TIMEOUT_SECS))\n            .await?;\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\n        let tx = build_eip1559_transaction(\n            expected_chain_id,\n            nonce,\n            gas_limit,","sourceCodeStart":1460,"sourceCodeEnd":1496,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/execution/client.rs#L1460-L1496","documentation":"gas_limit * max_fee_per_gas overflowed U256 while computing the worst-case gas cost before signing. Both inputs are bounded (gas limit derives from the node estimate plus a buffer capped by the configured gas_limit; max fee derives from the base fee plus buffer capped by max_fee_per_gas_wei), so an overflow implies wildly misconfigured caps rather than plausible chain values.","triggerScenarios":"prepare_and_sign with max_fee_per_gas_wei set near u128::MAX (wrong units, e.g. wei-vs-gwei confusion) combined with a high configured gas_limit, making the product exceed 2^256.","commonSituations":"Configuring gas prices in wei when the value was already in gwei (10^9 factor); pasting test/sentinel values like 2^127 into the config; generated configs with unbounded defaults.","solutions":["Sanity-check the fee config: max_fee_per_gas_wei should be a realistic gwei price scaled to wei (e.g. 100 gwei = 100 * 10**9)","Bound gas_limit to the block gas limit of the target chain (typically <= 30M)","Add startup validation rejecting configs whose max_fee_per_gas_wei * gas_limit could approach U256 bounds"],"exampleFix":"# before: gwei value written as if it were already scaled, near-overflowing product\nconfig.max_fee_per_gas_wei = 10**30\nconfig.gas_limit = 30_000_000\n\n# after: realistic caps (100 gwei ceiling, 1M gas)\nconfig.max_fee_per_gas_wei = 100 * 10**9\nconfig.gas_limit = 1_000_000\nassert config.max_fee_per_gas_wei * config.gas_limit < 2**128","handlingStrategy":"validation","validationCode":"# Startup config sanity: worst-case gas cost must stay far below U256\nassert config.max_fee_per_gas_wei <= 1_000 * 10**9, 'max fee above 1000 gwei is a units bug'\nassert config.gas_limit <= 30_000_000, 'gas limit above a typical block limit is a units bug'\nassert config.max_fee_per_gas_wei * config.gas_limit < 2**128, 'cost ceiling unrealistic'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Author gas caps in gwei and convert to wei in exactly one place","Reject configs where max_fee_per_gas_wei or gas_limit exceed plausible chain values at load time"],"tags":["blockchain","gas","arithmetic-overflow","config-validation","eip-1559"],"backgroundTag":"arithmetic-overflow","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}