Skip to content

feat(foreign-tx): avalanche and adi support - #4145

Open
frolvanya wants to merge 1 commit into
mainfrom
feat/avax-adi-foreign-tx
Open

feat(foreign-tx): avalanche and adi support#4145
frolvanya wants to merge 1 commit into
mainfrom
feat/avax-adi-foreign-tx

Conversation

@frolvanya

Copy link
Copy Markdown
Collaborator

Adds Avalanche C-Chain and ADI Chain to foreign transaction verification.
Both are fully EVM-compatible, so this is one PR of mechanical wiring — no new
inspector logic, both chains reuse the generic EvmInspector the same way
Polygon and HyperEVM do.

The chains

  • Avalanche C-Chain — geth fork, chain id 43114 (Fuji 43113). Instant
    finality: latest/safe/finalized all mean the last accepted block.
    Note: mainnet and Fuji share a genesis hash, so the eth_chainId
    fingerprint probe is the right network check for it.
  • ADI Chain — ZKsync OS L2 (same family as Abstract), chain id 36900
    (testnet 99999). safe/finalized answer correctly and lag latest.
    Young chain (mainnet Dec 2025) with a smaller provider set (foundation RPC,
    Alchemy, dRPC), but enough for a multi-provider quorum.

Changes

Standard new-EVM-chain wiring across the stack: enum variants in the contract
interface, inspector marker modules, node config slots, fingerprint probe +
golden vectors in the health check, node dispatch, SDK builders, and the
matching test rows, e2e coverage, and docs tables.

Testing

  • clippy / fmt / all touched crates' tests pass.
  • The new #[ignore]d manual tests were run against the live mainnet RPCs
    and pass: block-hash + log extraction on pinned real transactions, and
    eth_chainId fingerprints 43114 / 36900.

Heads-up: trivially conflicts with the open SVM PRs (both append variants
after Sui); whichever lands second rebases and keeps its variants last.

Copilot AI lite review requested due to automatic review settings August 14, 2026 09:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Avalanche C-Chain and ADI Chain as supported foreign EVM chains across the inspector, node wiring, health-checks, contract interface/ABI, SDK builders, docs, and test coverage.

Changes:

  • Extend the contract interface (ForeignChain / ForeignChainRpcRequest) and ABI/schema snapshots with Avalanche and Adi.
  • Wire Avalanche/ADI through node config + inspector fanout + verify-foreign-tx dispatch, plus health-check probing and golden vectors.
  • Add SDK builders and e2e/sandbox/manual tests + docs updates for eth_chainId fingerprints.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs/foreign-chain-transactions.md Documents new chains’ fingerprint probes and expected network fingerprints.
crates/node/src/web.rs Exposes provider counts for Avalanche/ADI in node web output + updates related tests.
crates/node/src/tests/foreign_chain_configuration.rs Ensures Avalanche/ADI config slots are present in startup auto-registration test setup.
crates/node/src/providers/verify_foreign_tx/sign.rs Adds request dispatch arms to execute Avalanche/ADI inspections.
crates/node/src/providers/verify_foreign_tx.rs Adds Avalanche/ADI inspector fanout construction from config.
crates/node-config/src/foreign_chains.rs Adds Avalanche/ADI optional config sections and includes them in configured-chain iteration.
crates/near-mpc-sdk/tests/avalanche.rs Adds SDK integration test for building Avalanche requests.
crates/near-mpc-sdk/tests/adi.rs Adds SDK integration test for building ADI requests.
crates/near-mpc-sdk/src/foreign_chain/avalanche.rs Adds Avalanche SDK builder module and wraps EVM requests into Avalanche variant.
crates/near-mpc-sdk/src/foreign_chain/adi.rs Adds ADI SDK builder module and wraps EVM requests into Adi variant.
crates/near-mpc-sdk/src/foreign_chain.rs Exposes new SDK modules (avalanche, adi).
crates/near-mpc-contract-interface/src/types/foreign_chain.rs Adds Avalanche/Adi enum variants + mapping tests.
crates/foreign-chain-inspector/tests/evm_inspector.rs Runs the shared EVM inspector test suite for Avalanche/ADI marker types.
crates/foreign-chain-inspector/tests/avalanche_rpc_manual.rs Adds ignored manual RPC sanity tests for Avalanche.
crates/foreign-chain-inspector/tests/adi_rpc_manual.rs Adds ignored manual RPC sanity tests for ADI.
crates/foreign-chain-inspector/src/lib.rs Exposes new inspector modules (avalanche, adi).
crates/foreign-chain-inspector/src/avalanche/inspector.rs Adds Avalanche EVM marker type + type aliases to generic EvmInspector.
crates/foreign-chain-inspector/src/avalanche.rs Adds Avalanche hashes and module wiring.
crates/foreign-chain-inspector/src/adi/inspector.rs Adds ADI EVM marker type + type aliases to generic EvmInspector.
crates/foreign-chain-inspector/src/adi.rs Adds ADI hashes and module wiring.
crates/foreign-chain-health-check/src/probe.rs Adds Avalanche/ADI probe dispatch and updates EVM chain-id coverage tests.
crates/foreign-chain-health-check/src/lib.rs Adds Avalanche/ADI health-check execution in the provider checker.
crates/foreign-chain-health-check/src/golden.rs Adds Avalanche/ADI mainnet golden vectors for block-hash checks.
crates/e2e-tests/tests/foreign_chain_tx_validation.rs Extends e2e foreign-tx signing coverage to include Avalanche/ADI.
crates/contract/tests/snapshots/abi__abi_has_not_changed.snap Updates ABI snapshot for new enum variants and request schema unions.
crates/contract/tests/sandbox/foreign_chain_request.rs Adds sandbox test cases for verifying Avalanche/ADI requests.
crates/contract/tests/sandbox/common.rs Adds helper constructors for Avalanche/ADI EVM requests in sandbox tests.
crates/contract/src/snapshots/mpc_contract__foreign_chains_metadata__tests__foreign_chains_metadata_borsh_schema__should_not_change.snap Updates Borsh schema snapshot for new foreign-chain variants.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/near-mpc-sdk/tests/avalanche.rs
Comment thread docs/foreign-chain-transactions.md
Comment thread crates/near-mpc-sdk/tests/adi.rs
Comment thread crates/near-mpc-sdk/src/foreign_chain/avalanche.rs
Comment thread crates/near-mpc-sdk/src/foreign_chain/adi.rs
@claude

