Skip to content

Commit

Permalink
feat: eip-3074
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed May 12, 2024
1 parent d9f9504 commit 2b3853c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ reth-testing-utils = { path = "testing/testing-utils" }
# revm
revm = { version = "8.0.0", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { version = "3.1.0", features = ["std"], default-features = false }
revm-interpreter = { version = "4.0.0", features = ["std"], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "c1b5dd0" }

# eth
Expand Down
4 changes: 3 additions & 1 deletion crates/ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ reth-evm.workspace = true
reth-primitives.workspace = true
reth-revm.workspace = true
reth-interfaces.workspace = true
alphanet-instructions = { git = "https://github.com/paradigmxyz/alphanet/" }

# Ethereum
revm-primitives.workspace = true
revm-interpreter.workspace = true

# misc
tracing.workspace = true

[dev-dependencies]
reth-revm = { workspace = true, features = ["test-utils"] }
reth-revm = { workspace = true, features = ["test-utils"] }
44 changes: 43 additions & 1 deletion crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,56 @@ impl ConfigureEvmEnv for EthEvmConfig {
}
}

use alphanet_instructions::{context::InstructionsContext, eip3074, BoxedInstructionWithOpCode};
use revm_interpreter::{opcode::InstructionTables, Host};
use std::sync::Arc;

/// Inserts the given boxed instructions with opcodes in the instructions table.
fn insert_boxed_instructions<'a, I, H>(
table: &mut InstructionTables<'a, H>,
boxed_instructions_with_opcodes: I,
) where
I: Iterator<Item = BoxedInstructionWithOpCode<'a, H>>,
H: Host + 'a,
{
for boxed_instruction_with_opcode in boxed_instructions_with_opcodes {
table.insert_boxed(
boxed_instruction_with_opcode.opcode,
boxed_instruction_with_opcode.boxed_instruction,
);
}
}

impl ConfigureEvm for EthEvmConfig {
type DefaultExternalContext<'a> = ();

fn evm<'a, DB: Database + 'a>(
&self,
db: DB,
) -> reth_revm::Evm<'a, Self::DefaultExternalContext<'a>, DB> {
EvmBuilder::default().with_db(db).build()
let instructions_context = InstructionsContext::default();
EvmBuilder::default()
.with_db(db)
.append_handler_register_box(Box::new(move |h| {
if let Some(ref mut table) = h.instruction_table {
insert_boxed_instructions(
table,
eip3074::boxed_instructions(instructions_context.clone()),
);

instructions_context.clear();
}

let post_execution_context = instructions_context.clone();
#[allow(clippy::arc_with_non_send_sync)]
{
h.post_execution.end = Arc::new(move |_, outcome: _| {
post_execution_context.clear();
outcome
});
}
}))
.build()
}
}

Expand Down

0 comments on commit 2b3853c

Please sign in to comment.