Skip to content

refactor(cli): resolve contract addresses to Address in the Resolved* structs, not String #1140

Closed

Description

@thiras

Spun out of the multi-agent review on #1137 (type-design finding). Pre-existing; noting it while the resolver family is fresh.

Problem

The chain_ctx resolver structs carry contract addresses as unvalidated String, so every consumer must remember to parse them:

  • Resolved.capacity_bond_address: String (chain_ctx.rs:60) — re-parsed with parse_address at three sites: register.rs:41, bond.rs:29, setup.rs:185
  • ResolvedAppeal.slash_appeal_address: String (:163) — re-parsed at appeal.rs:31
  • ResolvedPublish.{publisher_registry,origin_assignment}_address: Option<String> (:257-258) — each unwrapped + parsed in registry_ctx / assignment_ctx (publish.rs:51, :77)

The invariant "a Resolved carries a usable address" is true in practice but not by construction. Nothing stops a new consumer from reading the String and skipping the parse.

The zero-address guard in resolve_appeal (chain_ctx.rs:188) is the sharpest symptom — it validates by string-munging:

anyhow::ensure!(
    slash_appeal_address.trim_start_matches("0x").bytes().any(|b| b != b'0'),
    "slash_appeal_address must not be the zero address — ..."
);

Correct, but it's a stringly-typed stand-in for addr != Address::ZERO, and it emits the misleading "must not be the zero address" for an empty string.

Suggested fix

Change the fields to alloy::primitives::Address / Option<Address> and parse inside resolve / resolve_appeal / resolve_publish. These already return anyhow::Result<_>, so no new failure mode is introduced, and the labelled error is preserved by reusing the existing parse_address.

Payoff:

  • Deletes the four duplicate parse sites for the required addresses.
  • Turns the zero-address check into ensure!(addr != Address::ZERO).
  • Makes "a Resolved holds a valid address" true by construction.

Keep the Option on ResolvedPublish — each publish subcommand legitimately needs only one of the two contracts, so requiring both would be wrong. The two ok_or_else messages in registry_ctx / assignment_ctx are correctly per-subcommand and should not be hoisted into the resolver; only the payload type changes (Option<String> → Option<Address>).

Out of scope for this issue

The other parse_address call sites (fetch.rs, channel.rs, bundle_pull.rs, and the --provider-address / operator-list parses) resolve from different structs or from raw user args, and are fine as-is.

Activity

  1. added
    area:cli
    prio:low
    on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:cliprio:low

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions