Skip to content

[executor] fetch_params ceiling comparison: max_fee (wei) vs max_gas_gwei (u64 gwei) unit mismatch #179

@obchain

Description

@obchain

Summary

GasOracle::fetch_params computes max_fee in wei (U256) then compares it against BotConfig.max_gas_gwei which is a u64 in gwei units. The field is named max_gas_gwei and holds a value of 10 in config/default.toml, meaning the ceiling is 10 gwei = 10,000,000,000 wei.

If the comparison is max_fee > config.bot.max_gas_gwei without unit normalisation, the comparison is between a wei-scale U256 (~3,000,000,000 wei at 3 gwei baseFee x 1.25) and a raw gwei integer (10). The result is either always-true (block all txs) or always-false (never enforce ceiling) depending on type coercion.

File

crates/charon-executor/src/gas.rsfetch_params()

Risk

The gas-ceiling gate is an off-chain safety constraint listed in CLAUDE.md. A broken ceiling check either (a) blocks every liquidation opportunity (zero revenue) or (b) never enforces the ceiling, allowing unprofitable high-gas txs to broadcast.

Fix

Convert the ceiling to wei before comparison:

let max_gas_wei = U256::from(config.bot.max_gas_gwei) * U256::from(1_000_000_000u64);
if max_fee_per_gas > max_gas_wei {
    return Ok(None);
}

Alternatively rename the config field to max_gas_wei: U256 and update config/default.toml and config.rs consistently. Either path must be reflected atomically in all three files.

Refs #43

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p0-blockerBlocks the critical pathstatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions