Skip to content

Commit 4124dad

Browse files
committed
Run cargo fmt on the whole workspace
1 parent fd4fd6a commit 4124dad

34 files changed

+959
-794
lines changed

benches/loop.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::{str::FromStr, collections::BTreeMap};
21
use criterion::{criterion_group, criterion_main, Criterion};
3-
use primitive_types::{U256, H160};
2+
use evm::backend::{MemoryAccount, MemoryBackend, MemoryVicinity};
3+
use evm::executor::{MemoryStackState, StackExecutor, StackSubstateMetadata};
44
use evm::Config;
5-
use evm::executor::{StackExecutor, MemoryStackState, StackSubstateMetadata};
6-
use evm::backend::{MemoryAccount, MemoryVicinity, MemoryBackend};
5+
use primitive_types::{H160, U256};
6+
use std::{collections::BTreeMap, str::FromStr};
77

88
fn run_loop_contract() {
99
let config = Config::istanbul();
@@ -49,14 +49,15 @@ fn run_loop_contract() {
4949
H160::from_str("0xf000000000000000000000000000000000000000").unwrap(),
5050
H160::from_str("0x1000000000000000000000000000000000000000").unwrap(),
5151
U256::zero(),
52-
hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000b71b00").unwrap(),
52+
hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000b71b00")
53+
.unwrap(),
5354
// hex::decode("0f14a4060000000000000000000000000000000000000000000000000000000000002ee0").unwrap(),
5455
u64::MAX,
5556
);
5657
}
5758

5859
fn criterion_benchmark(c: &mut Criterion) {
59-
c.bench_function("loop contract", |b| b.iter(|| run_loop_contract()));
60+
c.bench_function("loop contract", |b| b.iter(|| run_loop_contract()));
6061
}
6162

6263
criterion_group!(benches, criterion_benchmark);

core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use alloc::borrow::Cow;
21
use crate::Opcode;
2+
use alloc::borrow::Cow;
33

44
/// Trap which indicates that an `ExternalOpcode` has to be handled.
55
pub type Trap = Opcode;

core/src/eval/arithmetic.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use core::ops::Rem;
1+
use crate::utils::I256;
22
use core::convert::TryInto;
3+
use core::ops::Rem;
34
use primitive_types::{U256, U512};
4-
use crate::utils::I256;
55

66
#[inline]
77
pub fn div(op1: U256, op2: U256) -> U256 {
@@ -51,7 +51,8 @@ pub fn addmod(op1: U256, op2: U256, op3: U256) -> U256 {
5151
U256::zero()
5252
} else {
5353
let v = (op1 + op2) % op3;
54-
v.try_into().expect("op3 is less than U256::MAX, thus it never overflows; qed")
54+
v.try_into()
55+
.expect("op3 is less than U256::MAX, thus it never overflows; qed")
5556
}
5657
}
5758

@@ -65,7 +66,8 @@ pub fn mulmod(op1: U256, op2: U256, op3: U256) -> U256 {
6566
U256::zero()
6667
} else {
6768
let v = (op1 * op2) % op3;
68-
v.try_into().expect("op3 is less than U256::MAX, thus it never overflows; qed")
69+
v.try_into()
70+
.expect("op3 is less than U256::MAX, thus it never overflows; qed")
6971
}
7072
}
7173

core/src/eval/bitwise.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use primitive_types::U256;
21
use crate::utils::{Sign, I256};
2+
use primitive_types::U256;
33

44
#[inline]
55
pub fn slt(op1: U256, op2: U256) -> U256 {
@@ -99,7 +99,8 @@ pub fn sar(shift: U256, value: U256) -> U256 {
9999
Sign::Plus | Sign::NoSign => value.1 >> shift as usize,
100100
Sign::Minus => {
101101
let shifted = ((value.1.overflowing_sub(U256::one()).0) >> shift as usize)
102-
.overflowing_add(U256::one()).0;
102+
.overflowing_add(U256::one())
103+
.0;
103104
I256(Sign::Minus, shifted).into()
104105
}
105106
}

core/src/eval/macros.rs

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ macro_rules! try_or_fail {
22
( $e:expr ) => {
33
match $e {
44
Ok(v) => v,
5-
Err(e) => return Control::Exit(e.into())
5+
Err(e) => return Control::Exit(e.into()),
66
}
7-
}
7+
};
88
}
99

1010
macro_rules! pop {
@@ -54,99 +54,79 @@ macro_rules! push_u256 {
5454
}
5555

5656
macro_rules! op1_u256_fn {
57-
( $machine:expr, $op:path ) => (
58-
{
59-
pop_u256!($machine, op1);
60-
let ret = $op(op1);
61-
push_u256!($machine, ret);
57+
( $machine:expr, $op:path ) => {{
58+
pop_u256!($machine, op1);
59+
let ret = $op(op1);
60+
push_u256!($machine, ret);
6261

63-
Control::Continue(1)
64-
}
65-
)
62+
Control::Continue(1)
63+
}};
6664
}
6765

6866
macro_rules! op2_u256_bool_ref {
69-
( $machine:expr, $op:ident ) => (
70-
{
71-
pop_u256!($machine, op1, op2);
72-
let ret = op1.$op(&op2);
73-
push_u256!($machine, if ret {
74-
U256::one()
75-
} else {
76-
U256::zero()
77-
});
78-
79-
Control::Continue(1)
80-
}
81-
)
67+
( $machine:expr, $op:ident ) => {{
68+
pop_u256!($machine, op1, op2);
69+
let ret = op1.$op(&op2);
70+
push_u256!($machine, if ret { U256::one() } else { U256::zero() });
71+
72+
Control::Continue(1)
73+
}};
8274
}
8375

8476
macro_rules! op2_u256 {
85-
( $machine:expr, $op:ident ) => (
86-
{
87-
pop_u256!($machine, op1, op2);
88-
let ret = op1.$op(op2);
89-
push_u256!($machine, ret);
77+
( $machine:expr, $op:ident ) => {{
78+
pop_u256!($machine, op1, op2);
79+
let ret = op1.$op(op2);
80+
push_u256!($machine, ret);
9081

91-
Control::Continue(1)
92-
}
93-
)
82+
Control::Continue(1)
83+
}};
9484
}
9585

9686
macro_rules! op2_u256_tuple {
97-
( $machine:expr, $op:ident ) => (
98-
{
99-
pop_u256!($machine, op1, op2);
100-
let (ret, ..) = op1.$op(op2);
101-
push_u256!($machine, ret);
87+
( $machine:expr, $op:ident ) => {{
88+
pop_u256!($machine, op1, op2);
89+
let (ret, ..) = op1.$op(op2);
90+
push_u256!($machine, ret);
10291

103-
Control::Continue(1)
104-
}
105-
)
92+
Control::Continue(1)
93+
}};
10694
}
10795

10896
macro_rules! op2_u256_fn {
109-
( $machine:expr, $op:path ) => (
110-
{
111-
pop_u256!($machine, op1, op2);
112-
let ret = $op(op1, op2);
113-
push_u256!($machine, ret);
97+
( $machine:expr, $op:path ) => {{
98+
pop_u256!($machine, op1, op2);
99+
let ret = $op(op1, op2);
100+
push_u256!($machine, ret);
114101

115-
Control::Continue(1)
116-
}
117-
)
102+
Control::Continue(1)
103+
}};
118104
}
119105

120106
macro_rules! op3_u256_fn {
121-
( $machine:expr, $op:path ) => (
122-
{
123-
pop_u256!($machine, op1, op2, op3);
124-
let ret = $op(op1, op2, op3);
125-
push_u256!($machine, ret);
107+
( $machine:expr, $op:path ) => {{
108+
pop_u256!($machine, op1, op2, op3);
109+
let ret = $op(op1, op2, op3);
110+
push_u256!($machine, ret);
126111

127-
Control::Continue(1)
128-
}
129-
)
112+
Control::Continue(1)
113+
}};
130114
}
131115

132116
macro_rules! as_usize_or_fail {
133-
( $v:expr ) => {
134-
{
135-
if $v > U256::from(usize::MAX) {
136-
return Control::Exit(ExitFatal::NotSupported.into())
137-
}
138-
139-
$v.as_usize()
117+
( $v:expr ) => {{
118+
if $v > U256::from(usize::MAX) {
119+
return Control::Exit(ExitFatal::NotSupported.into());
140120
}
141-
};
142121

143-
( $v:expr, $reason:expr ) => {
144-
{
145-
if $v > U256::from(usize::MAX) {
146-
return Control::Exit($reason.into())
147-
}
122+
$v.as_usize()
123+
}};
148124

149-
$v.as_usize()
125+
( $v:expr, $reason:expr ) => {{
126+
if $v > U256::from(usize::MAX) {
127+
return Control::Exit($reason.into());
150128
}
151-
};
129+
130+
$v.as_usize()
131+
}};
152132
}

core/src/eval/misc.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use super::Control;
2+
use crate::{ExitError, ExitFatal, ExitRevert, ExitSucceed, Machine};
13
use core::cmp::min;
24
use primitive_types::{H256, U256};
3-
use super::Control;
4-
use crate::{Machine, ExitError, ExitSucceed, ExitFatal, ExitRevert};
55

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

1717
try_or_fail!(state.memory.resize_offset(memory_offset, len));
18-
match state.memory.copy_large(memory_offset, code_offset, len, &state.code) {
18+
match state
19+
.memory
20+
.copy_large(memory_offset, code_offset, len, &state.code)
21+
{
1922
Ok(()) => Control::Continue(1),
2023
Err(e) => Control::Exit(e.into()),
2124
}
@@ -54,10 +57,13 @@ pub fn calldatacopy(state: &mut Machine) -> Control {
5457

5558
try_or_fail!(state.memory.resize_offset(memory_offset, len));
5659
if len == U256::zero() {
57-
return Control::Continue(1)
60+
return Control::Continue(1);
5861
}
5962

60-
match state.memory.copy_large(memory_offset, data_offset, len, &state.data) {
63+
match state
64+
.memory
65+
.copy_large(memory_offset, data_offset, len, &state.data)
66+
{
6167
Ok(()) => Control::Continue(1),
6268
Err(e) => Control::Exit(e.into()),
6369
}

core/src/eval/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ mod arithmetic;
44
mod bitwise;
55
mod misc;
66

7+
use crate::{ExitError, ExitReason, ExitSucceed, Machine, Opcode};
78
use core::ops::{BitAnd, BitOr, BitXor};
89
use primitive_types::{H256, U256};
9-
use crate::{ExitReason, ExitSucceed, ExitError, Machine, Opcode};
1010

1111
#[derive(Clone, Eq, PartialEq, Debug)]
1212
pub enum Control {

0 commit comments

Comments
 (0)