EVMole

repository·master·Indexed 19 days ago

https://github.com/cdump/evmole

A high-performance library for extracting metadata from Ethereum Virtual Machine (EVM) bytecode. It enables the extraction of function selectors, arguments, state mutability, and storage layouts from deployed runtime bytecode, including for unverified contracts. It provides a JSON CLI, Go bindings, and an MCP server (evmole-mcp) for integration with agentic environments.

Tokens
23.7K
Snippets
71
Records
111
Agent score
63%

What's inside evmole

  1. Overview of EVMole JavaScript (WASM)

    master

    EVMole JavaScript (WASM) provides a WebAssembly-based implementation of EVMole for use in JavaScript environments. It is built using wasm-pack and is designed to work across modern browsers and various JavaScript bundlers.

    To simplify integration, the library provides a default entry point at ./src/evmole_esm.js that includes an await init() call, enabling compatibility with environments that support top-level await.

  2. Understand EVMole analysis limitations and warnings

    master

    When interpreting EVMole results, be aware of the following constraints:

    Inference vs. Fact:

    • Selectors are considered bytecode evidence (facts).
    • Arguments, mutability, and storage types are inferred and should not be presented as verified source-level facts.

    What EVMole does NOT do:

    • Does not fetch contract addresses.
    • Does not decode calldata.
    • Does not resolve signature names.
    • Does not verify source code.
    • Does not reconstruct exact source code.

    Best Practices:

    • Always check the warnings and pagination objects in every response before summarizing the data.
    • EVMole runs locally; bytecode is not sent to an EVMole-operated service, though your agent provider may receive the data based on their own configuration.
  3. Privacy and limitations of evmole-mcp

    master

    Privacy

    • Uses stdio only; no network requests are made.
    • Requires no credentials.
    • Does not fetch contract addresses or write files.

    Technical Limitations

    • Inference vs. Verification: Arguments, mutability, and storage descriptions are inferred from bytecode rather than verified against source-level facts.
    • Scope: Does not decode calldata, verify source, execute creation bytecode, or fully decompile source.
    • Version Matching: Each evmole-mcp release depends on the matching exact evmole version.
  4. Rules for interpreting EVM bytecode analysis results

    master

    When using EVMole to explain or report on bytecode, adhere to these interpretation rules to ensure accuracy and safety:

    • Inference vs. Fact: Treat call arguments, mutability, storage types, and storage labels as inferred. Never present them as verified source-level facts.
    • No Hallucinations: Report selectors exactly as found. Do not invent function names or source-level semantics that are not present in the bytecode.
    • Evidence Separation: Clearly separate direct bytecode evidence from inferred data or material uncertainty.
    • Scope Limitations: Do not use EVMole for:
      • Calldata decoding
      • Address/RPC fetching
      • Source verification
      • Exact source reconstruction
      • Non-EVM input
      • Full decompilation
      • Creation-bytecode execution
  5. Understanding EVMole limitations and unsupported requests

    master

    EVMole is specialized for bytecode analysis and does not support the following tasks:

    • Calldata or transaction decoding: Requires a dedicated calldata/ABI decoder.
    • Fetching an address: Requires an authorized RPC or chain-data tool.
    • Solidity source verification: Requires a compiler and a verification workflow.
    • Source reconstruction: Exact source reconstruction or full decompilation is outside the scope of EVMole.
    • Non-EVM binaries: Requires an analyzer specific to that architecture.
  6. How Control Flow Graph (CFG) analysis is measured

    master

    The CFG analysis methodology evaluates how accurately a tool identifies reachable basic blocks in EVM bytecode.

    Methodology

    1. Basic Block Construction: A block is a contiguous sequence of opcodes with one entry point, ending at JUMP, JUMPI, STOP, REVERT, RETURN, INVALID, an unknown opcode, or the end of the code. JUMPDEST marks the start of a new block and cannot appear inside one.
    2. Unreachable Block Filtering: A block is considered definitely unreachable if it does not start at pc = 0, its first instruction is not JUMPDEST, and no previous block ends with a JUMPI that falls through to it.

    Error Metrics

    • SET_BB: The set of all valid basic blocks after partitioning and removing invalid blocks.
    • SET_CFG: The set of blocks reachable from pc = 0 according to the tool's CFG algorithm.

    Metrics Calculation:

    • False Positives: (SET_CFG - SET_BB). These are blocks the tool claims are reachable but are not valid basic blocks. This should ideally be empty.
    • False Negatives: (SET_BB - SET_CFG). These are valid blocks that the tool failed to mark as reachable. Fewer false negatives indicate more precise analysis.
  7. Understanding EVMole bytecode analysis limitations

    master

    When using any EVMole binding, keep the following conceptual constraints in mind:

    • Bytecode Type: All bindings analyze deployed/runtime bytecode. They do not automatically execute or strip creation bytecode.
    • Inference vs. Verification: Data such as inferred arguments, state mutability, storage types, and storage labels should be treated as inferred from the bytecode rather than verified source-level facts. They are probabilistic/deduced, not absolute truths from the original source code.
  8. Understand how EVMole works

    master

    EVMole performs function selector and argument extraction using symbolic execution with a custom EVM implementation. Instead of relying on static pattern matching, it traces how CALLDATA flows through the bytecode.

    This method allows EVMole to accurately handle:

    • Complex dispatchers
    • Proxy patterns
    • Compiler-specific optimizations (from both Solidity and Vyper)
    • Actual execution paths the EVM would take
  9. Interpret EVMole evidence and inference results

    master

    EVMole uses static analysis to infer contract properties. Users should treat these results as probabilistic inferences rather than verified source-code declarations:

    • Selectors: Four-byte dispatch values found via static analysis. They do not provide verified function names.
    • Argument Types: Inferred ABI types based on calldata usage. These may be incomplete or ambiguous due to optimizations, assembly, or proxy patterns.
    • State Mutability: Inferred from reachable operations and call-value handling; it is not a verified ABI declaration.
    • Storage Records: Describe observed persistent or transient access and inferred types. They do not represent a verified source layout, variable names, or inheritance structure.
    • Metadata: Decoded only if a valid terminal CBOR trailer is present.
    • Disassembly/Control-flow: Describes bytecode structure, not exact high-level source semantics.

    Warning: Never resolve selectors to names without an authorized signature source, and do not assume missing evidence proves an operation is impossible.

  10. Understand the difference between runtime and creation bytecode in EVMole

    master

    EVMole schema version 1 is designed to analyze deployed/runtime bytecode (the code stored at a contract address and executed during calls).

    It does not execute constructor code (creation bytecode) and cannot automatically locate the runtime code returned by a constructor. To analyze a contract, you must first fetch or obtain the deployed runtime code directly.

  11. Run specific benchmark steps

    master

    You can execute individual stages of the benchmarking process using specific make targets:

    • make build: Builds the required Docker images.
    • make run-selectors: Runs tests for function selectors (requires Docker images to be built).
    • make reference.build: Builds the reference provider.
    • make reference.<mode>/<dataset>: Generates reference results for a specific mode and dataset (e.g., make reference.selectors/solidity-random10k).
    # Only build docker-images
    make build
    
    # Only run tests for selectors
    make run-selectors
    
    # Build the reference provider
    make reference.build
    
    # Generate reference results for a specific mode/dataset
    make reference.selectors/solidity-random10k
    make reference.arguments/solidity-random10k