Skip to content

Conversation

@lukehalasy-anchorage
Copy link
Contributor

@lukehalasy-anchorage lukehalasy-anchorage commented Jan 2, 2026

prasanna-anchorage and others added 2 commits December 31, 2025 19:35
* feat(ethereum): Add compile-time ABI embedding infrastructure

  - use LayeredRegistry for AbiRegistry
  - Update VisualizerContextParams and VisualizerContext to use
    LayeredRegistry<AbiRegistry> for wallet-first ABI lookups
  - Add Clone derive to LayeredRegistry in visualsign crate
  - Fix test in abi_decoder.rs (incorrect visualize args)
  - Fix tests in context.rs (missing abi_registry field)
  - Fix clippy warnings (op_ref, uninlined_format_args)

ABIs must be embedded at compile-time using include_str!() for security and
determinism. Supports per-chain address mapping and fallback visualization.

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(ethereum): Add example dapp using embedded ABI JSON

Add minimal example demonstrating compile-time ABI embedding pattern:
- SimpleToken.sol: Example smart contract with mint/burn functions
- SimpleToken.abi.json: Generated ABI for static embedding
- README.md: Complete guide for dapp developers on using embedded ABIs

Demonstrates best practices for compile-time embedding via include_str!()
macro and AbiRegistry configuration.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(ethereum): Add CLI support for custom ABI embedding

Implement phase 2-4 of ABI embedding feature:

Phase 2: Create embedded_abis.rs helper module
- register_embedded_abi() for compile-time embedded ABIs
- map_abi_address() for chain-specific address mapping
- parse_abi_address_mapping() for CLI argument parsing ("AbiName:0xAddress")
- Proper error handling with AbiEmbeddingError type
- 8 comprehensive tests including integration tests

Phase 3: Extend CLI with --abi flag support
- Add --abi argument to parser CLI (Vec<String> for multiple mappings)
- Implement validate_abi_mappings() helper for format validation
- Enhanced user feedback with mapping details and summaries
- Seamlessly integrated into existing parse_and_display pipeline

Phase 4: Fix infrastructure issues
- Update test cases with missing abi_registry field in context
- Add embedded_abis to module exports
- Enable visualsign-ethereum dependency in CLI Cargo.toml

Updated documentation:
- Enhanced README.md with CLI integration section
- Added multiple mapping examples
- Updated Rust code example with register_embedded_abi()
- Clarified compilation/embedding requirements

Testing:
- All 120 ethereum parser tests pass
- 8 new embedded_abis tests validate registration, mapping, and parsing
- CLI builds successfully with new ABI support

Pending: Phase 5 (gRPC metadata integration) requires converter interface
refactor to accept AbiRegistry through VisualizerContext.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* docs(ethereum): Add comprehensive ABI testing guide with cast examples

Create TESTING.md guide for ABI embedding with:

1. Prerequisites & Installation
   - Foundry/cast installation instructions
   - Version verification commands

2. Getting Real ABIs (3 methods)
   - Etherscan API (recommended) with curl examples
   - cast commands for available versions
   - Online ABI repositories (OpenZeppelin, etc.)
   - Real contract examples (USDC, WETH, Uniswap)

3. Local Testing Instructions
   - Step-by-step: fetch ABIs → create test binary → run example
   - Complete working Rust example with SimpleToken
   - Multi-ABI registry setup and verification

4. CLI Integration Examples
   - Generate calldata with `cast calldata`
   - Get function selectors with `cast sig`
   - Working test commands
   - SimpleToken reference example

5. Real Contract Examples
   - USDC, WETH, Uniswap V3 with addresses
   - How to inspect function signatures with jq
   - Selector matching examples

6. Troubleshooting
   - PATH issues with Foundry
   - Etherscan API key validation
   - ABI verification and inspection
   - Function selector mismatches
   - Address format handling

7. Testing Script
   - Complete bash script for fetching multiple ABIs
   - Error handling and verification
   - Quick test commands without API key

Tested locally:
- cast sig "transfer(address,uint256)" → 0xa9059cbb ✓
- cast calldata generates valid Ethereum calldata ✓
- All examples are executable and verified

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(ethereum): Add gRPC ABI metadata extraction and validation

  Introduces extract_abi_from_metadata for wallet-provided ABIs with optional secp256k1 signature validation support.

