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

Integrate revmc JIT #86

Closed
gakonst opened this issue Jul 9, 2024 · 2 comments
Closed

Integrate revmc JIT #86

gakonst opened this issue Jul 9, 2024 · 2 comments

Comments

@gakonst
Copy link
Member

gakonst commented Jul 9, 2024

Depends on #85 so that code is better optimized and works better to do for all contracts that way.

@DaniPopes
Copy link
Member

Some more context:

revmc is an EVM AOT and JIT compiler. Instead of executing the bytecode through revm's interpreter, revmc lets us first compile it down to native machine code and then call into it, either ahead-of-time or while the node is running (JIT), massively improving performance in certain cases. This is all done using revm's modular handlers and external context.

What we're looking to do here is the latter; the former was attempted in this reth branch, but on testnet/mainnet didn't yield anything exciting (see links below).

Practically, implementing this means at a high level:

  • plug into ConfigureEvm with a custom revm external context; this context will receive bytecodes as input and decide whether to send it off to compile and execute in JIT or execute it normally through the interpreter
    impl ConfigureEvm for AlphaNetEvmConfig {
    type DefaultExternalContext<'a> = ();
    fn evm<DB: Database>(&self, db: DB) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> {
    EvmBuilder::default()
    .with_db(db)
    .optimism()
    // add additional precompiles
    .append_handler_register(Self::set_precompiles)
    .build()
    }
  • add a handler register which overrides the execute_frame handler, in which the external context operates to do the above
  • implement a background thread that receives bytecodes, compiles them and sends them back across a channel; this will be spawned on node launch, and a channel/handle to it will be passed through AlphaNetEvmConfig (it can also be spawned on AlphaNetEvmConfig::new)
  • add the build.rs using revmc_build to hook up the symbols needed for running the compiled codes; see https://github.com/paradigmxyz/revmc/blob/9ad12ebe060ab25818ae1bf89febde70e08ca775/examples/compiler/build.rs#L1-L4

It is crucial that any code that runs in the revm context is very performant, as it is called on every EVM interaction, including any CALL and CREATE operations.

Useful links:

@onbjerg
Copy link
Member

onbjerg commented Oct 12, 2024

Moving here: ithacaxyz/odyssey#25

@onbjerg onbjerg closed this as completed Oct 12, 2024
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

No branches or pull requests

3 participants