-
Notifications
You must be signed in to change notification settings - Fork 11
Decode Morpho Multicall in type safe way with sol! macros #119
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
Draft
prasanna-anchorage
wants to merge
29
commits into
feat/ethereum-ethglobal-e2e
Choose a base branch
from
feat/morpho-multicall
base: feat/ethereum-ethglobal-e2e
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Decode Morpho Multicall in type safe way with sol! macros #119
prasanna-anchorage
wants to merge
29
commits into
feat/ethereum-ethglobal-e2e
from
feat/morpho-multicall
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated the security policy to include guidelines for reporting vulnerabilities and our response policy. Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Enhance security policy with reporting guidelines
Clarified PR approval requirements for Core Team Members and Community/Public contributors, specifying the need for Anchorage employee involvement. Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com>
Governance and Contribution docs
* chore: Add @guido-peirano-anchor to CLA signers list Approved by: @prasanna-anchorage Related PR: #113 add diego-rivas-anchor to .cla-signed-users too * add the bot too --------- Co-authored-by: Prasanna Gautam <prasanna@anchorlabs.com>
* feat: Add VisualizerContext for Ethereum transaction visualization Add VisualizerContext struct with nested call support and token formatting. Includes Clone implementation, for_nested_call() method, and unit tests. Roadmap: Milestone 1-1, core datastructure * refactor: Implement Builder pattern for EthereumVisualizerRegistry - Rename VisualizerRegistry to EthereumVisualizerRegistry to avoid naming conflicts - Split into immutable EthereumVisualizerRegistry and mutable EthereumVisualizerRegistryBuilder - Clarify lifecycle: setup phase (builder) vs. execution phase (registry) - Make register() return Option<Box<dyn ContractVisualizer>> to signal overwrites - Add with_default_protocols() for explicit protocol initialization - Improve maintainability by enforcing setup/runtime separation in type system Roadmap: Milestone 1.1 - ContractVisualizer trait * refactor: Code formatting and registry module enhancements - Format code for better readability (alignment, line breaks) - Replace custom token formatting with Alloy's format_units utility - Implement ContractRegistry module with token and contract type management - Add comprehensive token formatting with metadata lookup - Update test fixtures to use proper formatting conventions Roadmap: Milestone 1.1 - Registry Co-Authored-By: Claude <noreply@anthropic.com> * refactor: Consolidate token metadata structures - Milestone 1.1 - Create token_metadata module as canonical wallet format for chain and token data - Define TokenMetadata struct with symbol, name, erc_standard, contract_address, decimals - Define ChainMetadata struct for wallet token metadata (network_id: String, assets: HashMap<symbol, TokenMetadata>) - Implement parse_network_id() to map network identifiers to chain IDs - Implement compute_metadata_hash() for SHA256 hashing of protobuf bytes - Refactor ContractRegistry to use canonical TokenMetadata structure - Registry internally maps (chain_id, Address) -> TokenMetadata for efficient lookup - Consolidate duplicate TokenMetadata and AssetInfo definitions - Update load_chain_metadata() to transform wallet format to registry format - Add sha2 dependency for metadata hashing Co-Authored-By: Claude <noreply@anthropic.com> Roadmap: Milestone 1.1 - Token and Contract registry * docs: Add CLAUDE.md guidelines for visualsign-ethereum module - Document field builder functions from visualsign crate - Include token metadata and registry usage patterns - Add supported networks and chain ID mappings - Provide best practices and common code examples - Reference Milestone 1.1 token and contract registry work Co-Authored-By: Claude <noreply@anthropic.com> Roadmap: Milestone 1.1 - code complete, starting on Uniswap using these * feat: Add registry architecture documentation and debug tracing - Document proposed registry refactor with provenance tracking - Add debug trace for contract/token lookups in transaction visualization - TODO marks for future registry layer implementation Roadmap: This marks reaching Stage1,we can start on contracts * fix: Address Copilot PR review comments and clippy warnings - Fix CLAUDE.md example to handle Result from register_token - Use inline format strings in token_metadata.rs (clippy) - Use .values() iterator in registry.rs (clippy) - Mark design doc code block as ignore to fix doc test Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
* Adding mintToChecked and burnChecked methods * Refactor fixture tests to use a common test function for mintToChecked and burnChecked transactions, improving code reuse and readability. * cargo fmt * Update error handling and layout generation to use more concise syntax. * Improve error message formatting for unsupported Token 2022 instructions * Adding test for non-happy path * Enhance security policy with reporting guidelines Updated the security policy to include guidelines for reporting vulnerabilities and our response policy. Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * Governance and Contribution docs * Update contribution workflow and approval requirements Clarified PR approval requirements for Core Team Members and Community/Public contributors, specifying the need for Anchorage employee involvement. Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * Update GOVERNANCE.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * Update CONTRIBUTING.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * Update CONTRIBUTING.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * Update CONTRIBUTING.md Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> * chore: Add CLA signers batch (#114) * chore: Add @guido-peirano-anchor to CLA signers list Approved by: @prasanna-anchorage Related PR: #113 add diego-rivas-anchor to .cla-signed-users too * add the bot too --------- Co-authored-by: Prasanna Gautam <prasanna@anchorlabs.com> * [BabyPR:ETHGlobal 1/6] Core Infrastructure Update (#102) * feat: Add VisualizerContext for Ethereum transaction visualization Add VisualizerContext struct with nested call support and token formatting. Includes Clone implementation, for_nested_call() method, and unit tests. Roadmap: Milestone 1-1, core datastructure * refactor: Implement Builder pattern for EthereumVisualizerRegistry - Rename VisualizerRegistry to EthereumVisualizerRegistry to avoid naming conflicts - Split into immutable EthereumVisualizerRegistry and mutable EthereumVisualizerRegistryBuilder - Clarify lifecycle: setup phase (builder) vs. execution phase (registry) - Make register() return Option<Box<dyn ContractVisualizer>> to signal overwrites - Add with_default_protocols() for explicit protocol initialization - Improve maintainability by enforcing setup/runtime separation in type system Roadmap: Milestone 1.1 - ContractVisualizer trait * refactor: Code formatting and registry module enhancements - Format code for better readability (alignment, line breaks) - Replace custom token formatting with Alloy's format_units utility - Implement ContractRegistry module with token and contract type management - Add comprehensive token formatting with metadata lookup - Update test fixtures to use proper formatting conventions Roadmap: Milestone 1.1 - Registry Co-Authored-By: Claude <noreply@anthropic.com> * refactor: Consolidate token metadata structures - Milestone 1.1 - Create token_metadata module as canonical wallet format for chain and token data - Define TokenMetadata struct with symbol, name, erc_standard, contract_address, decimals - Define ChainMetadata struct for wallet token metadata (network_id: String, assets: HashMap<symbol, TokenMetadata>) - Implement parse_network_id() to map network identifiers to chain IDs - Implement compute_metadata_hash() for SHA256 hashing of protobuf bytes - Refactor ContractRegistry to use canonical TokenMetadata structure - Registry internally maps (chain_id, Address) -> TokenMetadata for efficient lookup - Consolidate duplicate TokenMetadata and AssetInfo definitions - Update load_chain_metadata() to transform wallet format to registry format - Add sha2 dependency for metadata hashing Co-Authored-By: Claude <noreply@anthropic.com> Roadmap: Milestone 1.1 - Token and Contract registry * docs: Add CLAUDE.md guidelines for visualsign-ethereum module - Document field builder functions from visualsign crate - Include token metadata and registry usage patterns - Add supported networks and chain ID mappings - Provide best practices and common code examples - Reference Milestone 1.1 token and contract registry work Co-Authored-By: Claude <noreply@anthropic.com> Roadmap: Milestone 1.1 - code complete, starting on Uniswap using these * feat: Add registry architecture documentation and debug tracing - Document proposed registry refactor with provenance tracking - Add debug trace for contract/token lookups in transaction visualization - TODO marks for future registry layer implementation Roadmap: This marks reaching Stage1,we can start on contracts * fix: Address Copilot PR review comments and clippy warnings - Fix CLAUDE.md example to handle Result from register_token - Use inline format strings in token_metadata.rs (clippy) - Use .values() iterator in registry.rs (clippy) - Mark design doc code block as ignore to fix doc test Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> * Add spl-token-2022-interface dependency and refactor Token 2022 instruction parsing to utilize the new interface for improved clarity and error handling. * cargo fmt * fix lint --------- Signed-off-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> Co-authored-by: Diego Rivas <diego.rivas@anchorlabs.com> Co-authored-by: prasanna-anchorage <48452975+prasanna-anchorage@users.noreply.github.com> Co-authored-by: Prasanna Gautam <prasanna@anchorlabs.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
…caffolding (#103) * feat: Add VisualizerContext for Ethereum transaction visualization Add VisualizerContext struct with nested call support and token formatting. Includes Clone implementation, for_nested_call() method, and unit tests. Roadmap: Milestone 1-1, core datastructure * refactor: Code formatting and registry module enhancements - Format code for better readability (alignment, line breaks) - Replace custom token formatting with Alloy's format_units utility - Implement ContractRegistry module with token and contract type management - Add comprehensive token formatting with metadata lookup - Update test fixtures to use proper formatting conventions Roadmap: Milestone 1.1 - Registry Co-Authored-By: Claude <noreply@anthropic.com> * refactor: Consolidate token metadata structures - Milestone 1.1 - Create token_metadata module as canonical wallet format for chain and token data - Define TokenMetadata struct with symbol, name, erc_standard, contract_address, decimals - Define ChainMetadata struct for wallet token metadata (network_id: String, assets: HashMap<symbol, TokenMetadata>) - Implement parse_network_id() to map network identifiers to chain IDs - Implement compute_metadata_hash() for SHA256 hashing of protobuf bytes - Refactor ContractRegistry to use canonical TokenMetadata structure - Registry internally maps (chain_id, Address) -> TokenMetadata for efficient lookup - Consolidate duplicate TokenMetadata and AssetInfo definitions - Update load_chain_metadata() to transform wallet format to registry format - Add sha2 dependency for metadata hashing Co-Authored-By: Claude <noreply@anthropic.com> Roadmap: Milestone 1.1 - Token and Contract registry * feat: Add registry architecture documentation and debug tracing - Document proposed registry refactor with provenance tracking - Add debug trace for contract/token lookups in transaction visualization - TODO marks for future registry layer implementation Roadmap: This marks reaching Stage1,we can start on contracts * fix: Address Copilot PR review comments and clippy warnings - Fix CLAUDE.md example to handle Result from register_token - Use inline format strings in token_metadata.rs (clippy) - Use .values() iterator in registry.rs (clippy) - Mark design doc code block as ignore to fix doc test Co-Authored-By: Claude <noreply@anthropic.com> * refactor: Add type-safe protocol architecture for Ethereum contracts - Implement ContractType trait with compile-time uniqueness guarantees - Restructure: contracts/core/ for standards, protocols/ for DeFi protocols - Create protocols/uniswap module with config, contracts/, and register() - Add register_contract_typed<T>() for type-safe contract registration - Implement FallbackVisualizer for unknown contract calls - Document Uniswap versions (V1, V1.2, V2) and V4 PoolManager for future Impact: Prevents duplicate type identifiers at compile-time, enables scalable addition of protocols (Aave, Compound, etc.), and provides clear architectural patterns for contract organization. Roadmap: Milestone 2 * feat(ethereum): Type-safe protocol architecture with Uniswap scaffolding - Add ContractType trait for compile-time unique contract identifiers - Restructure: contracts/core/ (standards) vs protocols/ (DeFi protocols) - Implement protocols/uniswap module with config-driven registration - Rename UniswapV4Visualizer → UniversalRouterVisualizer (matches IUniversalRouter) - Stub ERC721, Permit2, and V4 PoolManager for future Etherscan decoding - Add FallbackVisualizer for unknown contracts - Document Uniswap versions (V1, V1.2, V2) and V4 PoolManager Impact: Prevents duplicate type identifiers at compile-time, enables scalable addition of protocols with clear separation of concerns. Roadmap: Uniswap transaction decoding * docs(ethereum): Add comprehensive ARCHITECTURE.md with scope and limitations Incorporate "Scope and Limitations" section from ethglobal/buenos-aires to clarify architectural boundaries between calldata decoding (in-scope) and transaction simulation (out-of-scope). This sets the final vision through PR 6. - Add detailed "Scope and Limitations" section explaining what module decodes vs what requires simulation (actual amounts, pool resolution, state changes) - Remove redundant "Benefits" checklists and testing scaffolding - Keep focused on essential architecture without implementation details - Include example output and rationale for scope boundaries * fix(ethereum): Resolve clippy warnings and apply formatting - Prefix unused parameters with underscore in visualize_tx_commands - Replace expect(&format!(...)) with unwrap_or_else(|| panic!(...)) - Use inline format string for chain_id in panic message - Apply cargo fmt formatting across modified files Co-Authored-By: Claude <noreply@anthropic.com> * change back to Input Data --------- Co-authored-by: Claude <noreply@anthropic.com>
Shows fee more correctly
WRAP_ETH was missing recipient field in struct definition, causing address bytes to be interpreted as amount (showing "2 ETH" instead of "0.0032 ETH"). SWEEP had incorrect field order (token, amount, recipient) instead of (token, recipient, amount), causing recipient bytes to be read as amount (showing astronomically large numbers). Added unit tests for both decoders to verify correct parameter order and amount formatting.
- Add `pub mod id` to chains.rs with constants grouped by chain type - Update match statement to use named constants instead of magic numbers - Replace local chains module in uniswap/config.rs with re-export - Add DefiLlama chainlist attribution for future additions Supported chains: Ethereum, BSC, Polygon, Avalanche, Fantom, Gnosis, Celo (L1); Optimism, Arbitrum, Base, Blast, Mantle, Worldchain (L2-OP); zkSync, Linea, Scroll (L2-ZK); Zora, Unichain (App-Specific) Co-Authored-By: Claude <noreply@anthropic.com>
- 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>
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>
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>
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>
Introduces extract_abi_from_metadata for wallet-provided ABIs with optional secp256k1 signature validation support.
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.
- Add Morpho protocol module with Bundler3 contract visualization - Implement type-safe decoding for multicall operations (permit, transfer, vault deposit) - Add IERC2612 interface for standard ERC-2612 permit parsing - Fix permit parameter decoding with proper token amount formatting - Add utility functions for unlimited value detection (is_unlimited_u256/u128) - Register Morpho contracts across mainnet, Optimism, Base, and Arbitrum - Support detailed parameter breakdown in expanded transaction views Fixes permit decoding that was previously failing with "Failed to decode permit parameters" error by using correct ABI interface for standard ERC-2612 permits vs bundler-specific variants.
fa0577a to
7e672cc
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is extracted from the work I initially did in #95 and from what lives on in ethglobal/buenos-aires branch. The idea here is to showcase how far you can get to support a protocol and a specific transaction with just
alloy-sol-types'ssol!macro and the abstractions provided by visualsign-parser.For instance this unsigned txn decodes as following in human-mode
Note that this doesn't cover any proxy calls or inner contract calls