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

Add memory offset #1032

Merged
merged 46 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
81f6d57
mems offset
DoTheBestToGetTheBest Jan 30, 2024
3cfbdce
Update evm.rs
DoTheBestToGetTheBest Jan 30, 2024
ad8b6af
Update context.rs
DoTheBestToGetTheBest Jan 30, 2024
9923c28
Update host.rs
DoTheBestToGetTheBest Jan 30, 2024
1bce713
Update host.rs
DoTheBestToGetTheBest Jan 30, 2024
7d4542a
Update host.rs
DoTheBestToGetTheBest Jan 30, 2024
2db4e52
use core instead of std
DoTheBestToGetTheBest Jan 30, 2024
47ae246
Update host.rs
DoTheBestToGetTheBest Jan 31, 2024
857c9d9
Update evm.rs
DoTheBestToGetTheBest Jan 31, 2024
11cf24d
Update interpreter.rs
DoTheBestToGetTheBest Jan 31, 2024
d3526bc
clippy
DoTheBestToGetTheBest Jan 31, 2024
6c33f94
Update interpreter.rs
DoTheBestToGetTheBest Jan 31, 2024
04b314a
rename Ranger to Range
DoTheBestToGetTheBest Jan 31, 2024
5589bbc
Update inner_models.rs
DoTheBestToGetTheBest Jan 31, 2024
35c45b4
Update inner_models.rs
DoTheBestToGetTheBest Feb 1, 2024
d9ea8d0
Update evm.rs
DoTheBestToGetTheBest Feb 1, 2024
d720618
Update execution.rs
DoTheBestToGetTheBest Feb 2, 2024
8e1de41
Update evm.rs
DoTheBestToGetTheBest Feb 2, 2024
a63bb1e
Update evm.rs
DoTheBestToGetTheBest Feb 2, 2024
6450b24
Update evm.rs
DoTheBestToGetTheBest Feb 2, 2024
baee6c0
Update host.rs
DoTheBestToGetTheBest Feb 2, 2024
bf5cb66
Update crates/interpreter/src/interpreter.rs
DoTheBestToGetTheBest Feb 2, 2024
b4a601f
Update execution.rs
DoTheBestToGetTheBest Feb 7, 2024
91fc750
Update execution.rs
DoTheBestToGetTheBest Feb 7, 2024
25d0b77
Update handler_register.rs
DoTheBestToGetTheBest Feb 7, 2024
59a7d68
Update context.rs
DoTheBestToGetTheBest Feb 7, 2024
f505139
Update frame.rs
DoTheBestToGetTheBest Feb 7, 2024
bcbcbb1
Update execution.rs
DoTheBestToGetTheBest Feb 7, 2024
e2dfde8
Update execution.rs
DoTheBestToGetTheBest Feb 7, 2024
5f6a870
Update evm.rs
DoTheBestToGetTheBest Feb 7, 2024
1f0111c
Update handler_register.rs
DoTheBestToGetTheBest Feb 7, 2024
b6da825
Update eip3155.rs
DoTheBestToGetTheBest Feb 7, 2024
6a5c2a2
Update eip3155.rs
DoTheBestToGetTheBest Feb 7, 2024
0716693
Update customprinter.rs
DoTheBestToGetTheBest Feb 7, 2024
eb0b8ee
Update inspector.rs
DoTheBestToGetTheBest Feb 7, 2024
6218664
Update gas.rs
DoTheBestToGetTheBest Feb 7, 2024
709c831
Update handler_register.rs
DoTheBestToGetTheBest Feb 7, 2024
80dcd5d
Update context.rs
DoTheBestToGetTheBest Feb 7, 2024
22e7fd9
Update execution.rs
DoTheBestToGetTheBest Feb 7, 2024
cd79f7f
Update evm.rs
DoTheBestToGetTheBest Feb 7, 2024
5f84bcd
Update inner_models.rs
DoTheBestToGetTheBest Feb 7, 2024
0e0ae60
Update handler_register.rs
DoTheBestToGetTheBest Feb 7, 2024
59a5b5d
Update handler_register.rs
DoTheBestToGetTheBest Feb 8, 2024
cb2e066
Update inner_models.rs
DoTheBestToGetTheBest Feb 8, 2024
1ebe9eb
Update crates/revm/src/inspector.rs
rakita Feb 12, 2024
cedfd61
Merge branch 'main' into add-memory-offset
rakita Feb 12, 2024
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
22 changes: 16 additions & 6 deletions crates/interpreter/src/inner_models.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pub use crate::primitives::CreateScheme;
use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
use alloc::boxed::Box;

