From 5e6546e2a57bbc7661469fa606ea3c6569fe1838 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 16 Jan 2024 20:15:22 +0800 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 2 +- .github/workflows/ethereum-tests.yml | 8 +++++--- Cross.toml | 10 ++++++++++ crates/interpreter/src/instructions/macros.rs | 8 ++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 Cross.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af2b3a4127..c4d7e3ddde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - run: | cd crates/revm cargo check --no-default-features - + check-serde: name: check serde runs-on: ubuntu-latest diff --git a/.github/workflows/ethereum-tests.yml b/.github/workflows/ethereum-tests.yml index 032a632346..328cff78e1 100644 --- a/.github/workflows/ethereum-tests.yml +++ b/.github/workflows/ethereum-tests.yml @@ -10,7 +10,6 @@ on: pull_request: branches: [main, "release/**"] - jobs: tests-stable: name: Ethereum Tests (Stable) @@ -19,6 +18,7 @@ jobs: strategy: matrix: profile: [ethtests, release] + target: [i686-unknown-linux-gnu, x86_64-unknown-linux-gnu] steps: - name: Checkout sources uses: actions/checkout@v3 @@ -37,11 +37,13 @@ jobs: with: cache-on-failure: true + - name: Install cross + run: cargo install cross + - name: Run Ethereum tests run: | - cargo run --profile ${{ matrix.profile }} -p revme -- statetest \ + cross run --target ${{matrix.target}} --profile ${{ matrix.profile }} -p revme -- statetest \ ethtests/GeneralStateTests/ \ ethtests/LegacyTests/Constantinople/GeneralStateTests/ \ ethtests/EIPTests/StateTests/stEIP1153-transientStorage/ \ ethtests/EIPTests/StateTests/stEIP4844-blobtransactions/ \ - ethtests/EIPTests/StateTests/stEIP5656-MCOPY/ diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000000..d25de22494 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,10 @@ +[build] +pre-build = [ + "apt-get update && apt-get install --assume-yes --no-install-recommends llvm-dev clang libclang-dev", +] + +[target.i686-unknown-linux-gnu] +image = "ghcr.io/cross-rs/i686-unknown-linux-gnu:main" + +[target.x86_64-unknown-linux-gnu] +image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main" diff --git a/crates/interpreter/src/instructions/macros.rs b/crates/interpreter/src/instructions/macros.rs index 7c4c222555..92189707bf 100644 --- a/crates/interpreter/src/instructions/macros.rs +++ b/crates/interpreter/src/instructions/macros.rs @@ -190,7 +190,7 @@ macro_rules! as_u64_saturated { macro_rules! as_usize_saturated { ($v:expr) => { - as_u64_saturated!($v) as usize + ::core::convert::TryInto::::try_into(as_u64_saturated!($v)).unwrap_or(usize::MAX) }; } @@ -205,6 +205,10 @@ macro_rules! as_usize_or_fail { $interp.instruction_result = $reason; return; } - x[0] as usize + let Ok(val) = ::core::convert::TryInto::::try_into(x[0]) else { + $interp.instruction_result = $reason; + return; + }; + val }}; }