Skip to content
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

prototype to support web3 provider connection #956

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

anvacaru
Copy link
Contributor

@anvacaru anvacaru commented Feb 1, 2025

This PR enhances the KEVM semantics by integrating support for forking state via a remote web3 provider. With the new --fork-url and --fork-block-number options, users can now run proofs against real network state, and the updated custom steps properly fetch account and storage data on demand. The new web3 RPC utilities and refactoring reduce duplication and improve code maintainability.

Limitations:

1.Running multiple proofs in parallel might throw a Max retries exceeded with url due to the number of requests at startup. Will be fixed by caching responses in a future PR.
2. Fork management using cheatcodes (i.e. vm.createFork, vm.selectFork) not yet supported.

Summary

  1. pyproject.toml: added web3 module as a dependency

  2. In src/kontrol/cli.py:

    • added --fork-url. This option allows users to specify a remote web3 provider URL so that state can be fetched from a live network.
    • added --fork-block-number. This option allows users to specify a block number from which the provider reads information. The number is set in the configuration's <number> cell.
  3. In src/kontrol/foundry.py, the KontrolSemantics class constructor now accepts an optional provider_url. When provided, it retrieves a web3 provider via the new Web3Providers registry.

  4. New custom step definitions have been added (using the new CustomStep wrapper) for fetching account data and storage from the web3 provider. These custom steps include:
    _fetch_storage_pattern with _exec_fetch_storage_custom_step
    _fetch_account_pattern with _exec_fetch_account_custom_step

  5. Helper functions such as update_forked_accounts_cell, get_set_from_cterm, and add_storage_slot_to_account have been added/refactored to remove duplicated logic when updating the forked accounts cell or adding storage data to an account.

  6. Proof Initialization Updates:

  • When a fork URL is provided, a web3 provider is obtained and block metadata is fetched via the new helper function get_block_metadata. These values are injected into the configuration.
  1. New Web3 Module has been added in src/kontrol/web3_rpc.py. This module contains:
  • The Web3Providers class, which caches and reuses Web3 instances per unique URL.
  • Helper functions to fetch block metadata, account code, storage value, and balance from the web3 provider.
  1. Semantics update in foundry.md:
  • two new cells added to the configuration:
    - <forkedAccounts> .Set </forkedAccounts> - to keep track of accounts read from a provider.
    - <allowWeb3Connection> false </allowWeb3Connection> - flag to allow web3 connections.
  • two new functions added: #accountInState and #accountHasStorageSlot (can be upstreamed to kevm).
  • two new productions FETCH_ACCOUNT and FETCH_ACCOUNT_STORAGE added together with rules that add them at the top of the K_CELL when there is a need to fetch informantion from a Web3 provider.

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.

None yet

1 participant