Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no_std to primitives #366

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 63 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

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
10 changes: 5 additions & 5 deletions crates/interpreter/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ pub fn eval<H: Host, S: Spec>(opcode: u8, interp: &mut Interpreter, host: &mut H
opcode::SLOAD => host::sload::<S>(interp, host),
opcode::SSTORE => host::sstore::<S>(interp, host),
opcode::GAS => system::gas(interp, host),
opcode::LOG0 => host::log::<0, S>(interp, host),
opcode::LOG1 => host::log::<1, S>(interp, host),
opcode::LOG2 => host::log::<2, S>(interp, host),
opcode::LOG3 => host::log::<3, S>(interp, host),
opcode::LOG4 => host::log::<4, S>(interp, host),
opcode::LOG0 => host::log::<0>(interp, host),
opcode::LOG1 => host::log::<1>(interp, host),
opcode::LOG2 => host::log::<2>(interp, host),
opcode::LOG3 => host::log::<3>(interp, host),
opcode::LOG4 => host::log::<4>(interp, host),
opcode::SELFDESTRUCT => host::selfdestruct::<S>(interp, host),
opcode::CREATE => host::create::<false, S>(interp, host), //check
opcode::CREATE2 => host::create::<true, S>(interp, host), //check
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn sstore<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Host) {
}
}

pub fn log<const N: u8, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Host) {
pub fn log<const N: u8>(interpreter: &mut Interpreter, host: &mut dyn Host) {
check_staticcall!(interpreter);

pop!(interpreter, offset, len);
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