Skip to content

Commit 6cb53ef

Browse files
authored
Support multiple underlying uint256 libraries (#399)
* Use uint reexport Remove all reference of primitive_types except in evm_interpreter::uint. Eventually this will allow us to support multiple underlying uint types. * Run cargo fmt * All skeletons needed for ruint and ethnum * Add ZERO and ONE consts in U256Ext * Move to_h256/from_h256 to_h160/from_h160 to U256Ext * Make ruint compile * Get ethnum to compile * Make everything compile We still need to implement those trait functions. * Run cargo fmt * Fix CI * Unbreak semver for evm-interpreter There's no reason to break it, just adding a few old functions back. * Run cargo fmt * Only require main crate to be built against ruint and ethnum * Explicitly select packages to build for ruint and ethnum * Run cargo fmt * Add allow unused_imports * Mark U256Ext as doc(hidden) We expect frequent change in this trait, so we don't want it to be part of the public API. * Seal U256Ext trait * Impl from/to_h256 for ethnum and ruint * Rename addmod -> add_mod, mulmod -> mul_mod * Native ruint add_mod and mul_mod * Finish all ruint impls * Better conversion function naming for uint * Distinguish external and internal crates External crates are not allowed to use U256Ext. * Fix tests for ruint and ethnum * Remove ethnum Too different compared with primitive-types and ruint to reliably support. Some semantics doesn't follow common uint standard. Perhaps at a later date when we have type alias impl trait. * Fix lint * Run cargo fmt * Allow unused imports of U256Ext * Update rust toolchain to 1.92 * Make ruint compile on the rest of the crates * Time-consuming tests * Bump evm/evm-interpreter to 1.1.0
1 parent 9c1e54a commit 6cb53ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+814
-439
lines changed

.github/workflows/rust.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ jobs:
2424
run: cargo clippy --workspace -- -D warnings
2525
- name: clippy no-std
2626
run: cargo clippy --workspace --no-default-features --all-targets -- -D warnings
27-
- name: clippy with features
28-
run: cargo clippy --workspace --all-features --all-targets -- -D warnings
27+
- name: clippy with normal features
28+
run: cargo clippy --workspace --features std,scale,serde --all-targets -- -D warnings
29+
- name: clippy with ruint
30+
run: cargo clippy --workspace --features ruint --all-targets -- -D warnings
31+
2932
build:
3033
runs-on: ubuntu-latest
3134
steps:
@@ -35,28 +38,41 @@ jobs:
3538
- name: Build no-std
3639
run: cargo build --no-default-features
3740
- name: Build all-features
38-
run: cargo build --all-features
39-
- name: Run tests
40-
run: cargo test --verbose
41+
run: cargo build --workspace --features std,scale,serde
42+
- name: Build ruint
43+
run: cargo build --workspace --features ruint
44+
4145
semver:
4246
runs-on: ubuntu-latest
4347
steps:
4448
- uses: actions/checkout@v5
4549
- name: Install cargo-semver-checks
4650
run: cargo install cargo-semver-checks --locked
4751
- name: SemVer evm-interpreter
48-
run: cargo semver-checks -p evm-interpreter
52+
run: cargo semver-checks --default-features -p evm-interpreter
4953
- name: SemVer evm
50-
run: cargo semver-checks -p evm
54+
run: cargo semver-checks --default-features -p evm
5155
- name: SemVer evm-precompile
52-
run: cargo semver-checks -p evm-precompile
56+
run: cargo semver-checks --default-features -p evm-precompile
5357
- name: SemVer evm-mainnet
54-
run: cargo semver-checks -p evm-mainnet
58+
run: cargo semver-checks --default-features -p evm-mainnet
59+
5560
tests:
5661
runs-on: ubuntu-latest
5762
steps:
5863
- uses: actions/checkout@v5
5964
with:
6065
submodules: recursive
61-
- name: Run tests
66+
- name: Run main tests
6267
run: cargo test --all --release --verbose
68+
- name: Run ruint tests.
69+
run: cargo test --all --release --verbose --features ruint
70+
71+
time-consuming-tests:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v5
75+
with:
76+
submodules: recursive
77+
- name: Run time consuming tests.
78+
run: cargo test --all --release --verbose --features time-consuming

Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ repository = "https://github.com/rust-ethereum/evm"
2222
keywords = ["no_std", "ethereum", "evm"]
2323

2424
[workspace.dependencies]
25-
evm = { version = "1.0.0", path = ".", default-features = false }
26-
evm-interpreter = { version = "1.0.0", path = "interpreter", default-features = false }
25+
evm = { version = "1.1.0", path = ".", default-features = false }
26+
evm-interpreter = { version = "1.1.0", path = "interpreter", default-features = false }
2727
evm-precompile = { version = "1.0.0", path = "precompile", default-features = false }
2828
evm-mainnet = { version = "1.0.0", path = "mainnet", default-features = false }
2929
evm-compat = { version = "0.1.0", path = "compat", default-features = false }
3030

3131
[package]
3232
name = "evm"
33-
version = "1.0.1"
33+
version = "1.1.0"
3434
edition = { workspace = true }
3535
rust-version = { workspace = true }
3636
license = { workspace = true }
@@ -40,7 +40,6 @@ keywords = { workspace = true }
4040
description = "Ethereum Virtual Machine"
4141

4242
[dependencies]
43-
primitive-types = { version = "0.12", default-features = false, features = ["rlp"] }
4443
sha3 = { version = "0.10", default-features = false }
4544
evm-interpreter = { workspace = true }
4645

@@ -50,16 +49,15 @@ hex = { version = "0.4", features = [ "serde" ] }
5049
[features]
5150
default = ["std"]
5251
std = [
53-
"primitive-types/std",
5452
"sha3/std",
5553
"evm-interpreter/std",
5654
]
5755
scale = [
58-
"primitive-types/codec",
59-
"primitive-types/scale-info",
6056
"evm-interpreter/scale",
6157
]
6258
serde = [
63-
"primitive-types/impl-serde",
6459
"evm-interpreter/serde",
6560
]
61+
ruint = [
62+
"evm-interpreter/ruint",
63+
]

features/evm64/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ repository = { workspace = true }
1010
keywords = { workspace = true }
1111

1212
[dependencies]
13-
primitive-types = { version = "0.12", default-features = false, features = ["rlp"] }
1413
evm = { workspace = true }
1514

1615
[features]
1716
default = ["std"]
1817
std = [
19-
"primitive-types/std",
2018
"evm/std",
2119
]

features/evm64/src/eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use core::ops::{BitAnd, BitOr, BitXor};
22

33
use evm::interpreter::{Control, ExitException, Machine};
4-
use primitive_types::U256;
4+
use evm::uint::{U256, U256Ext};
55

66
macro_rules! pop_u64 {
77
( $machine:expr, $( $x:ident ),* ) => (
88
$(
99
let $x = match $machine.stack.pop() {
10-
Ok(value) => value.0[0],
10+
Ok(value) => value.low_u64(),
1111
Err(e) => return Control::Exit(e.into()),
1212
};
1313
)*
@@ -17,7 +17,7 @@ macro_rules! pop_u64 {
1717
macro_rules! push_u64 {
1818
( $machine:expr, $( $x:expr ),* ) => (
1919
$(
20-
match $machine.stack.push(U256([$x, 0, 0, 0])) {
20+
match $machine.stack.push(U256::from_u64($x)) {
2121
Ok(()) => (),
2222
Err(e) => return Control::Exit(e.into()),
2323
}

features/evm64/src/gasometer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[allow(unused_imports)]
2+
use evm::uint::U256Ext;
13
use evm::{
24
interpreter::{Control, ExitException, Machine, Opcode},
35
standard::GasometerState,
@@ -66,7 +68,7 @@ where
6668
#[allow(clippy::single_match)]
6769
match opcode {
6870
Opcode::EXP => {
69-
let power = try_or_fail!(machine.stack.peek(1)).0[0];
71+
let power = try_or_fail!(machine.stack.peek(1)).low_u64();
7072
let cost = if power == 0 {
7173
G_EXP64_STATIC
7274
} else {

future/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ keywords.workspace = true
1212
[dependencies]
1313
evm = { path = ".." }
1414
environmental = "1.1"
15-
16-
[dev-dependencies]
17-
primitive-types = "0.12"

future/tests/usability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use evm::interpreter::{
44
Log, RuntimeBackend, RuntimeBaseBackend, RuntimeEnvironment, SetCodeOrigin, TouchKind,
55
},
66
};
7+
use evm::uint::{H160, H256, U256};
78
use evm_future::{FutureInterpreter, FutureInterpreterAction, FutureInterpreterSubmit};
8-
use primitive_types::{H160, H256, U256};
99
use std::rc::Rc;
1010

1111
struct EmptyAction;

fuzz/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ keywords.workspace = true
1313
[dependencies]
1414
arbitrary = { version = "1.4.1", features = ["derive"] }
1515
ziggy = { version = "1.3.2", default-features = false }
16-
primitive-types = { version = "0.12", default-features = false, features = ["rlp"] }
1716
# evm
1817
evm = { workspace = true }
1918
# grammar

fuzz/src/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use std::collections::BTreeMap;
2222

2323
use evm::backend::{OverlayedChangeSet, RuntimeBaseBackend, RuntimeEnvironment};
24-
use primitive_types::{H160, H256, U256};
24+
use evm::uint::{H160, H256, U256};
2525

2626
#[derive(Default, Clone, Debug, PartialEq)]
2727
pub struct MockAccount {

fuzz/src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ mod grammar;
2626
use std::alloc::System;
2727

2828
use backend::MockBackend;
29+
#[allow(unused_imports)]
30+
use evm::uint::{H160, U256, U256Ext};
2931
use evm::{
3032
backend::{OverlayedBackend, RuntimeBaseBackend},
3133
interpreter::{
@@ -37,7 +39,6 @@ use evm::{
3739
TransactValue, TransactValueCallCreate,
3840
},
3941
};
40-
use primitive_types::{H160, U256};
4142
#[cfg(not(feature = "fuzzing"))]
4243
use stats_alloc::{INSTRUMENTED_SYSTEM, StatsAlloc};
4344

@@ -72,7 +73,7 @@ fn main() {
7273
backend::MockAccount {
7374
balance: init_balance,
7475
code: vec![],
75-
nonce: U256::one(),
76+
nonce: U256::ONE,
7677
storage: Default::default(),
7778
transient_storage: Default::default(),
7879
},
@@ -85,7 +86,7 @@ fn main() {
8586
salt: None,
8687
},
8788
caller: H160::from_low_u64_be(1),
88-
value: U256::zero(),
89+
value: U256::ZERO,
8990
gas_limit,
9091
gas_price: gas_price.into(),
9192
access_list: vec![],
@@ -117,7 +118,7 @@ fn main() {
117118
salt: None,
118119
},
119120
caller: H160::from_low_u64_be(1),
120-
value: U256::zero(),
121+
value: U256::ZERO,
121122
gas_limit,
122123
gas_price: gas_price.into(),
123124
access_list: vec![],
@@ -141,7 +142,7 @@ fn main() {
141142
data: calldata,
142143
},
143144
caller: user_address,
144-
value: U256::zero(),
145+
value: U256::ZERO,
145146
gas_limit,
146147
gas_price: gas_price.into(),
147148
access_list: vec![],
@@ -160,7 +161,7 @@ fn main() {
160161
});
161162
}
162163
fn assert_no_mint(backend: &MockBackend, initial_balance: U256) -> U256 {
163-
let mut total = U256::zero();
164+
let mut total = U256::ZERO;
164165
for (_k, v) in backend.state.iter() {
165166
total += v.balance;
166167
}

0 commit comments

Comments
 (0)