Skip to content

Commit

Permalink
chore: enabled primtive default feature in precompile (bluealloy#409)
Browse files Browse the repository at this point in the history
* chore: enabled primtive default feature in precompile

* cleanup bitvec import

* fmt

---------

Co-authored-by: rakita <[email protected]>
  • Loading branch information
mattsse and rakita authored Mar 8, 2023
1 parent f2656b7 commit a193d79
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 81 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ readme = "../../README.md"

[dependencies]
revm-primitives = { path = "../primitives", version="1.0.0", default-features = false }
bitvec = { version = "1", default-features = false }

#utility
derive_more = "0.99"
Expand Down Expand Up @@ -46,11 +45,10 @@ optional_balance_check = ["revm-primitives/optional_balance_check"]
optional_block_gas_limit = ["revm-primitives/optional_block_gas_limit"]
optional_eip3607 = ["revm-primitives/optional_eip3607"]
optional_gas_refund = ["revm-primitives/optional_gas_refund"]
std = ["revm-primitives/std", "bitvec/std"]
std = ["revm-primitives/std"]
serde = [
"dep:serde",
"revm-primitives/serde",
"bitvec/serde",
]
arbitrary = [
"dep:arbitrary",
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions/i256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Sign {
Zero,
}

pub const SIGN_BIT_MASK: U256 = U256::from_limbs([
pub const _SIGN_BIT_MASK: U256 = U256::from_limbs([
0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,
Expand Down
11 changes: 7 additions & 4 deletions crates/interpreter/src/interpreter/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::opcode;
use crate::primitives::{Bytecode, BytecodeState, Bytes, B256};
use alloc::sync::Arc;
use bitvec::order::Lsb0;
use bitvec::prelude::bitvec;
use bitvec::vec::BitVec;
use revm_primitives::JumpMap;
// use bitvec::order::Lsb0;
// use bitvec::prelude::bitvec;
// use bitvec::vec::BitVec;
use revm_primitives::{
bitvec::prelude::{bitvec, BitVec, Lsb0},
JumpMap,
};

/// Perform bytecode analysis.
///
Expand Down
69 changes: 0 additions & 69 deletions crates/interpreter/src/interpreter/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,6 @@ pub struct Contract {
pub value: U256,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Analysis {
JumpDest,
GasBlockEnd, //contains gas for next block
None,
}

const JUMP_MASK: u32 = 0x80000000;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnalysisData {
/// This variable packs two informations:
/// IS_JUMP (1bit) | gas block ( 31bits)
is_jump_and_gas_block: u32,
}

impl AnalysisData {
pub fn none() -> Self {
AnalysisData {
is_jump_and_gas_block: 0,
}
}

pub fn set_is_jump(&mut self) {
self.is_jump_and_gas_block |= JUMP_MASK;
}

pub fn set_gas_block(&mut self, gas_block: u32) {
let jump = self.is_jump_and_gas_block & JUMP_MASK;
self.is_jump_and_gas_block = gas_block | jump;
}

pub fn is_jump(&self) -> bool {
self.is_jump_and_gas_block & JUMP_MASK == JUMP_MASK
}

pub fn gas_block(&self) -> u64 {
(self.is_jump_and_gas_block & (!JUMP_MASK)) as u64
}
}

impl Contract {
pub fn new(input: Bytes, bytecode: Bytecode, address: B160, caller: B160, value: U256) -> Self {
let bytecode = to_analysed(bytecode).try_into().expect("it is analyzed");
Expand Down Expand Up @@ -102,30 +60,3 @@ impl Contract {
)
}
}
#[cfg(test)]
mod tests {
use super::AnalysisData;

#[test]
pub fn test_jump_set() {
let mut jump = AnalysisData::none();
assert!(!jump.is_jump());
assert_eq!(jump.gas_block(), 0);

jump.set_gas_block(2350);
assert!(!jump.is_jump());
assert_eq!(jump.gas_block(), 2350);

jump.set_is_jump();
assert!(jump.is_jump());
assert_eq!(jump.gas_block(), 2350);

jump.set_gas_block(10);
assert!(jump.is_jump());
assert_eq!(jump.gas_block(), 10);

jump.set_gas_block(350);
assert!(jump.is_jump());
assert_eq!(jump.gas_block(), 350);
}
}
3 changes: 1 addition & 2 deletions crates/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![allow(dead_code)]
//#![no_std]
#![cfg_attr(not(feature = "std"), no_std)]

pub mod gas;
mod host;
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ primitive-types = { version = "0.12", default-features = false }
rlp = { version = "0.5", default-features = false } # used for create2 address calculation
ruint = { version = "1.7.0", features = ["primitive-types", "rlp"] }
auto_impl = "1.0"
bitvec = { version = "1", default-features = false }
bitvec = { version = "1", default-features = false, features = ["alloc"] }

# bits B256 B160 crate
fixed-hash = { version = "0.8", default-features = false, features = [
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod bits;
pub mod bytecode;
pub mod db;
Expand All @@ -23,6 +24,7 @@ pub type Address = B160;
/// Hash, in Ethereum usually kecack256.
pub type Hash = B256;

pub use bitvec;
pub use bytecode::*;
pub use env::*;
pub use hashbrown::{hash_map, HashMap};
Expand Down
2 changes: 2 additions & 0 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod db;
mod evm;
mod evm_impl;
Expand Down

0 comments on commit a193d79

Please sign in to comment.