claude Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request overview

Adds Avalanche C-Chain and ADI Chain as foreign-transaction verification targets. Both are EVM-compatible, so neither introduces new inspector logic — each gets a marker type implementing EvmChain and reuses the generic EvmInspector, exactly as Polygon and HyperEVM do. The change is mechanical wiring across the full stack: contract-interface enum variants, node config slots, node dispatch, health-check golden vectors and fingerprint probe, SDK builders, plus tests and docs.

Changes:

  • ForeignChain / ForeignChainRpcRequest gain Avalanche and Adi variants (borsh discriminants 13/14, appended — existing discriminants unchanged); ABI and borsh-schema snapshots regenerated.
  • New inspector marker modules with per-chain define_hash! newtypes and the usual *Inspector / *ExtractedValue / *Extractor aliases.
  • ForeignChainsConfig gains avalanche / adi slots; node builds FanOut inspectors and dispatches both in execute_foreign_chain_request.
  • Health check: mainnet golden block-hash vectors (testnet None), check_all_providers wiring, and eth_chainId probe dispatch (43114 / 36900).
  • SDK new_avalanche() / new_adi() builders; contract sandbox, e2e, evm_inspector macro, and #[ignore]d live-RPC tests; docs fingerprint tables.

Reviewed changes

Per-file summary
File Description
crates/near-mpc-contract-interface/src/types/foreign_chain.rs Avalanche / Adi appended to ForeignChain and ForeignChainRpcRequest, chain() arms, rstest cases
crates/contract/tests/snapshots/abi__abi_has_not_changed.snap Regenerated ABI (JSON schema + borsh variants 13/14)
crates/contract/src/snapshots/...foreign_chains_metadata_borsh_schema...snap Regenerated borsh schema container
crates/contract/tests/sandbox/common.rs avalanche_evm_request() / adi_evm_request() fixtures
crates/contract/tests/sandbox/foreign_chain_request.rs New rstest cases across success / no-policy / timeout scenarios
crates/foreign-chain-inspector/src/{avalanche,adi}.rs + .../inspector.rs Hash newtypes, EvmChain marker impls, type aliases (identical in shape to polygon)
crates/foreign-chain-inspector/src/lib.rs Module declarations
crates/foreign-chain-inspector/tests/{avalanche,adi}_rpc_manual.rs #[ignore]d live-RPC block-hash + fingerprint checks
crates/foreign-chain-inspector/tests/evm_inspector.rs evm_inspector_tests! instantiations
crates/foreign-chain-health-check/src/golden.rs Mainnet BlockHashVectors; testnet None; parse test updated
crates/foreign-chain-health-check/src/lib.rs run_evm / mark_not_configured branches, chain-name test list
crates/foreign-chain-health-check/src/probe.rs probe_evm::<Avalanche> / ::<Adi> dispatch, EVM_MAINNETS, must_put_chain slots
crates/node-config/src/foreign_chains.rs Config slots + all_configured_chains() DTO mapping
crates/node/src/providers/verify_foreign_tx.rs ForeignChainInspectors fields + build_fanout calls
crates/node/src/providers/verify_foreign_tx/sign.rs Two new dispatch arms
crates/node/src/web.rs Provider-count fields + secret-leak test coverage
crates/node/src/tests/foreign_chain_configuration.rs Exhaustive struct literal updated
crates/e2e-tests/tests/foreign_chain_tx_validation.rs Two mock servers, config/whitelist entries, verify_avalanche / verify_adi
crates/near-mpc-sdk/src/foreign_chain{,/avalanche.rs,/adi.rs} + tests/ Builder entry points and tests
docs/foreign-chain-transactions.md Probe table + expected-fingerprint rows

