-
Notifications
You must be signed in to change notification settings - Fork 4
feat: enable RIP-7212
#51
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use reth_ethereum::evm::{ | ||
primitives::{eth::EthEvmContext, precompiles::PrecompilesMap, Database, EvmEnv, EvmFactory}, | ||
revm::{ | ||
context::{ | ||
result::{EVMError, HaltReason}, | ||
TxEnv, | ||
}, | ||
handler::EthPrecompiles, | ||
inspector::NoOpInspector, | ||
interpreter::interpreter::EthInterpreter, | ||
primitives::hardfork::SpecId, | ||
Context, Inspector, MainBuilder, MainContext, | ||
}, | ||
EthEvm, | ||
}; | ||
|
||
use crate::precompiles::custom_prague_precompiles; | ||
|
||
/// Rollkit EVM factory that allows custom precompiles. | ||
#[derive(Debug, Clone, Default)] | ||
#[non_exhaustive] | ||
pub struct RollkitEvmFactory; | ||
|
||
impl EvmFactory for RollkitEvmFactory { | ||
type Evm<DB: Database, I: Inspector<EthEvmContext<DB>, EthInterpreter>> = | ||
EthEvm<DB, I, Self::Precompiles>; | ||
type Context<DB: Database> = EthEvmContext<DB>; | ||
type Tx = TxEnv; | ||
type Error<DBError: core::error::Error + Send + Sync + 'static> = EVMError<DBError>; | ||
type HaltReason = HaltReason; | ||
type Spec = SpecId; | ||
type Precompiles = PrecompilesMap; | ||
|
||
fn create_evm<DB: Database>(&self, db: DB, input: EvmEnv) -> Self::Evm<DB, NoOpInspector> { | ||
let spec = input.cfg_env.spec; | ||
let mut evm = Context::mainnet() | ||
.with_db(db) | ||
.with_cfg(input.cfg_env) | ||
.with_block(input.block_env) | ||
.build_mainnet_with_inspector(NoOpInspector {}) | ||
.with_precompiles(PrecompilesMap::from_static( | ||
EthPrecompiles::default().precompiles, | ||
)); | ||
|
||
if spec == SpecId::PRAGUE { | ||
evm = evm.with_precompiles(PrecompilesMap::from_static(custom_prague_precompiles())); | ||
} | ||
|
||
EthEvm::new(evm, false) | ||
} | ||
|
||
fn create_evm_with_inspector<DB: Database, I: Inspector<Self::Context<DB>, EthInterpreter>>( | ||
&self, | ||
db: DB, | ||
input: EvmEnv, | ||
inspector: I, | ||
) -> Self::Evm<DB, I> { | ||
EthEvm::new( | ||
self.create_evm(db, input) | ||
.into_inner() | ||
.with_inspector(inspector), | ||
true, | ||
) | ||
} | ||
Comment on lines
+52
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider refactoring the EVM context creation into a private helper function. This helper could take an inspector as an argument and be used by both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The interface can't be changed because we are implementing Reth's |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::evm::RollkitEvmFactory; | ||
use reth_ethereum::{ | ||
chainspec::ChainSpec, | ||
node::{ | ||
api::{FullNodeTypes, NodeTypes}, | ||
builder::{components::ExecutorBuilder, BuilderContext}, | ||
EthEvmConfig, | ||
}, | ||
EthPrimitives, | ||
}; | ||
|
||
/// Rollkit executor builder that utilizes the Rollkit EVM factory. | ||
#[derive(Debug, Default, Clone, Copy)] | ||
#[non_exhaustive] | ||
pub struct RollkitExecutorBuilder; | ||
|
||
impl<Node> ExecutorBuilder<Node> for RollkitExecutorBuilder | ||
where | ||
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives>>, | ||
{ | ||
type EVM = EthEvmConfig<ChainSpec, RollkitEvmFactory>; | ||
|
||
async fn build_evm(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::EVM> { | ||
let evm_config = | ||
EthEvmConfig::new_with_evm_factory(ctx.chain_spec(), RollkitEvmFactory::default()); | ||
Ok(evm_config) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use reth_ethereum::evm::revm::precompile::{secp256r1, Precompiles}; | ||
use std::sync::OnceLock; | ||
|
||
pub(crate) fn custom_prague_precompiles() -> &'static Precompiles { | ||
static INSTANCE: OnceLock<Precompiles> = OnceLock::new(); | ||
INSTANCE.get_or_init(|| { | ||
let mut precompiles = Precompiles::prague().clone(); | ||
|
||
// https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md | ||
precompiles.extend(secp256r1::precompiles()); | ||
|
||
precompiles | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation incorrectly overrides spec-specific precompiles with those for the
LATEST
hardfork. The call to.with_precompiles(PrecompilesMap::from_static(EthPrecompiles::default().precompiles))
forces the use ofLATEST
precompiles, which is incorrect for other hardforks like Cancun. This can lead to consensus failures.The fix is to remove this explicit
with_precompiles
call and letrevm
determine the correct precompiles based on thespec_id
. The custom Prague precompiles should only be applied when the spec is indeedPRAGUE
.