Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fmt, clippy
  • Loading branch information
rakita committed Jul 30, 2022
commit 18ec4767d67147a11d0952af9d317695d2de482e
22 changes: 10 additions & 12 deletions bins/revm-test/src/bin/analysis.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bins/revme/src/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sha3::{Digest, Keccak256};

use indicatif::ProgressBar;
use primitive_types::{H160, H256, U256};
use revm::{db::AccountState, CreateScheme, Env, SpecId, TransactTo, Bytecode};
use revm::{db::AccountState, Bytecode, CreateScheme, Env, SpecId, TransactTo};
use std::sync::atomic::Ordering;
use walkdir::{DirEntry, WalkDir};

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use web3db::Web3DB;

pub use in_memory_db::{AccountState, BenchmarkDB, CacheDB, DbAccount, EmptyDB, InMemoryDB};

use crate::{Account, interpreter::bytecode::Bytecode};
use crate::{interpreter::bytecode::Bytecode, Account};
use hashbrown::HashMap as Map;
use primitive_types::{H160, H256, U256};

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub struct BenchmarkDB(pub Bytecode, H256);
impl BenchmarkDB {
pub fn new_bytecode(bytecode: Bytecode) -> Self {
let hash = bytecode.hash();
Self(bytecode,hash)
Self(bytecode, hash)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/db/web3db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AccountInfo, Database, KECCAK_EMPTY, interpreter::bytecode::Bytecode};
use crate::{interpreter::bytecode::Bytecode, AccountInfo, Database, KECCAK_EMPTY};
use bytes::Bytes;
use primitive_types::{H160, H256, U256};
use tokio::runtime::{Handle, Runtime};
Expand Down
3 changes: 2 additions & 1 deletion crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
db::Database,
gas, interpreter::{self, bytecode::Bytecode},
gas,
interpreter::{self, bytecode::Bytecode},
interpreter::{Contract, Interpreter},
models::SelfDestructResult,
return_ok,
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn extcodecopy<H: Host, SPEC: Spec>(interp: &mut Interpreter, host: &mut H)
// Safety: set_data is unsafe function and memory_resize ensures us that it is safe to call it
interp
.memory
.set_data(memory_offset, code_offset, len, &code.bytes());
.set_data(memory_offset, code_offset, len, code.bytes());
Return::Continue
}