pub use crate::primitives::CreateScheme;

use core::ops::Range as Ranger;
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
/// Inputs for a call.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -19,6 +18,8 @@ pub struct CallInputs {
pub context: CallContext,
/// Whether this is a static call.
pub is_static: bool,
/// The return memory offset where the output of the call is written.
pub return_memory_offset: Ranger<usize>,
}

/// Inputs for a create call.
Expand All @@ -39,7 +40,11 @@ pub struct CreateInputs {

impl CallInputs {
/// Creates new call inputs.
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
pub fn new(
tx_env: &TxEnv,
gas_limit: u64,
return_memory_offset: Ranger<usize>,
) -> Option<Self> {
let TransactTo::Call(address) = tx_env.transact_to else {
return None;
};
Expand All @@ -61,12 +66,17 @@ impl CallInputs {
scheme: CallScheme::Call,
},
is_static: false,
return_memory_offset,
})
}

/// Returns boxed call inputs.
pub fn new_boxed(tx_env: &TxEnv, gas_limit: u64) -> Option<Box<Self>> {
Self::new(tx_env, gas_limit).map(Box::new)
pub fn new_boxed(
tx_env: &TxEnv,
gas_limit: u64,
return_memory_offset: Ranger<usize>,
) -> Option<Box<Self>> {
Self::new(tx_env, gas_limit, return_memory_offset).map(Box::new)
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ pub fn call<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
scheme: CallScheme::Call,
},
is_static: interpreter.is_static,
return_memory_offset,
}),
return_memory_offset,
};
interpreter.instruction_result = InstructionResult::CallOrCreate;
}
Expand Down Expand Up @@ -419,8 +419,8 @@ pub fn call_code<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut
scheme: CallScheme::CallCode,
},
is_static: interpreter.is_static,
return_memory_offset,
}),
return_memory_offset,
};
interpreter.instruction_result = InstructionResult::CallOrCreate;
}
Expand Down Expand Up @@ -465,8 +465,8 @@ pub fn delegate_call<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &
scheme: CallScheme::DelegateCall,
},
is_static: interpreter.is_static,
return_memory_offset,
}),
return_memory_offset,
};
interpreter.instruction_result = InstructionResult::CallOrCreate;
}
Expand Down Expand Up @@ -511,8 +511,8 @@ pub fn static_call<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &mu
scheme: CallScheme::StaticCall,
},
is_static: true,
return_memory_offset,
}),
return_memory_offset,
};
interpreter.instruction_result = InstructionResult::CallOrCreate;
}
6 changes: 1 addition & 5 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};
use alloc::boxed::Box;
use core::cmp::min;
use core::ops::Range;

DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
use revm_primitives::U256;

pub use self::shared_memory::EMPTY_SHARED_MEMORY;
Expand Down Expand Up @@ -70,10 +70,6 @@ pub enum InterpreterAction {
Call {
/// Call inputs
inputs: Box<CallInputs>,
/// The offset into `self.memory` of the return data.
///
/// This value must be ignored if `self.return_len` is 0.
return_memory_offset: Range<usize>,
},
/// CREATE or CREATE2 instruction called.
Create { inputs: Box<CreateInputs> },
Expand Down
1 change: 1 addition & 0 deletions crates/revm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ pub(crate) mod test_utils {
scheme: revm_interpreter::CallScheme::Call,
},
is_static: false,
return_memory_offset: 0..0,
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {

let exec = &mut self.handler.execution;
let frame_or_result = match next_action {
InterpreterAction::Call {
inputs,
return_memory_offset,
} => exec.call(&mut self.context, inputs, return_memory_offset),
InterpreterAction::Call { inputs } => exec.call(&mut self.context, inputs, 0..0),
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
InterpreterAction::Create { inputs } => exec.create(&mut self.context, inputs),
InterpreterAction::Return { result } => {
// free memory context.
Expand Down Expand Up @@ -276,7 +273,7 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
let first_frame_or_result = match ctx.evm.env.tx.transact_to {
TransactTo::Call(_) => exec.call(
ctx,
CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit).unwrap(),
CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit, 0..0).unwrap(),
0..0,
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
),
TransactTo::Create(_) => exec.create(
Expand Down
Loading