Skip to content

Commit 5e6546e

Browse files
authored
fix: cast overflow in 32-bits OS (#978)
* fix: cast overflow in 32-bits OS * Fix type conversion issues in bitwise.rs, host.rs, host_env.rs, macros.rs, and system.rs * Fix error in as_usize_or_fail macro * Update CI configuration and add Cross.toml * Fix command arguments in ethereum-tests.yml * Update Ethereum tests workflow * Update Cross.toml with pre-build commands for i686 target
1 parent 9d42562 commit 5e6546e

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- run: |
5252
cd crates/revm
5353
cargo check --no-default-features
54-
54+
5555
check-serde:
5656
name: check serde
5757
runs-on: ubuntu-latest

.github/workflows/ethereum-tests.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
pull_request:
1111
branches: [main, "release/**"]
1212

13-
1413
jobs:
1514
tests-stable:
1615
name: Ethereum Tests (Stable)
@@ -19,6 +18,7 @@ jobs:
1918
strategy:
2019
matrix:
2120
profile: [ethtests, release]
21+
target: [i686-unknown-linux-gnu, x86_64-unknown-linux-gnu]
2222
steps:
2323
- name: Checkout sources
2424
uses: actions/checkout@v3
@@ -37,11 +37,13 @@ jobs:
3737
with:
3838
cache-on-failure: true
3939

40+
- name: Install cross
41+
run: cargo install cross
42+
4043
- name: Run Ethereum tests
4144
run: |
42-
cargo run --profile ${{ matrix.profile }} -p revme -- statetest \
45+
cross run --target ${{matrix.target}} --profile ${{ matrix.profile }} -p revme -- statetest \
4346
ethtests/GeneralStateTests/ \
4447
ethtests/LegacyTests/Constantinople/GeneralStateTests/ \
4548
ethtests/EIPTests/StateTests/stEIP1153-transientStorage/ \
4649
ethtests/EIPTests/StateTests/stEIP4844-blobtransactions/ \
47-
ethtests/EIPTests/StateTests/stEIP5656-MCOPY/

Cross.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[build]
2+
pre-build = [
3+
"apt-get update && apt-get install --assume-yes --no-install-recommends llvm-dev clang libclang-dev",
4+
]
5+
6+
[target.i686-unknown-linux-gnu]
7+
image = "ghcr.io/cross-rs/i686-unknown-linux-gnu:main"
8+
9+
[target.x86_64-unknown-linux-gnu]
10+
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"

crates/interpreter/src/instructions/macros.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ macro_rules! as_u64_saturated {
190190

191191
macro_rules! as_usize_saturated {
192192
($v:expr) => {
193-
as_u64_saturated!($v) as usize
193+
::core::convert::TryInto::<usize>::try_into(as_u64_saturated!($v)).unwrap_or(usize::MAX)
194194
};
195195
}
196196

@@ -205,6 +205,10 @@ macro_rules! as_usize_or_fail {
205205
$interp.instruction_result = $reason;
206206
return;
207207
}
208-
x[0] as usize
208+
let Ok(val) = ::core::convert::TryInto::<usize>::try_into(x[0]) else {
209+
$interp.instruction_result = $reason;
210+
return;
211+
};
212+
val
209213
}};
210214
}

0 commit comments

Comments
 (0)