Expand Down
9 changes: 6 additions & 3 deletions crates/revm/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ pub fn codecopy(interp: &mut Interpreter) -> Return {
memory_resize!(interp, memory_offset, len);

// Safety: set_data is unsafe function and memory_resize ensures us that it is safe to call it
interp
.memory
.set_data(memory_offset, code_offset, len, interp.contract.bytecode.original_bytecode_slice());
interp.memory.set_data(
memory_offset,
code_offset,
len,
interp.contract.bytecode.original_bytecode_slice(),
);
Return::Continue
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ mod contract;
pub(crate) mod memory;
mod stack;

pub use bytecode::{Bytecode, BytecodeLocked, BytecodeState};
pub use contract::Contract;
pub use memory::Memory;
pub use stack::Stack;
pub use bytecode::{Bytecode,BytecodeState,BytecodeLocked};

use crate::{
instructions::{eval, Return},
Expand Down
26 changes: 20 additions & 6 deletions crates/revm/src/interpreter/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ impl Bytecode {
}
}

/// Safety: Bytecode need to end with STOP (0x00) opcode as checked bytecode assumes that
/// Create new checked bytecode
///
/// # Safety
/// Bytecode need to end with STOP (0x00) opcode as checked bytecode assumes that
/// that it is safe to iterate over bytecode without checking lengths
pub unsafe fn new_checked(bytecode: Bytes, len: usize) -> Self {
Self {
Expand All @@ -58,7 +61,10 @@ impl Bytecode {
}
}

/// Safety: Same as new_checked, bytecode needs to end with STOP (0x00) opcode as checked bytecode assumes
/// Create new analysed bytecode
///
/// # Safety
/// Same as new_checked, bytecode needs to end with STOP (0x00) opcode as checked bytecode assumes
/// that it is safe to iterate over bytecode without checking length
pub unsafe fn new_analysed(bytecode: Bytes, len: usize, jumptable: ValidJumpAddress) -> Self {
Self {
Expand Down Expand Up @@ -120,15 +126,15 @@ impl Bytecode {
BytecodeState::Raw => {
let len = self.bytecode.len();
let checked = self.to_checked();
(checked.bytecode.into(), len)
(checked.bytecode, len)
}
BytecodeState::Checked { len } => (self.bytecode, len),
_ => return self,
};
let jumptable = Self::analyze::<SPEC>(bytecode.as_ref());

Self {
bytecode: bytecode.into(),
bytecode,
state: BytecodeState::Analysed { len, jumptable },
}
}
Expand Down Expand Up @@ -195,7 +201,9 @@ impl Bytecode {
}
}
unsafe {
jumps.get_unchecked_mut(block_start).set_gas_block(gas_in_block);
jumps
.get_unchecked_mut(block_start)
.set_gas_block(gas_in_block);
}
block_start = index;
gas_in_block = 0;
Expand All @@ -210,7 +218,9 @@ impl Bytecode {
}
if gas_in_block != 0 {
unsafe {
jumps.get_unchecked_mut(block_start).set_gas_block(gas_in_block);
jumps
.get_unchecked_mut(block_start)
.set_gas_block(gas_in_block);
}
}
analysis
Expand All @@ -231,6 +241,10 @@ impl BytecodeLocked {
self.len
}

pub fn is_empty(&self) -> bool {
self.len == 0
}

pub fn unlock(self) -> Bytecode {
Bytecode {
bytecode: self.bytecode,
Expand Down
19 changes: 7 additions & 12 deletions crates/revm/src/interpreter/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::rc::Rc;

use super::bytecode::{Bytecode, BytecodeLocked};
use crate::{alloc::vec::Vec, CallContext, Spec};
use bytes::Bytes;
use primitive_types::{H160, U256};
use super::bytecode::{Bytecode, BytecodeLocked};

pub struct Contract {
/// Contracts data
Expand All @@ -27,7 +27,7 @@ pub enum Analysis {
None,
}

const JUMP_MASK : u32 = 0x80000000;
const JUMP_MASK: u32 = 0x80000000;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AnalysisData {
Expand Down Expand Up @@ -69,7 +69,6 @@ impl Contract {
caller: H160,
value: U256,
) -> Self {

let bytecode = bytecode.lock::<SPEC>();
Self {
input,
Expand Down Expand Up @@ -149,35 +148,31 @@ impl ValidJumpAddress {
}
}



#[cfg(test)]
mod tests {
use super::AnalysisData;


#[test]
pub fn test_jump_set() {
let mut jump = AnalysisData::none();
assert!(!jump.is_jump());
assert_eq!(jump.gas_block(),0);

assert_eq!(jump.gas_block(), 0);

jump.set_gas_block(2350);
assert!(!jump.is_jump());
assert_eq!(jump.gas_block(),2350);
assert_eq!(jump.gas_block(), 2350);

jump.set_is_jump();
assert!(jump.is_jump());
assert_eq!(jump.gas_block(),2350);
assert_eq!(jump.gas_block(), 2350);

jump.set_gas_block(10);
assert!(jump.is_jump());
assert_eq!(jump.gas_block(),10);
assert_eq!(jump.gas_block(), 10);

jump.set_gas_block(350);
assert!(jump.is_jump());
assert_eq!(jump.gas_block(),350);
assert_eq!(jump.gas_block(), 350);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cmp::min;

use crate::{alloc::vec::Vec, SpecId, interpreter::bytecode::Bytecode};
use crate::{alloc::vec::Vec, interpreter::bytecode::Bytecode, SpecId};
use bytes::Bytes;
use primitive_types::{H160, H256, U256};

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/subroutine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{models::SelfDestructResult, Return, KECCAK_EMPTY, interpreter::bytecode::Bytecode};
use crate::{interpreter::bytecode::Bytecode, models::SelfDestructResult, Return, KECCAK_EMPTY};
use alloc::{vec, vec::Vec};
use core::mem::{self};
use hashbrown::{hash_map::Entry, HashMap as Map};
Expand Down
2 changes: 1 addition & 1 deletion crates/revmjs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::convert::TryInto;

use bn_rs::BN;
use bytes::{Bytes, BytesMut};
use bytes::Bytes;
use primitive_types::{H160, U256};
use revm::{AccountInfo, Bytecode, DatabaseCommit, InMemoryDB, SpecId, TransactTo, EVM as rEVM};
use wasm_bindgen::prelude::*;
Expand Down