* feat: implement runtime ABI JSON loading and parameter decoding

  Wires up complete end-to-end support for loading custom ABI JSON files at runtime and decoding transaction parameters:

  Core changes:
  - Add `abi_registry` field to `VisualSignOptions` for passing registries through both CLI and gRPC pipelines
  - Implement parameter decoding in AbiDecoder for common Solidity types:
    * uint256 and other uint types (decoded as decimal)
    * address (decoded as checksummed hex)
    * address[] (dynamic arrays decoded with proper offset handling)
  - Update Ethereum converter to extract AbiRegistry from options and use DynamicAbiVisualizer for unknown contracts
  - Add `load_and_map_abi()` helper to combine file loading and address mapping

  CLI changes:
  - Rename `--abi` to `--abi-json-mappings` with format: `AbiName:/path/to/file.json:0xAddress`
  - Build AbiRegistry from file-based mappings and pass through options to visualizer

  Verified with SushiSwapRouter example - all parameters decode correctly matching Etherscan.

* Apply Patch #109 from @vaniiiii

* lint fixes

* eat(ethereum): implement secp256k1 signature validation for ABI metadata

  Add cryptographic signature verification for wallet-provided ABIs using
  the k256 crate. The validate_abi_signature function now:
  - Validates algorithm is "secp256k1"
  - Hashes ABI JSON with SHA-256
  - Verifies DER-encoded signatures against provided public key

  Changes:
  - Add k256 dependency with ecdsa feature
  - Add public_key field to SignatureMetadata struct
  - Implement actual signature verification (previously placeholder)
  - Add comprehensive tests for valid signatures, tampering detection,
    and error cases

Co-Authored-By: Claude <noreply@anthropic.com>

* Update src/parser/cli/src/cli.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>

* docs(ethereum): fix documentation issues in ABI JSON examples

  Address review comments from PR #120:
  - Fix WETH addresses to use EIP-55 checksummed format throughout
  - Correct --abi-json-mappings format to AbiName:FilePath:0xAddress
  - Remove non-existent example CLI references from "Using the Example"
  - Update cast commands to use `cast interface` instead of `cast abi`
  - Remove broken OpenZeppelin references from TESTING guide
  - Add clarifications about address format requirements
  - Add cast version compatibility notes
  - Change checkmark to plan emoji for planned features

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Update src/chain_parsers/visualsign-ethereum/examples/using_abijson/TESTING.md

Co-authored-by: Luke Halasy <107507807+lukehalasy-anchorage@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>

* feat(ethereum): implement proper chain_id extraction from ChainMetadata

  - Add extract_chain_id_from_metadata() function in networks.rs that
    extracts chain_id from ChainMetadata with fallback to ETHEREUM_MAINNET
  - Update Ethereum parser to use metadata as primary chain_id source
    instead of transaction.chain_id()
  - Fix CLI type error by extracting chain_id from metadata for ABI registry
  - Update CLI help text to clarify supported network formats (canonical
    names like POLYGON_MAINNET or numeric chain_ids like 137)
  - Add generated crate dependency to visualsign-ethereum
  - Update test expectations for legacy transactions to reflect new default
    behavior (Ethereum Mainnet instead of Unknown Network)

  Users can now specify networks using either canonical names
  (ETHEREUM_MAINNET, POLYGON_MAINNET) or numeric chain_ids (1, 137),
  and the system properly extracts chain_id from metadata for consistent
  network identification throughout the parser.

  Tested with multiple networks:
  - Numeric chain_ids: 1, 137, 8453, 11155111
  - Canonical names: ETHEREUM_MAINNET, ARBITRUM_MAINNET, BASE_MAINNET
  - Case-insensitive matching works correctly
  - Proper defaults with clear warnings when metadata is missing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Update src/chain_parsers/visualsign-ethereum/examples/using_abijson/TESTING.md

Co-authored-by: Luke Halasy <107507807+lukehalasy-anchorage@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>

* Update src/chain_parsers/visualsign-ethereum/examples/using_abijson/TESTING.md

Co-authored-by: Luke Halasy <107507807+lukehalasy-anchorage@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>

* Update src/chain_parsers/visualsign-ethereum/examples/using_abijson/TESTING.md

Co-authored-by: Luke Halasy <107507807+lukehalasy-anchorage@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>

