nautechsystems/nautilus_trader · error

Maximum gas cost overflow

Error message

Maximum gas cost overflow

What it means

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.

Solutions

  1. Lower the configured `gas_limit` and `gas_buffer_bps` to realistic values for the transaction type.
  2. Cap `max_fee_per_gas_wei` configuration to a sane ceiling (gwei-scale, not wei-scale mistakes).
  3. Sanity-check the priority fee source; a bad fee oracle returning huge values inflates max_fee_per_gas.
  4. Verify units: gas price must be in wei per gas, not gwei or whole ether.

Example fix

// before
gas_limit: 10_000_000_000_000, // absurd config value
// after
gas_limit: 1_000_000, // realistic ceiling for the tx type
Defensive patterns

Strategy: validation

Validate before calling

pub fn gas_cost_fits(gas_limit: u64, max_fee_per_gas: u128) -> bool {
    U256::from(gas_limit).checked_mul(U256::from(max_fee_per_gas)).is_some()
}

Try / catch

if let Err(e) = client.prepare_and_sign(...).await {
    if e.to_string().contains("Maximum gas cost overflow") { alert_config_out_of_range(); }
    return Err(e.into());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/a6184764bb3b1ce4. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/blockchain/src/execution/client.rs:2374

            u128::from(self.max_fee_per_gas_wei),
        )?;
        let gas_estimate_verification = required_verification(
            self.verification
                .verify_gas_estimate(
                    &self.wallet_address,
                    &to,
                    value,
                    &input,
                    decision_header.number,
                )
                .await,
            "pre-sign gas estimate",
        )?;
        let gas_estimate = gas_estimate_verification.value;
        let gas_limit = derive_gas_limit(gas_estimate, self.gas_buffer_bps, self.gas_limit)?;
        let max_gas_cost = U256::from(gas_limit)
            .checked_mul(U256::from(max_fee_per_gas))
            .ok_or_else(|| anyhow::anyhow!("Maximum gas cost overflow"))?;
        let max_transaction_cost = value
            .checked_add(max_gas_cost)
            .ok_or_else(|| anyhow::anyhow!("Maximum transaction cost overflow"))?;
        let native_balance_verification = required_verification(
            self.verification
                .verify_balance(&self.wallet_address, decision_header.number)
                .await,
            "pre-sign native balance",
        )?;
        let native_balance = native_balance_verification.value;

        if native_balance < max_transaction_cost {
            anyhow::bail!(
                "Native currency balance {native_balance} wei is below maximum transaction cost {max_transaction_cost} wei"
            );
        }
        let decision_height = Some(decision_header.number);
        let mut decisions = vec![

View on GitHub (pinned to 18893faf8b)