-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,099 additions
and
665 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# v3.0.0 | ||
|
||
Interpreter was extracted from main REVM crate. Before v3.0.0 version, this code was part of REVM. |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[package] | ||
authors = ["Dragan Rakita <[email protected]>"] | ||
description = "REVM Interpreter" | ||
edition = "2021" | ||
keywords = ["no_std", "ethereum", "vm", "evm", "revm", "interpreter"] | ||
license = "MIT" | ||
name = "revm-interpreter" | ||
repository = "https://github.com/bluealloy/revm" | ||
version = "3.0.0" | ||
readme = "../../README.md" | ||
|
||
[dependencies] | ||
bytes = { version = "1.1", default-features = false } | ||
hashbrown = { version = "0.13" } | ||
hex = { version = "0.4", default-features = false } | ||
rlp = { version = "0.5", default-features = false } # used for create2 address calculation | ||
ruint = { version = "1.7.0", features = ["primitive-types", "rlp"] } | ||
|
||
|
||
# bits B256 B160 crate | ||
fixed-hash = { version = "0.8", default-features = false, features = [ | ||
"rustc-hex", | ||
] } | ||
|
||
#utility | ||
hex-literal = "0.3" | ||
derive_more = "0.99" | ||
enumn = "0.1" | ||
|
||
# sha3 keccak hasher | ||
sha3 = { version = "0.10", default-features = false, features = [] } | ||
|
||
# optional | ||
serde = { version = "1.0", features = ["derive", "rc"], optional = true } | ||
arbitrary = { version = "1.2", features = ["derive"], optional = true } | ||
|
||
[dev-dependencies] | ||
arbitrary = { version = "1.2", features = ["derive"] } | ||
proptest = { version = "1.0" } | ||
proptest-derive = "0.2.0" | ||
ruint = { version = "1.7.0", features = [ | ||
"primitive-types", | ||
"rlp", | ||
"proptest", | ||
"arbitrary", | ||
] } | ||
|
||
[features] | ||
default = ["std"] | ||
dev = [ | ||
"memory_limit", | ||
"optional_balance_check", | ||
"optional_block_gas_limit", | ||
"optional_eip3607", | ||
"optional_gas_refund", | ||
] | ||
memory_limit = [] | ||
no_gas_measuring = [] | ||
optional_balance_check = [] | ||
optional_block_gas_limit = [] | ||
optional_eip3607 = [] | ||
optional_gas_refund = [] | ||
std = ["bytes/std", "rlp/std", "hex/std"] | ||
serde = [ | ||
"dep:serde", | ||
"hex/serde", | ||
"hashbrown/serde", | ||
"ruint/serde", | ||
"bytes/serde", | ||
] | ||
arbitrary = ["dep:arbitrary", "ruint/arbitrary", "ruint/proptest"] |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::{B160, B256, U256}; | ||
use sha3::{Digest, Keccak256}; | ||
|
||
#[inline(always)] | ||
pub fn keccak256(input: &[u8]) -> B256 { | ||
B256::from_slice(Keccak256::digest(input).as_slice()) | ||
} | ||
|
||
/// Returns the address for the legacy `CREATE` scheme: [`CreateScheme::Create`] | ||
pub fn create_address(caller: B160, nonce: u64) -> B160 { | ||
let mut stream = rlp::RlpStream::new_list(2); | ||
stream.append(&caller.0.as_ref()); | ||
stream.append(&nonce); | ||
let out = keccak256(&stream.out()); | ||
B160(out[12..].try_into().unwrap()) | ||
} | ||
|
||
/// Returns the address for the `CREATE2` scheme: [`CreateScheme::Create2`] | ||
pub fn create2_address(caller: B160, code_hash: B256, salt: U256) -> B160 { | ||
let mut hasher = Keccak256::new(); | ||
hasher.update([0xff]); | ||
hasher.update(&caller[..]); | ||
hasher.update(salt.to_be_bytes::<{ U256::BYTES }>()); | ||
hasher.update(&code_hash[..]); | ||
|
||
B160(hasher.finalize().as_slice()[12..].try_into().unwrap()) | ||
} | ||
|
||
/// Serde functions to serde as [bytes::Bytes] hex string | ||
#[cfg(feature = "serde")] | ||
pub(crate) mod serde_hex_bytes { | ||
use serde::{Deserialize, Deserializer, Serializer}; | ||
|
||
pub fn serialize<S, T>(x: T, s: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
T: AsRef<[u8]>, | ||
{ | ||
s.serialize_str(&format!("0x{}", hex::encode(x.as_ref()))) | ||
} | ||
|
||
pub fn deserialize<'de, D>(d: D) -> Result<bytes::Bytes, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let value = String::deserialize(d)?; | ||
if let Some(value) = value.strip_prefix("0x") { | ||
hex::decode(value) | ||
} else { | ||
hex::decode(&value) | ||
} | ||
.map(Into::into) | ||
.map_err(|e| serde::de::Error::custom(e.to_string())) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
mod dummy_host; | ||
|
||
use crate::{ | ||
Bytecode, Bytes, CallInputs, CreateInputs, Env, Gas, Interpreter, Return, SelfDestructResult, | ||
B160, B256, U256, | ||
}; | ||
pub use dummy_host::DummyHost; | ||
|
||
/// EVM context host. | ||
pub trait Host { | ||
fn step(&mut self, interpreter: &mut Interpreter, is_static: bool) -> Return; | ||
fn step_end(&mut self, interpreter: &mut Interpreter, is_static: bool, ret: Return) -> Return; | ||
|
||
fn env(&mut self) -> &mut Env; | ||
|
||
/// load account. Returns (is_cold,is_new_account) | ||
fn load_account(&mut self, address: B160) -> Option<(bool, bool)>; | ||
/// Get environmental block hash. | ||
fn block_hash(&mut self, number: U256) -> Option<B256>; | ||
/// Get balance of address and if account is cold loaded. | ||
fn balance(&mut self, address: B160) -> Option<(U256, bool)>; | ||
/// Get code of address and if account is cold loaded. | ||
fn code(&mut self, address: B160) -> Option<(Bytecode, bool)>; | ||
/// Get code hash of address and if account is cold loaded. | ||
fn code_hash(&mut self, address: B160) -> Option<(B256, bool)>; | ||
/// Get storage value of address at index and if account is cold loaded. | ||
fn sload(&mut self, address: B160, index: U256) -> Option<(U256, bool)>; | ||
/// Set storage value of account address at index. | ||
/// Returns (original, present, new, sis_cold) | ||
fn sstore( | ||
&mut self, | ||
address: B160, | ||
index: U256, | ||
value: U256, | ||
) -> Option<(U256, U256, U256, bool)>; | ||
/// Create a log owned by address with given topics and data. | ||
fn log(&mut self, address: B160, topics: Vec<B256>, data: Bytes); | ||
/// Mark an address to be deleted, with funds transferred to target. | ||
fn selfdestruct(&mut self, address: B160, target: B160) -> Option<SelfDestructResult>; | ||
/// Invoke a create operation. | ||
fn create(&mut self, inputs: &mut CreateInputs) -> (Return, Option<B160>, Gas, Bytes); | ||
/// Invoke a call operation. | ||
fn call(&mut self, input: &mut CallInputs) -> (Return, Gas, Bytes); | ||
} |
Oops, something went wrong.