Skip to content

[PR #29] Config::load performs no cross-reference or sentinel validation #77

@obchain

Description

@obchain

PR: #29 (feat/04-toml-config-loader)
File: crates/charon-core/src/config.rs, lines 79-91

Config::load parses TOML and returns. No semantic validation. Concrete gaps:

  1. ProtocolConfig.chain = "bnb" — no check that "bnb" exists as key in Config.chain map. Typo → runtime unwrap() panic in scanner boot.
  2. LiquidatorConfig.contract_address — placeholder 0x0000000000000000000000000000000000000000 in committed default.toml is accepted silently. Bot will encode calldata targeting the zero address.
  3. FlashLoanConfig.chain / LiquidatorConfig.chain — same dangling-reference issue.
  4. Empty chain, protocol, flashloan, liquidator maps pass validation; bot boots with nothing to do.

Impact: Misconfigured deploy reaches tx-build stage before failing. Potential fund loss if zero-address accepted and gas burns on revert.

Fix: Add Config::validate(&self) -> Result<()> invoked inside load():

for (name, p) in &self.protocol {
    if !self.chain.contains_key(&p.chain) {
        bail!("protocol `{name}` references unknown chain `{}`", p.chain);
    }
}
for (name, l) in &self.liquidator {
    if l.contract_address == Address::ZERO {
        bail!("liquidator `{name}` has zero address — deploy contract first");
    }
    if !self.chain.contains_key(&l.chain) { ... }
}

Same for flashloan. Empty-map check optional but recommended for boot-time sanity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scope

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions