Skip to content

Add RPC chainId validation #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

pcarranzav
Copy link
Member

No description provided.

@pcarranzav pcarranzav marked this pull request as ready for review August 3, 2025 22:50
pcarranzav and others added 2 commits August 3, 2025 22:54
Implements automatic validation of RPC endpoints to ensure they match
the expected chain IDs from CAIP-2 identifiers. This prevents
misconfiguration errors where an RPC URL points to the wrong chain.

Features:
- Validates protocol chain and all indexed chains on startup
- Calls eth_chainId on each EVM RPC endpoint
- Compares returned chain ID with expected value from CAIP-2
- Fails fast with clear error message on mismatch
- Skips validation for non-EVM chains (non-eip155 namespace)

Example output on success:
✓ Chain ID validated for eip155:42161: RPC https://arbitrum.example.com correctly returns chain ID 42161

Example output on failure:
ERROR Chain ID mismatch for eip155:42161: RPC https://ethereum.example.com returned chain ID 1 (0x1), expected 42161

This addresses the safety requirement from TODO.md section 7.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Added 6 unit tests that verify chain validation logic without
requiring real RPC endpoints:

- test_validate_chain_id_success: Verifies matching chain IDs pass
- test_validate_chain_id_mismatch: Verifies mismatched IDs fail with clear error
- test_validate_chain_id_hex_variations: Tests different hex formats (0x1, 0x01, 0xa4b1)
- test_validate_chain_id_skips_non_evm: Ensures non-EVM chains are skipped
- test_validate_chain_id_invalid_hex: Tests graceful handling of malformed responses
- test_caip2_parsing: Verifies CAIP-2 parsing for both EVM and non-EVM chains

Implemented a MockTransport that simulates RPC responses, allowing
thorough testing of all validation paths without network dependencies.

All 20 oracle tests pass.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@pcarranzav pcarranzav force-pushed the pcv/feat-rpc-chain-validation branch from d14143f to 7d3640a Compare August 4, 2025 01:54
Base automatically changed from pcv/feat-correct-epoch to main August 4, 2025 12:50
@pcarranzav pcarranzav closed this Aug 4, 2025
@pcarranzav pcarranzav reopened this Aug 4, 2025
Copy link
Member

@Maikol Maikol left a comment

Choose a reason for hiding this comment

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

🙌

Maikol

This comment was marked as duplicate.

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