-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add debug_traceTransaction API * update tracer builder * update EvmBuilder * add debug transaction to the tracer * add testing for debug transaction * cleaning * fix comments
- Loading branch information
Showing
9 changed files
with
338 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ lint: | |
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- trufflehog@3.75.1 | ||
- trufflehog@3.76.0 | ||
- [email protected] | ||
ignore: | ||
- linters: [ALL] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,61 @@ | ||
use std::sync::Arc; | ||
|
||
use alphanet_instructions::{context::InstructionsContext, eip3074}; | ||
use reth_revm::{inspector_handle_register, primitives::EnvWithHandlerCfg, Database, Evm, EvmBuilder}; | ||
use reth_revm::{ | ||
handler::register::HandleRegisterBox, inspector_handle_register, primitives::EnvWithHandlerCfg, Database, Evm, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub(super) struct KakarotEvmConfig; | ||
pub(super) struct EvmBuilder; | ||
|
||
impl KakarotEvmConfig { | ||
/// Returns new EVM with the given database and env. Similar to the implementation of [reth_evm::ConfigureEvmEnv] | ||
impl EvmBuilder { | ||
/// Returns new EVM with the given database, env and inspector. Similar to the implementation of [reth_evm::ConfigureEvmEnv] | ||
/// but only keeping the necessary API. | ||
pub(super) fn evm_with_env_and_inspector<'a, DB: Database + 'a, I: reth_revm::Inspector<DB>>( | ||
&self, | ||
db: DB, | ||
env: EnvWithHandlerCfg, | ||
inspector: I, | ||
) -> Evm<'a, I, DB> { | ||
let instructions_context = InstructionsContext::default(); | ||
let to_capture_instructions = instructions_context.clone(); | ||
|
||
let mut evm = EvmBuilder::default() | ||
let mut evm = reth_revm::EvmBuilder::default() | ||
.with_db(db) | ||
.with_external_context(inspector) | ||
.append_handler_register_box(Box::new(move |handler| { | ||
if let Some(ref mut table) = handler.instruction_table { | ||
for boxed_instruction_with_opcode in eip3074::boxed_instructions(to_capture_instructions.clone()) { | ||
table.insert_boxed( | ||
boxed_instruction_with_opcode.opcode, | ||
boxed_instruction_with_opcode.boxed_instruction, | ||
); | ||
} | ||
} | ||
let post_execution_context = instructions_context.clone(); | ||
handler.post_execution.end = Arc::new(move |_, outcome: _| { | ||
// at the end of the transaction execution we clear the instructions | ||
post_execution_context.clear(); | ||
outcome | ||
}); | ||
})) | ||
.append_handler_register_box(eip3074_handle_register()) | ||
.append_handler_register(inspector_handle_register) | ||
.build(); | ||
evm.modify_spec_id(env.spec_id()); | ||
evm.context.evm.env = env.env; | ||
evm | ||
} | ||
|
||
/// Returns new EVM with the given database and env. Similar to the implementation of [reth_evm::ConfigureEvmEnv] | ||
/// but only keeping the necessary API. | ||
pub(super) fn evm_with_env<'a, DB: Database + 'a>(db: DB, env: EnvWithHandlerCfg) -> Evm<'a, (), DB> { | ||
let mut evm = | ||
reth_revm::EvmBuilder::default().with_db(db).append_handler_register_box(eip3074_handle_register()).build(); | ||
evm.modify_spec_id(env.spec_id()); | ||
evm.context.evm.env = env.env; | ||
evm | ||
} | ||
} | ||
|
||
fn eip3074_handle_register<EXT, DB: Database>() -> HandleRegisterBox<EXT, DB> { | ||
let instructions_context = InstructionsContext::default(); | ||
let to_capture_instructions = instructions_context.clone(); | ||
|
||
Box::new(move |handler| { | ||
if let Some(ref mut table) = handler.instruction_table { | ||
for boxed_instruction_with_opcode in eip3074::boxed_instructions(to_capture_instructions.clone()) { | ||
table.insert_boxed( | ||
boxed_instruction_with_opcode.opcode, | ||
boxed_instruction_with_opcode.boxed_instruction, | ||
); | ||
} | ||
} | ||
let post_execution_context = instructions_context.clone(); | ||
handler.post_execution.end = Arc::new(move |_, outcome: _| { | ||
// at the end of the transaction execution we clear the instructions | ||
post_execution_context.clear(); | ||
outcome | ||
}); | ||
}) | ||
} |
Oops, something went wrong.