Findings

I traced every site that mentions an existing EVM chain (hyper_evm as the reference) and each one is covered here — config slots, the DTO mapping, both health-check routes including must_put_chain, node dispatch, web.rs counts, and both snapshots. foreign_chain_whitelist_verifier.rs and probe_all_providers drive off iter_chains() / explicit match arms, so nothing silently falls through to a wildcard. Enum variants are appended, so on-chain state keyed by ForeignChain (foreign_chain_rpc_whitelist) still decodes, and an old node that indexes a receipt naming an unknown chain logs a warning and skips rather than panicking (crates/node/src/indexer/handler.rs:400). No blocking issues.

Non-blocking (nits, follow-ups, suggestions):

  • docs/foreign-chain-transactions.md:697`"99999"` (AB testnet) — every other row names the network it belongs to (Fuji, Amoy, Sepolia); "AB testnet" doesn't obviously correspond to ADI and reads like a leftover. Per the PR description only the mainnet fingerprints were exercised against live RPCs, so 99999 is the one value in these two rows that nothing verified. Worth confirming and relabelling before operators copy it into expected_network_fingerprint, since a wrong value makes the probe report WrongNetwork for correctly-configured providers.
  • crates/node/src/providers/verify_foreign_tx/sign.rs:296 and :318execute_foreign_chain_request is now ~310 lines, and the seven EVM arms (Abstract, Bnb, Base, Arbitrum, HyperEvm, Polygon, and now Avalanche/Adi) are byte-identical apart from the self.inspectors.<field> pick and the chain name in the context string. Adding a chain shouldn't cost 22 lines of copy-paste. A small helper taking the FanOut<EvmInspector<_, Chain>> and a &'static str label would collapse ~150 lines and make the next chain a two-line change:
    async fn extract_evm<Chain: EvmChain>(
        inspector: Option<&FanOut<EvmInspector<HttpClient, Chain>>>,
        chain: &'static str,
        request: &dtos::EvmRpcRequest,
    ) -> anyhow::Result<Vec<dtos::ExtractedValue>>
    Pre-existing, so fine as a follow-up — but this PR is the second consecutive one to widen it.
  • Test naming — six new tests don't follow the <system_under_test>__should_<assertion> form that CLAUDE.md requires for new tests: crates/near-mpc-sdk/src/foreign_chain/avalanche.rs:51, .../adi.rs:51, crates/near-mpc-sdk/tests/avalanche.rs:8, crates/near-mpc-sdk/tests/adi.rs:8, crates/foreign-chain-inspector/tests/avalanche_rpc_manual.rs:14 and :63, crates/foreign-chain-inspector/tests/adi_rpc_manual.rs:14 and :67. They're verbatim copies of the hyper_evm / polygon siblings, so the drift is inherited rather than introduced — but the convention applies to new tests, and copying is how it stays broken.
  • crates/near-mpc-contract-interface/src/types/foreign_chain.rs:1283Avalanche denotes the C-Chain specifically (Avalanche also has X- and P-Chains, neither EVM). The variant name is baked into the contract ABI and borsh schema permanently; AvalancheCChain would cost nothing now and can't be changed later. Judgment call — the EvmRpcRequest payload arguably makes it unambiguous.
  • Deployment ordering: a node that ships avalanche: / adi: in its foreign_chains.yaml before the contract carrying variants 13/14 is deployed will have its register_available_foreign_chain_config call rejected wholesale (unknown variant), losing registration for the chains it does cover — the failure is a tracing::warn! in register_foreign_chains (crates/node/src/coordinator.rs:1058), so it's silent to the operator. Same for every prior chain addition, so presumably understood, but worth a line in the release notes.

✅ Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants