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

build: bump revm to commit aceb093 #428

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-tables-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Upgraded revm to commit aceb093
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/edr_eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ reqwest = { version = "0.11", features = ["blocking", "json"] }
reqwest-middleware = { version = "0.2.4", default-features = false }
reqwest-retry = { version = "0.3.0", default-features = false }
reqwest-tracing = { version = "0.4.7", default-features = false, optional = true }
revm-primitives = { git = "https://github.com/Wodann/revm", rev = "451f122", version = "3.1", default-features = false, features = ["hashbrown"] }
revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "3.1", default-features = false, features = ["hashbrown"] }
serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0.89", optional = true }
sha3 = { version = "0.10.8", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_eth/src/block/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn bomb_delay(spec_id: SpecId) -> u64 {
// SpecId::LONDON => 9500000, // EIP-3554
SpecId::ARROW_GLACIER => 10700000,
SpecId::GRAY_GLACIER => 11400000,
SpecId::MERGE | SpecId::SHANGHAI | SpecId::CANCUN | SpecId::LATEST => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Prague was added to the SpecId. Given that rewards were removed post-Merge, there is no point not using the wildcard here (and below)

_ => {
unreachable!("Post-merge hardforks don't have a bomb delay")
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_eth/src/block/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ pub fn miner_reward(spec_id: SpecId) -> Option<U256> {
| SpecId::LONDON
| SpecId::ARROW_GLACIER
| SpecId::GRAY_GLACIER => Some(U256::from(2_000_000_000_000_000_000u128)),
SpecId::MERGE | SpecId::SHANGHAI | SpecId::CANCUN | SpecId::LATEST => None,
_ => None,
}
}
2 changes: 1 addition & 1 deletion crates/edr_evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ once_cell = { version = "1.18.0", default-features = false, features = ["alloc",
parking_lot = { version = "0.12.1", default-features = false }
edr_defaults = { version = "0.3.5", path = "../edr_defaults" }
edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["rand", "serde"] }
revm = { git = "https://github.com/Wodann/revm", rev = "451f122", version = "8.0", default-features = false, features = ["c-kzg", "dev", "serde"] }
revm = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "8.0", default-features = false, features = ["c-kzg", "dev", "serde"] }
rpds = { version = "1.1.0", default-features = false, features = ["std"] }
serde = { version = "1.0.158", default-features = false, features = ["std"] }
serde_json = { version = "1.0.94", default-features = false, features = ["std"] }
Expand Down
1 change: 0 additions & 1 deletion crates/edr_evm/benches/state/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,5 @@ pub fn account_has_code(state: &dyn SyncState<StateError>, address: &Address) ->
&& !state
.code_by_hash(account_info.code_hash)
.expect("code_by_hash should succeed")
.bytecode
.is_empty()
}
8 changes: 4 additions & 4 deletions crates/edr_evm/src/debug_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use revm::{
db::DatabaseComponents,
handler::register::EvmHandler,
interpreter::{
opcode::{self, BoxedInstruction, InstructionTables},
opcode::{self, BoxedInstruction, InstructionTables, OpCode},
InstructionResult, Interpreter, InterpreterResult,
},
primitives::{
Expand Down Expand Up @@ -326,7 +326,7 @@ impl TracerEip3155 {
}

fn step(&mut self, interp: &mut Interpreter) {
self.contract_address = interp.contract.address;
self.contract_address = interp.contract.target_address;
self.gas_remaining = interp.gas().remaining();

if !self.config.disable_stack {
Expand Down Expand Up @@ -392,15 +392,15 @@ impl TracerEip3155 {
};

let mut error = None;
let op_name = opcode::OPCODE_JUMPMAP[self.opcode as usize].map_or_else(
let op_name = OpCode::new(self.opcode).map_or_else(
|| {
// Matches message from Hardhat
// https://github.com/NomicFoundation/hardhat/blob/37c5c5845969b15995cc96cb6bd0596977f8b1f8/packages/hardhat-core/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts#L452
let fallback = format!("opcode 0x${:x} not defined", self.opcode);
error = Some(fallback.clone());
fallback
},
String::from,
|opcode| opcode.to_string(),
);

let gas_cost = self.gas_remaining.saturating_sub(interp.gas().remaining());
Expand Down
22 changes: 14 additions & 8 deletions crates/edr_evm/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use revm::{
handler::register::EvmHandler,
interpreter::{
opcode::{self, BoxedInstruction, InstructionTables},
return_revert, CallInputs, CallOutcome, CreateInputs, CreateOutcome, InstructionResult,
Interpreter, SuccessOrHalt,
return_revert, CallInputs, CallOutcome, CallValue, CreateInputs, CreateOutcome,
InstructionResult, Interpreter, SuccessOrHalt,
},
primitives::{Bytecode, EVMError, ExecutionResult, Output},
Database, Evm, EvmContext, FrameOrResult, FrameResult,
Expand Down Expand Up @@ -118,6 +118,10 @@ pub fn register_trace_collector_handles<
let create_inputs = create_input_stack.borrow_mut().pop().unwrap();
tracer.create_transaction_end(&ctx.evm, &create_inputs, outcome);
}
// TODO: https://github.com/NomicFoundation/edr/issues/427
FrameResult::EOFCreate(_) => {
panic!("EDR doesn't support EOF yet. This code should not be reachable.")
Wodann marked this conversation as resolved.
Show resolved Hide resolved
}
}
old_handle(ctx, frame_result)
});
Expand Down Expand Up @@ -284,7 +288,7 @@ impl TraceCollector {
let code = data
.journaled_state
.state
.get(&inputs.contract)
.get(&inputs.bytecode_address)
.map(|account| account.info.clone())
.map(|mut account_info| {
if let Some(code) = account_info.code.take() {
Expand All @@ -294,7 +298,7 @@ impl TraceCollector {
}
})
.unwrap_or_else(|| {
data.db.basic(inputs.contract).unwrap().map_or(
data.db.basic(inputs.bytecode_address).unwrap().map_or(
// If an invalid contract address was provided, return empty code
Bytecode::new(),
|account_info| {
Expand All @@ -307,12 +311,14 @@ impl TraceCollector {

self.pending_before = Some(BeforeMessage {
depth: data.journaled_state.depth,
caller: inputs.context.caller,
to: Some(inputs.context.address),
caller: inputs.caller,
to: Some(inputs.target_address),
gas_limit: inputs.gas_limit,
data: inputs.input.clone(),
value: inputs.context.apparent_value,
code_address: Some(inputs.context.code_address),
value: match inputs.value {
CallValue::Transfer(value) | CallValue::Apparent(value) => value,
},
code_address: Some(inputs.bytecode_address),
code: Some(code),
});
}
Expand Down
20 changes: 17 additions & 3 deletions crates/edr_evm/src/transaction/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use edr_eth::{
Eip1559SignedTransaction, Eip155SignedTransaction, Eip2930SignedTransaction,
Eip4844SignedTransaction, LegacySignedTransaction, SignedTransaction, TxKind,
},
Address, U256,
Address, HashMap, U256,
};
use revm::{
interpreter::gas::validate_initial_tx_gas,
primitives::{CreateScheme, SpecId, TransactTo, TxEnv},
primitives::{SpecId, TransactTo, TxEnv},
};

use super::TransactionCreationError;
Expand Down Expand Up @@ -109,7 +109,7 @@ impl From<ExecutableTransaction> for TxEnv {
fn transact_to(kind: TxKind) -> TransactTo {
match kind {
TxKind::Call(address) => TransactTo::Call(address),
TxKind::Create => TransactTo::Create(CreateScheme::Create),
TxKind::Create => TransactTo::Create,
}
}

Expand Down Expand Up @@ -145,6 +145,9 @@ impl From<ExecutableTransaction> for TxEnv {
access_list: Vec::new(),
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
// TODO: https://github.com/NomicFoundation/edr/issues/427
eof_initcodes: Vec::new(),
eof_initcodes_hashed: HashMap::new(),
},
SignedTransaction::Eip2930(Eip2930SignedTransaction {
nonce,
Expand All @@ -168,6 +171,9 @@ impl From<ExecutableTransaction> for TxEnv {
access_list: access_list.into(),
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
// TODO: https://github.com/NomicFoundation/edr/issues/427
eof_initcodes: Vec::new(),
eof_initcodes_hashed: HashMap::new(),
},
SignedTransaction::Eip1559(Eip1559SignedTransaction {
nonce,
Expand All @@ -192,6 +198,9 @@ impl From<ExecutableTransaction> for TxEnv {
access_list: access_list.into(),
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
// TODO: https://github.com/NomicFoundation/edr/issues/427
eof_initcodes: Vec::new(),
eof_initcodes_hashed: HashMap::new(),
},
SignedTransaction::Eip4844(Eip4844SignedTransaction {
nonce,
Expand All @@ -218,6 +227,9 @@ impl From<ExecutableTransaction> for TxEnv {
gas_priority_fee: Some(max_priority_fee_per_gas),
blob_hashes,
max_fee_per_blob_gas: Some(max_fee_per_blob_gas),
// TODO: https://github.com/NomicFoundation/edr/issues/427
eof_initcodes: Vec::new(),
eof_initcodes_hashed: HashMap::new(),
},
}
}
Expand Down Expand Up @@ -416,6 +428,8 @@ fn initial_cost(spec_id: SpecId, transaction: &SignedTransaction) -> u64 {
access_list
.as_ref()
.map_or(&[], |access_list| access_list.as_slice()),
// TODO: https://github.com/NomicFoundation/edr/issues/427
&[],
)
}

Expand Down
6 changes: 2 additions & 4 deletions crates/edr_napi/src/trace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use edr_evm::{interpreter::OPCODE_JUMPMAP, trace::BeforeMessage};
use edr_evm::{interpreter::OpCode, trace::BeforeMessage};
use napi::{
bindgen_prelude::{BigInt, Buffer, Either3},
Env, JsBuffer, JsBufferValue,
Expand Down Expand Up @@ -96,9 +96,7 @@ impl TracingStep {
Self {
depth: step.depth as u8,
pc: BigInt::from(step.pc),
opcode: OPCODE_JUMPMAP[usize::from(step.opcode)]
.unwrap_or("")
.to_string(),
opcode: OpCode::name_by_op(step.opcode).to_string(),
stack_top: step.stack_top.map(|v| BigInt {
sign_bit: false,
words: v.into_limbs().to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_provider/src/console_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn register_console_log_handles<
let old_handle = handler.execution.call.clone();
handler.execution.call = Arc::new(
move |ctx, inputs| -> Result<FrameOrResult, EVMError<DatabaseT::Error>> {
if inputs.contract == CONSOLE_ADDRESS {
if inputs.bytecode_address == CONSOLE_ADDRESS {
let collector = ctx.external.get_context_data();
collector.record_console_log(inputs.input.clone());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_provider/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn register_mocking_handles<DatabaseT: Database, ContextT: GetContextData<Mo
if let Some(CallOverrideResult {
output,
should_revert,
}) = mocker.override_call(inputs.contract, inputs.input.clone())
}) = mocker.override_call(inputs.bytecode_address, inputs.input.clone())
{
let result = if should_revert {
InstructionResult::Revert
Expand Down
Loading