* Address Comments and incorporate changes

  Replace manual calldata construction with alloy's sol! macro in the
  using_abijson example. This change improves code maintainability and
  type safety by:

  - Using sol! interface definitions for IERC20::transfer
  - Replacing vec![0xa9, 0x05, 0x9c, 0xbb] with IERC20::transferCall::abi_encode()
  - Removing manual byte padding and slicing operations
  - Adding comprehensive documentation explaining typesafe vs manual encoding

  The typesafe approach provides compile-time verification of function
  signatures and automatic ABI encoding, matching the pattern used
  throughout the visualsign-ethereum codebase.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* refactor(ethereum): replace manual ABI decoding with alloy-dyn-abi

  Replace manual byte parsing in abi_decoder.rs with alloy's native
  DynSolType and DynSolValue for runtime ABI decoding.

  Changes:
  - Add alloy-dyn-abi 1.4.1 dependency
  - Delete decode_solidity_value() function (~80 lines of manual parsing)
  - Add format_dyn_sol_value() helper for recursive type formatting
  - Refactor visualize() to use DynSolType::parse() and tuple decoding
  - Update documentation to mention alloy-dyn-abi usage
  - Add test for transfer function with alloy-encoded data

  Benefits:
  - Support for ALL Solidity types (arrays, tuples, structs, etc.)
  - No manual offset tracking (alloy handles ABI layout)
  - More maintainable code (net reduction of ~55 lines)
  - Leverages proven alloy implementation

  All tests passing (159/159). Interface unchanged - all consumers
  (DynamicAbiVisualizer, lib.rs, examples) work automatically.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* docs(ethereum): fix bash syntax errors in TESTING.md examples

  Address remaining review comments from PR #120:
  - Fix malformed cast calldata command (line 224) to properly assign
    output to CALLDATA variable
  - Fix curl command syntax error in fetch_abis.sh example (line 401)
    by replacing malformed `-d '` with `-d "chainId=1"`

  These fixes ensure users can successfully copy-paste the example
  commands without encountering bash syntax errors.

* lint fix

* fix(ethereum): correct chain_id handling for CLI vs gRPC paths

  Address remaining issues from PR #120 and fix chain_id behavior:

  Documentation fixes (TESTING.md):
  - Fix malformed cast calldata command to properly assign to $CALLDATA variable
  - Fix curl syntax error in fetch_abis.sh example (replace `-d '` with `-d "chainId=1"`)

  Chain ID behavior refactor:
  - Change extract_chain_id_from_metadata() to return Option<u64> instead of u64
    to remove inappropriate defaulting in gRPC path
  - Update convert_to_visual_sign_payload() to return Result and error when
    chain_id cannot be determined from either metadata or transaction
  - CLI now defaults to ETHEREUM_MAINNET (chain_id: 1) when --network not specified
  - gRPC path uses transaction's chain_id when no metadata provided (no defaulting)

  This ensures proper separation of concerns:
  - CLI provides user-friendly defaults for better UX
  - gRPC path strictly uses provided data, returning actual chain_id from transaction

  Integration tests now correctly expect "Unknown Network (Chain ID: 37)" for
  legacy transactions without metadata, rather than defaulting to Ethereum Mainnet.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(ethereum): default to mainnet for legacy transactions without chain_id

  Legacy transactions (pre-EIP-155) don't always contain a chain_id field.
  When no metadata is provided, these transactions now default to Ethereum
  Mainnet (chain_id 1) instead of failing with a decode error.

  This fix is scoped specifically to TypedTransaction::Legacy. Other
  transaction types (EIP-1559, etc.) still require an explicit chain_id
  from either metadata or the transaction itself.

  Fixes the 'legacy' fixture test case.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Luke Halasy <107507807+lukehalasy-anchorage@users.noreply.github.com>
@lukehalasy-anchorage lukehalasy-anchorage changed the base branch from feat/solana-idl-parser to main January 2, 2026 18:37
@lukehalasy-anchorage lukehalasy-anchorage changed the base branch from main to feat/solana-idl-parser January 2, 2026 18:37
@lukehalasy-anchorage lukehalasy-anchorage changed the title merge "main" ( a86e7979fb8864194f1149b577966a8c7d023198 ) branch into the Solana idl parser merge "main" ( a86e7979fb8864194f1149b577966a8c7d023198 ) branch into the feat/solana-idl-parser branch to make reviewing easier Jan 2, 2026
@lukehalasy-anchorage lukehalasy-anchorage marked this pull request as ready for review January 2, 2026 18:41
@lukehalasy-anchorage lukehalasy-anchorage changed the title merge "main" ( a86e7979fb8864194f1149b577966a8c7d023198 ) branch into the feat/solana-idl-parser branch to make reviewing easier merge "main" ( a86e7979fb8864194f1149b577966a8c7d023198 ) branch into the feat/solana-idl-parser branch to make reviewing / eventual merge easier Jan 2, 2026
@lukehalasy-anchorage
Copy link
Contributor Author

closing in favor of rebase as mentioned here: #128

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