From 281cbd91193867a35628ffb30b60088437943f3f Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 14 Jun 2024 08:15:47 +0200 Subject: [PATCH 1/3] chore: use const blocks --- .../interpreter/src/instructions/contract.rs | 4 +-- crates/interpreter/src/instructions/macros.rs | 6 +++-- crates/interpreter/src/interpreter.rs | 12 ++++----- crates/interpreter/src/opcode/tables.rs | 25 ++++++------------- crates/revm/src/db/states/cache.rs | 6 ++--- crates/revm/src/handler/mainnet/execution.rs | 1 - 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/crates/interpreter/src/instructions/contract.rs b/crates/interpreter/src/instructions/contract.rs index f57a786962..54079e690d 100644 --- a/crates/interpreter/src/instructions/contract.rs +++ b/crates/interpreter/src/instructions/contract.rs @@ -192,7 +192,7 @@ pub fn extcall(interpreter: &mut Interpreter, host require_eof!(interpreter); pop_address!(interpreter, target_address); - // TODO check if target is left paddded with zeroes. + // TODO check if target is left padded with zeroes. // input call let Some(input) = extcall_input(interpreter) else { @@ -264,7 +264,7 @@ pub fn extstaticcall(interpreter: &mut Interpreter, host: &mut require_eof!(interpreter); pop_address!(interpreter, target_address); - // TODO check if target is left paddded with zeroes. + // TODO check if target is left padded with zeroes. // input call let Some(input) = extcall_input(interpreter) else { diff --git a/crates/interpreter/src/instructions/macros.rs b/crates/interpreter/src/instructions/macros.rs index 6938eeada4..4df6f62d1a 100644 --- a/crates/interpreter/src/instructions/macros.rs +++ b/crates/interpreter/src/instructions/macros.rs @@ -37,8 +37,10 @@ macro_rules! require_init_eof { #[macro_export] macro_rules! check { ($interp:expr, $min:ident) => { - // TODO: Force const-eval on the condition with a `const {}` block once they are stable - if !::enabled($crate::primitives::SpecId::$min) { + if const { + !::SPEC_ID + .is_enabled_in($crate::primitives::SpecId::$min) + } { $interp.instruction_result = $crate::InstructionResult::NotActivated; return; } diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index d74f7d08bc..b8004938bd 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -467,13 +467,13 @@ mod tests { let mut interp = Interpreter::new(Contract::default(), u64::MAX, false); let mut host = crate::DummyHost::default(); - let table: InstructionTable = - crate::opcode::make_instruction_table::(); - let _ = interp.run(EMPTY_SHARED_MEMORY, &table, &mut host); + let table: &InstructionTable = + &crate::opcode::make_instruction_table::(); + let _ = interp.run(EMPTY_SHARED_MEMORY, table, &mut host); let host: &mut dyn Host = &mut host as &mut dyn Host; - let table: InstructionTable = - crate::opcode::make_instruction_table::(); - let _ = interp.run(EMPTY_SHARED_MEMORY, &table, host); + let table: &InstructionTable = + &crate::opcode::make_instruction_table::(); + let _ = interp.run(EMPTY_SHARED_MEMORY, table, host); } } diff --git a/crates/interpreter/src/opcode/tables.rs b/crates/interpreter/src/opcode/tables.rs index 48a1b6cca8..a2a66bc218 100644 --- a/crates/interpreter/src/opcode/tables.rs +++ b/crates/interpreter/src/opcode/tables.rs @@ -133,24 +133,15 @@ impl<'a, H: Host + ?Sized + 'a> InstructionTables<'a, H> { /// Make instruction table. #[inline] pub const fn make_instruction_table() -> InstructionTable { - // Force const-eval of the table creation, making this function trivial. - // TODO: Replace this with a `const {}` block once it is stable. - struct ConstTable { - _host: core::marker::PhantomData, - _spec: core::marker::PhantomData, - } - impl ConstTable { - const NEW: InstructionTable = { - let mut tables: InstructionTable = [control::unknown; 256]; - let mut i = 0; - while i < 256 { - tables[i] = instruction::(i as u8); - i += 1; - } - tables - }; + const { + let mut tables: InstructionTable = [control::unknown; 256]; + let mut i = 0; + while i < 256 { + tables[i] = instruction::(i as u8); + i += 1; + } + tables } - ConstTable::::NEW } /// Make boxed instruction table that calls `f` closure for every instruction. diff --git a/crates/revm/src/db/states/cache.rs b/crates/revm/src/db/states/cache.rs index 63c0160bab..5dd6770d49 100644 --- a/crates/revm/src/db/states/cache.rs +++ b/crates/revm/src/db/states/cache.rs @@ -14,10 +14,10 @@ use std::vec::Vec; /// It generates transitions that is used to build BundleState. #[derive(Clone, Debug, PartialEq, Eq)] pub struct CacheState { - /// Block state account with account state + /// Block state account with account state. pub accounts: HashMap, - /// created contracts - /// TODO add bytecode counter for number of bytecodes added/removed. + /// Created contracts. + // TODO add bytecode counter for number of bytecodes added/removed. pub contracts: HashMap, /// Has EIP-161 state clear enabled (Spurious Dragon hardfork). pub has_state_clear: bool, diff --git a/crates/revm/src/handler/mainnet/execution.rs b/crates/revm/src/handler/mainnet/execution.rs index 4ee557f81b..df8fb3d419 100644 --- a/crates/revm/src/handler/mainnet/execution.rs +++ b/crates/revm/src/handler/mainnet/execution.rs @@ -231,7 +231,6 @@ mod tests { assert_eq!(gas.refunded(), 0); } - // TODO #[test] fn test_consume_gas_with_refund() { let mut return_gas = Gas::new(90); From 1f1884775497ffe5570abb3b86b4ae2d46379f59 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 14 Jun 2024 08:19:46 +0200 Subject: [PATCH 2/3] ci --- .github/workflows/ci.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbea7ba5c4..9ef73e2141 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,8 +31,8 @@ jobs: - uses: Swatinem/rust-cache@v2 - run: cargo test --workspace ${{ matrix.flags }} - test-no-std: - name: test no_std + check-no-std: + name: check no_std runs-on: ubuntu-latest timeout-minutes: 30 steps: @@ -48,9 +48,8 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@v4 - - run: | - cd crates/revm - cargo check --no-default-features + - uses: dtolnay/rust-toolchain@stable + - run: cargo check --no-default-features -p revm check-serde: name: check serde @@ -58,9 +57,8 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@v4 - - run: | - cd crates/revm - cargo check --no-default-features --features serde + - uses: dtolnay/rust-toolchain@stable + - run: cargo check --no-default-features --features serde -p revm check-std: name: check std @@ -68,9 +66,8 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@v4 - - run: | - cd crates/revm - cargo check --no-default-features --features std + - uses: dtolnay/rust-toolchain@stable + - run: cargo check --no-default-features --features std -p revm clippy: name: clippy From 94e7dbecce56595b6e04373d06c7b99e52213915 Mon Sep 17 00:00:00 2001 From: rakita Date: Fri, 21 Jun 2024 11:47:43 +0200 Subject: [PATCH 3/3] rm new line from last commit merge --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e481be4d59..5b51370b02 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,6 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: targets: riscv32imac-unknown-none-elf - - run: cargo check --target riscv32imac-unknown-none-elf --no-default-features --features=${{ matrix.features }} check: