Skip to content

Commit

Permalink
chore: use const blocks (bluealloy#1522)
Browse files Browse the repository at this point in the history
* chore: use const blocks

* ci

* rm new line from last commit merge
  • Loading branch information
DaniPopes authored Jun 22, 2024
1 parent 150af37 commit a51d53b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo test --workspace ${{ matrix.flags }}

test-no-std:
name: test no_std ${{ matrix.features }}
check-no-std:
name: check no_std ${{ matrix.features }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
Expand All @@ -56,9 +56,8 @@ jobs:
features: ["", "serde", "std"]
steps:
- uses: actions/checkout@v4
- run: |
cd crates/revm
cargo check --no-default-features --features=${{ matrix.features }}
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --no-default-features -p revm --features=${{ matrix.features }}

clippy:
name: clippy
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/instructions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn extcall<H: Host + ?Sized, SPEC: Spec>(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 {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub fn extstaticcall<H: Host + ?Sized>(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 {
Expand Down
6 changes: 4 additions & 2 deletions crates/interpreter/src/instructions/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 !<SPEC as $crate::primitives::Spec>::enabled($crate::primitives::SpecId::$min) {
if const {
!<SPEC as $crate::primitives::Spec>::SPEC_ID
.is_enabled_in($crate::primitives::SpecId::$min)
} {
$interp.instruction_result = $crate::InstructionResult::NotActivated;
return;
}
Expand Down
12 changes: 6 additions & 6 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,13 @@ mod tests {
let mut interp = Interpreter::new(Contract::default(), u64::MAX, false);

let mut host = crate::DummyHost::default();
let table: InstructionTable<DummyHost> =
crate::opcode::make_instruction_table::<DummyHost, CancunSpec>();
let _ = interp.run(EMPTY_SHARED_MEMORY, &table, &mut host);
let table: &InstructionTable<DummyHost> =
&crate::opcode::make_instruction_table::<DummyHost, CancunSpec>();
let _ = interp.run(EMPTY_SHARED_MEMORY, table, &mut host);

let host: &mut dyn Host = &mut host as &mut dyn Host;
let table: InstructionTable<dyn Host> =
crate::opcode::make_instruction_table::<dyn Host, CancunSpec>();
let _ = interp.run(EMPTY_SHARED_MEMORY, &table, host);
let table: &InstructionTable<dyn Host> =
&crate::opcode::make_instruction_table::<dyn Host, CancunSpec>();
let _ = interp.run(EMPTY_SHARED_MEMORY, table, host);
}
}
25 changes: 8 additions & 17 deletions crates/interpreter/src/opcode/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,15 @@ impl<'a, H: Host + ?Sized + 'a> InstructionTables<'a, H> {
/// Make instruction table.
#[inline]
pub const fn make_instruction_table<H: Host + ?Sized, SPEC: Spec>() -> InstructionTable<H> {
// Force const-eval of the table creation, making this function trivial.
// TODO: Replace this with a `const {}` block once it is stable.
struct ConstTable<H: Host + ?Sized, SPEC: Spec> {
_host: core::marker::PhantomData<H>,
_spec: core::marker::PhantomData<SPEC>,
}
impl<H: Host + ?Sized, SPEC: Spec> ConstTable<H, SPEC> {
const NEW: InstructionTable<H> = {
let mut tables: InstructionTable<H> = [control::unknown; 256];
let mut i = 0;
while i < 256 {
tables[i] = instruction::<H, SPEC>(i as u8);
i += 1;
}
tables
};
const {
let mut tables: InstructionTable<H> = [control::unknown; 256];
let mut i = 0;
while i < 256 {
tables[i] = instruction::<H, SPEC>(i as u8);
i += 1;
}
tables
}
ConstTable::<H, SPEC>::NEW
}

/// Make boxed instruction table that calls `f` closure for every instruction.
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/src/db/states/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address, CacheAccount>,
/// 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<B256, Bytecode>,
/// Has EIP-161 state clear enabled (Spurious Dragon hardfork).
pub has_state_clear: bool,
Expand Down
1 change: 0 additions & 1 deletion crates/revm/src/handler/mainnet/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a51d53b

Please sign in to comment.