Skip to content

Commit

Permalink
chore: no_std to primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Feb 13, 2023
1 parent d5ebdb0 commit 60d6cb5
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ structure:
* revme: cli binary, used for running state test json
* revm-test: test binaries with contracts, used mostly to check performance

Last checked revm requires rust v1.65 or higher for `core::error::Error`

There were some big efforts on optimization of revm:
* Optimizing interpreter loop: https://github.com/bluealloy/revm/issues/7
* Introducing Bytecode format (and better bytecode analysis): https://github.com/bluealloy/revm/issues/121
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod jump_table;

use crate::{keccak256, B256, KECCAK_EMPTY};
use alloc::sync::Arc;
use alloc::{sync::Arc, vec, vec::Vec};
use bytes::Bytes;
pub use jump_table::{Analysis, AnalysisData, ValidJumpAddress};

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/bytecode/jump_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::sync::Arc;
use alloc::{sync::Arc, vec::Vec};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Analysis {
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub mod bits;
pub mod bytecode;
pub mod db;
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{bytes::Bytes, B160, B256};
use alloc::vec::Vec;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/precompile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::vec::Vec;

/// A precompile operation result.
pub type PrecompileResult = Result<(u64, Vec<u8>), PrecompileError>;

Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{Log, State, B160};
use alloc::vec::Vec;
use bytes::Bytes;
use ruint::aliases::U256;

Expand Down
3 changes: 2 additions & 1 deletion crates/primitives/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ pub fn create2_address(caller: B160, code_hash: B256, salt: U256) -> B160 {
/// Serde functions to serde as [bytes::Bytes] hex string
#[cfg(feature = "serde")]
pub mod serde_hex_bytes {
use alloc::string::String;
use serde::{Deserialize, Deserializer, Serializer};

pub fn serialize<S, T>(x: T, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<[u8]>,
{
s.serialize_str(&format!("0x{}", hex::encode(x.as_ref())))
s.serialize_str(&alloc::format!("0x{}", hex::encode(x.as_ref())))
}

pub fn deserialize<'de, D>(d: D) -> Result<bytes::Bytes, D::Error>
Expand Down
1 change: 1 addition & 0 deletions crates/revm/src/inspector/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::interpreter::{CallInputs, CreateInputs, Gas, InstructionResult};
use crate::primitives::{db::Database, Bytes, B160};
use crate::{evm_impl::EVMData, Inspector};

#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Default)]
pub struct GasInspector {
/// We now batch continual gas_block in one go, that means we need to reduce it if we want
Expand Down
5 changes: 1 addition & 4 deletions crates/revm/src/journaled_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::interpreter::{inner_models::SelfDestructResult, InstructionResult};
use crate::primitives::{
db::Database, hash_map::Entry, Account, Bytecode, HashMap, Log, StorageSlot, B160,
db::Database, hash_map::Entry, Account, Bytecode, HashMap, Log, State, StorageSlot, B160,
KECCAK_EMPTY, U256,
};
use alloc::{vec, vec::Vec};
Expand All @@ -26,9 +26,6 @@ pub struct JournaledState {
pub num_of_precompiles: usize,
}

pub type State = HashMap<B160, Account>;
pub type Storage = HashMap<U256, StorageSlot>;

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum JournalEntry {
Expand Down
2 changes: 0 additions & 2 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(dead_code)]
//#![no_std]
pub mod db;
mod evm;
mod evm_impl;
Expand Down

0 comments on commit 60d6cb5

Please sign in to comment.