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

WEB3-322: feat: Add HostEvmEnv::extend method for merging environments #420

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

Conversation

Wollac
Copy link
Contributor

@Wollac Wollac commented Jan 27, 2025

This PR adds the ability to merge multiple HostEvmEnv instances, enabling parallel preflight execution of contract calls.

Changes

  • Add extend method to HostEvmEnv for merging environments
  • Add comprehensive documentation with examples
  • Add extend_checked helper function for safe HashMap merging

Usage Example

// Create separate environments for parallel execution
let mut env1 = builder.clone().build().await?;
let mut contract1 = Contract::preflight(usdt_addr, &mut env1);
let mut env2 = builder.clone().build().await?;
let mut contract2 = Contract::preflight(usdc_addr, &mut env2);
// Execute calls in parallel
tokio::join!(
  contract1.call_builder(&call).call(),
  contract2.call_builder(&call).call()
);
// Merge the environments
env1.extend(env2);
let evm_input = env1.into_input().await?;

Implementation Details

  • Merges database state
  • Performs consistency checks to ensure environments are compatible
  • Panics on inconsistencies (mismatching configs, headers, or DB states)
  • Preserves all proofs and state from both environments

Testing

The functionality is demonstrated through doctest examples. Additional integration tests would be valuable to add in a follow-up PR.

@Wollac Wollac requested a review from a team as a code owner January 27, 2025 18:17
@github-actions github-actions bot changed the title feat: Add HostEvmEnv::extend method for merging environments WEB3-322: feat: Add HostEvmEnv::extend method for merging environments Jan 27, 2025
Comment on lines +93 to +94
/// Extends the `ProofDb` with the contents of another `ProofDb`. It panics if they are not
/// consistent.
Copy link
Contributor

Choose a reason for hiding this comment

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

A ProofDb is linked to a single state (commitment) ya? So trying to merge the ProofDb for two different blocks will panic here. I can see how, if written correctly, this will never fail. It also seems like an common enough mistake that panicking is perhaps too extreme, and could result in DoS in cases where e.g. someone is running a service that produces Steel proofs, if an error can cause the service to go down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it so that the public extend now returns an error if the header config does not match. This could be a user error.
If the actual hash maps are extended, the panic is kept because this should not be possible without fraudulent RPC nodes. Also, this would be unrecoverable since the DB has already been modified.

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