{"record":{"id":"681ddaf107184035","repo":"nautechsystems/nautilus_trader","slug":"maximum-transaction-cost-overflow","errorCode":null,"errorMessage":"Maximum transaction cost overflow","messagePattern":"Maximum transaction cost overflow","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":1481,"sourceCode":"        })?;\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,\n            max_fee_per_gas,\n            max_priority_fee_per_gas,\n            to,","sourceCodeStart":1463,"sourceCodeEnd":1499,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/execution/client.rs#L1463-L1499","documentation":"value + max_gas_cost overflowed U256 while computing the worst-case transaction cost used for the balance check. value is the native ETH attached to the transaction and max_gas_cost is the (already computed) worst-case fee; only values approaching 2^256 can overflow, which for real chains means a misconfigured or nonsensical input amount.","triggerScenarios":"prepare_and_sign where the swap/wrap value passed in is astronomically large (unit error, e.g. raw amount computed against the wrong decimals or a Decimal cast that lost its scale) on top of an already-huge max gas cost.","commonSituations":"Quantity converted with the quote token's 18 decimals instead of the base token's; test fixtures using U256 near-max values; amounts derived from unbounded user input without clamping.","solutions":["Recheck amount units: convert order quantity with the correct token decimals, and keep it under transaction_limits.max_order_amount","Clamp value and fee caps to realistic on-chain magnitudes at config load time","If this fires in tests, replace sentinel near-max values with plausible raw amounts"],"exampleFix":"# before: decimals mix-up produces an astronomically large value\nvalue = int(order_qty * 10**18)  # token has 6 decimals -> 10^12x too big\n\n# after: scale by the token's actual decimals and clamp\nvalue = int(order_qty * 10**base_token.decimals)\nassert value <= config.max_order_amount","handlingStrategy":"validation","validationCode":"# Reject U256-scale native amounts before submission\nvalue_raw = int(order_qty * 10**base_token.decimals)\nassert 0 < value_raw <= config.max_order_amount, 'value exceeds max_order_amount (units bug?)'\nassert value_raw + (config.gas_limit * config.max_fee_per_gas_wei) < 2**128, 'cost ceiling unrealistic'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert quantities with the token's actual decimals from the instrument definition, never a hardcoded 10**18","Keep max_order_amount as the hard ceiling on raw amounts in strategy code"],"tags":["blockchain","arithmetic-overflow","token-decimals","config-validation"],"backgroundTag":"arithmetic-overflow","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}