Skip to content

Commit

Permalink
Run cargo fmt on the whole workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas committed Jul 26, 2021
1 parent fd4fd6a commit 4124dad
Show file tree
Hide file tree
Showing 34 changed files with 959 additions and 794 deletions.
13 changes: 7 additions & 6 deletions benches/loop.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{str::FromStr, collections::BTreeMap};
use criterion::{criterion_group, criterion_main, Criterion};
use primitive_types::{U256, H160};
use evm::backend::{MemoryAccount, MemoryBackend, MemoryVicinity};
use evm::executor::{MemoryStackState, StackExecutor, StackSubstateMetadata};
use evm::Config;
use evm::executor::{StackExecutor, MemoryStackState, StackSubstateMetadata};
use evm::backend::{MemoryAccount, MemoryVicinity, MemoryBackend};
use primitive_types::{H160, U256};
use std::{collections::BTreeMap, str::FromStr};

fn run_loop_contract() {
let config = Config::istanbul();
Expand Down Expand Up @@ -49,14 +49,15 @@ fn run_loop_contract() {
H160::from_str("0xf000000000000000000000000000000000000000").unwrap(),
H160::from_str("0x1000000000000000000000000000000000000000").unwrap(),
U256::zero(),
hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000b71b00").unwrap(),
hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000b71b00")
.unwrap(),
// hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000002ee0").unwrap(),
u64::MAX,
);
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("loop contract", |b| b.iter(|| run_loop_contract()));
c.bench_function("loop contract", |b| b.iter(|| run_loop_contract()));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
2 changes: 1 addition & 1 deletion core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::borrow::Cow;
use crate::Opcode;
use alloc::borrow::Cow;

/// Trap which indicates that an `ExternalOpcode` has to be handled.
pub type Trap = Opcode;
Expand Down
10 changes: 6 additions & 4 deletions core/src/eval/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ops::Rem;
use crate::utils::I256;
use core::convert::TryInto;
use core::ops::Rem;
use primitive_types::{U256, U512};
use crate::utils::I256;

#[inline]
pub fn div(op1: U256, op2: U256) -> U256 {
Expand Down Expand Up @@ -51,7 +51,8 @@ pub fn addmod(op1: U256, op2: U256, op3: U256) -> U256 {
U256::zero()
} else {
let v = (op1 + op2) % op3;
v.try_into().expect("op3 is less than U256::MAX, thus it never overflows; qed")
v.try_into()
.expect("op3 is less than U256::MAX, thus it never overflows; qed")
}
}

Expand All @@ -65,7 +66,8 @@ pub fn mulmod(op1: U256, op2: U256, op3: U256) -> U256 {
U256::zero()
} else {
let v = (op1 * op2) % op3;
v.try_into().expect("op3 is less than U256::MAX, thus it never overflows; qed")
v.try_into()
.expect("op3 is less than U256::MAX, thus it never overflows; qed")
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/eval/bitwise.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use primitive_types::U256;
use crate::utils::{Sign, I256};
use primitive_types::U256;

#[inline]
pub fn slt(op1: U256, op2: U256) -> U256 {
Expand Down Expand Up @@ -99,7 +99,8 @@ pub fn sar(shift: U256, value: U256) -> U256 {
Sign::Plus | Sign::NoSign => value.1 >> shift as usize,
Sign::Minus => {
let shifted = ((value.1.overflowing_sub(U256::one()).0) >> shift as usize)
.overflowing_add(U256::one()).0;
.overflowing_add(U256::one())
.0;
I256(Sign::Minus, shifted).into()
}
}
Expand Down
120 changes: 50 additions & 70 deletions core/src/eval/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ macro_rules! try_or_fail {
( $e:expr ) => {
match $e {
Ok(v) => v,
Err(e) => return Control::Exit(e.into())
Err(e) => return Control::Exit(e.into()),
}
}
};
}

macro_rules! pop {
Expand Down Expand Up @@ -54,99 +54,79 @@ macro_rules! push_u256 {
}

macro_rules! op1_u256_fn {
( $machine:expr, $op:path ) => (
{
pop_u256!($machine, op1);
let ret = $op(op1);
push_u256!($machine, ret);
( $machine:expr, $op:path ) => {{
pop_u256!($machine, op1);
let ret = $op(op1);
push_u256!($machine, ret);

Control::Continue(1)
}
)
Control::Continue(1)
}};
}

macro_rules! op2_u256_bool_ref {
( $machine:expr, $op:ident ) => (
{
pop_u256!($machine, op1, op2);
let ret = op1.$op(&op2);
push_u256!($machine, if ret {
U256::one()
} else {
U256::zero()
});

Control::Continue(1)
}
)
( $machine:expr, $op:ident ) => {{
pop_u256!($machine, op1, op2);
let ret = op1.$op(&op2);
push_u256!($machine, if ret { U256::one() } else { U256::zero() });

Control::Continue(1)
}};
}

macro_rules! op2_u256 {
( $machine:expr, $op:ident ) => (
{
pop_u256!($machine, op1, op2);
let ret = op1.$op(op2);
push_u256!($machine, ret);
( $machine:expr, $op:ident ) => {{
pop_u256!($machine, op1, op2);
let ret = op1.$op(op2);
push_u256!($machine, ret);

Control::Continue(1)
}
)
Control::Continue(1)
}};
}

macro_rules! op2_u256_tuple {
( $machine:expr, $op:ident ) => (
{
pop_u256!($machine, op1, op2);
let (ret, ..) = op1.$op(op2);
push_u256!($machine, ret);
( $machine:expr, $op:ident ) => {{
pop_u256!($machine, op1, op2);
let (ret, ..) = op1.$op(op2);
push_u256!($machine, ret);

Control::Continue(1)
}
)
Control::Continue(1)
}};
}

macro_rules! op2_u256_fn {
( $machine:expr, $op:path ) => (
{
pop_u256!($machine, op1, op2);
let ret = $op(op1, op2);
push_u256!($machine, ret);
( $machine:expr, $op:path ) => {{
pop_u256!($machine, op1, op2);
let ret = $op(op1, op2);
push_u256!($machine, ret);

Control::Continue(1)
}
)
Control::Continue(1)
}};
}

macro_rules! op3_u256_fn {
( $machine:expr, $op:path ) => (
{
pop_u256!($machine, op1, op2, op3);
let ret = $op(op1, op2, op3);
push_u256!($machine, ret);
( $machine:expr, $op:path ) => {{
pop_u256!($machine, op1, op2, op3);
let ret = $op(op1, op2, op3);
push_u256!($machine, ret);

Control::Continue(1)
}
)
Control::Continue(1)
}};
}

macro_rules! as_usize_or_fail {
( $v:expr ) => {
{
if $v > U256::from(usize::MAX) {
return Control::Exit(ExitFatal::NotSupported.into())
}

$v.as_usize()
( $v:expr ) => {{
if $v > U256::from(usize::MAX) {
return Control::Exit(ExitFatal::NotSupported.into());
}
};

( $v:expr, $reason:expr ) => {
{
if $v > U256::from(usize::MAX) {
return Control::Exit($reason.into())
}
$v.as_usize()
}};

$v.as_usize()
( $v:expr, $reason:expr ) => {{
if $v > U256::from(usize::MAX) {
return Control::Exit($reason.into());
}
};

$v.as_usize()
}};
}
16 changes: 11 additions & 5 deletions core/src/eval/misc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Control;
use crate::{ExitError, ExitFatal, ExitRevert, ExitSucceed, Machine};
use core::cmp::min;
use primitive_types::{H256, U256};
use super::Control;
use crate::{Machine, ExitError, ExitSucceed, ExitFatal, ExitRevert};

#[inline]
pub fn codesize(state: &mut Machine) -> Control {
Expand All @@ -15,7 +15,10 @@ pub fn codecopy(state: &mut Machine) -> Control {
pop_u256!(state, memory_offset, code_offset, len);

try_or_fail!(state.memory.resize_offset(memory_offset, len));
match state.memory.copy_large(memory_offset, code_offset, len, &state.code) {
match state
.memory
.copy_large(memory_offset, code_offset, len, &state.code)
{
Ok(()) => Control::Continue(1),
Err(e) => Control::Exit(e.into()),
}
Expand Down Expand Up @@ -54,10 +57,13 @@ pub fn calldatacopy(state: &mut Machine) -> Control {

try_or_fail!(state.memory.resize_offset(memory_offset, len));
if len == U256::zero() {
return Control::Continue(1)
return Control::Continue(1);
}

match state.memory.copy_large(memory_offset, data_offset, len, &state.data) {
match state
.memory
.copy_large(memory_offset, data_offset, len, &state.data)
{
Ok(()) => Control::Continue(1),
Err(e) => Control::Exit(e.into()),
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ mod arithmetic;
mod bitwise;
mod misc;

use crate::{ExitError, ExitReason, ExitSucceed, Machine, Opcode};
use core::ops::{BitAnd, BitOr, BitXor};
use primitive_types::{H256, U256};
use crate::{ExitReason, ExitSucceed, ExitError, Machine, Opcode};

#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Control {
Expand Down
Loading

0 comments on commit 4124dad

Please sign in to comment.