From 1a3e8fdb3b0ea579a0c17584b3589f34cf2bb316 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 5 Dec 2015 17:32:36 +0100 Subject: [PATCH 1/3] ethcore compiling with latest util --- src/lib.rs | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index df2e7c528..9c3fa2626 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,25 +5,25 @@ use ethcore_util::hash::*; use ethcore_util::uint::*; pub type Bytes = Vec; -pub type LogBloom = Hash4096; +pub type LogBloom = H2048; pub static ZERO_ADDRESS: Address = Address([0x00; 20]); -pub static ZERO_HASH256: Hash256 = Hash256([0x00; 32]); -pub static ZERO_LOGBLOOM: LogBloom = Hash4096([0x00; 512]); +pub static ZERO_H256: H256 = H256([0x00; 32]); +pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]); #[derive(Debug)] pub struct Header { - parent_hash: Hash256, + parent_hash: H256, timestamp: U256, number: U256, author: Address, - transactions_root: Hash256, - uncles_hash: Hash256, - extra_data_hash: Hash256, + transactions_root: H256, + uncles_hash: H256, + extra_data_hash: H256, - state_root: Hash256, - receipts_root: Hash256, + state_root: H256, + receipts_root: H256, log_bloom: LogBloom, gas_used: U256, gas_limit: U256, @@ -35,22 +35,22 @@ pub struct Header { impl Header { pub fn new() -> Header { Header { - parent_hash: ZERO_HASH256, - timestamp: BAD_U256, - number: ZERO_U256, - author: ZERO_ADDRESS, + parent_hash: ZERO_H256.clone(), + timestamp: BAD_U256.clone(), + number: ZERO_U256.clone(), + author: ZERO_ADDRESS.clone(), - transactions_root: ZERO_HASH256, - uncles_hash: ZERO_HASH256, - extra_data_hash: ZERO_HASH256, + transactions_root: ZERO_H256.clone(), + uncles_hash: ZERO_H256.clone(), + extra_data_hash: ZERO_H256.clone(), - state_root: ZERO_HASH256, - receipts_root: ZERO_HASH256, - log_bloom: ZERO_LOGBLOOM, - gas_used: ZERO_U256, - gas_limit: ZERO_U256, + state_root: ZERO_H256.clone(), + receipts_root: ZERO_H256.clone(), + log_bloom: ZERO_LOGBLOOM.clone(), + gas_used: ZERO_U256.clone(), + gas_limit: ZERO_U256.clone(), - difficulty: ZERO_U256, + difficulty: ZERO_U256.clone(), seal: vec![], } } From 02c8ee3c913a3e10d296ce2e2f8a430460d5e697 Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 5 Dec 2015 19:21:07 +0100 Subject: [PATCH 2/3] evmjit as sublibrary --- Cargo.toml | 4 ++ rust-evmjit/.gitignore | 3 ++ rust-evmjit/Cargo.toml | 7 ++++ rust-evmjit/src/lib.rs | 95 ++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 6 ++- 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 rust-evmjit/.gitignore create mode 100644 rust-evmjit/Cargo.toml create mode 100644 rust-evmjit/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index ba558dc96..b0cae8dce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,7 @@ authors = ["Ethcore "] log = "0.3" env_logger = "0.3" ethcore-util = "0.1.0" +evmjit = { path = "rust-evmjit", optional = true } + +[features] +jit = ["evmjit"] diff --git a/rust-evmjit/.gitignore b/rust-evmjit/.gitignore new file mode 100644 index 000000000..d4f917d3d --- /dev/null +++ b/rust-evmjit/.gitignore @@ -0,0 +1,3 @@ +target +Cargo.lock +*.swp diff --git a/rust-evmjit/Cargo.toml b/rust-evmjit/Cargo.toml new file mode 100644 index 000000000..54c4437f4 --- /dev/null +++ b/rust-evmjit/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "evmjit" +version = "0.1.0" +authors = ["debris "] + +[dependencies] +libc = "0.2.2" diff --git a/rust-evmjit/src/lib.rs b/rust-evmjit/src/lib.rs new file mode 100644 index 000000000..85d8317ba --- /dev/null +++ b/rust-evmjit/src/lib.rs @@ -0,0 +1,95 @@ +//! Bare rust wrapper around evmjit +//! +//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit + +extern crate libc; +use std::ptr; + +#[repr(C)] +pub struct JitI256 { + pub words: [u64; 4] +} + +impl JitI256 { + pub fn new() -> JitI256 { + JitI256 { + words: [0; 4] + } + } +} + +#[repr(C)] +pub struct JitRuntimeData { + pub gas: i64, + pub gas_price: i64, + pub call_data: *const libc::c_char, + pub call_data_size: u64, + pub address: JitI256, + pub caller: JitI256, + pub origin: JitI256, + pub call_value: JitI256, + pub coinbase: JitI256, + pub difficulty: JitI256, + pub gas_limit: JitI256, + pub number: u64, + pub timestamp: i64, + pub code: *const libc::c_char, + pub code_size: u64, + pub code_hash: JitI256 +} + +impl JitRuntimeData { + pub fn new() -> JitRuntimeData { + JitRuntimeData { + gas: 0, + gas_price: 0, + call_data: ptr::null(), + call_data_size: 0, + address: JitI256::new(), + caller: JitI256::new(), + origin: JitI256::new(), + call_value: JitI256::new(), + coinbase: JitI256::new(), + difficulty: JitI256::new(), + gas_limit: JitI256::new(), + number: 0, + timestamp: 0, + code: ptr::null(), + code_size: 0, + code_hash: JitI256::new() + } + } +} + +#[repr(C)] +#[derive(Debug)] +pub enum JitReturnCode { + Stop = 0, + Return = 1, + Suicide = 2, + + OutOfGas = -1, + + LLVMError = -101, + UnexpectedError = -111 +} + +#[derive(Copy, Clone)] +pub enum JitContext {} + +#[link(name="evmjit")] +extern "C" { + pub fn evmjit_create(data: JitRuntimeData, env: u8) -> JitContext; + pub fn evmjit_exec(context: JitContext) -> JitReturnCode; + pub fn evmjit_destroy(context: JitContext); +} + +#[test] +fn it_works() { + unsafe { + let context = evmjit_create(JitRuntimeData::new(), 0); + let _result = evmjit_exec(context); + evmjit_destroy(context); + } +} + diff --git a/src/lib.rs b/src/lib.rs index 9c3fa2626..7755afe76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,10 @@ -#[macro_use] extern crate log; +#[macro_use] +extern crate log; extern crate ethcore_util; +#[cfg(feature = "jit" )] +extern crate evmjit; + use ethcore_util::hash::*; use ethcore_util::uint::*; From d516fca1653a2242b8b51b4adb4455c159c119ed Mon Sep 17 00:00:00 2001 From: debris Date: Sat, 5 Dec 2015 19:44:43 +0100 Subject: [PATCH 3/3] added installation guide --- src/lib.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7755afe76..d51f17bef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,74 @@ +//! Ethcore's ethereum implementation +//! +//! ### Rust version +//! - beta +//! - nightly +//! +//! ### Supported platforms: +//! - OSX +//! - Linux/Ubuntu +//! +//! ### Dependencies: +//! - RocksDB 3.13 +//! - LLVM 3.7 (optional, required for `jit`) +//! - evmjit (optional, required for `jit`) +//! +//! ### Dependencies Installation +//! +//! - OSX +//! +//! - rocksdb +//! ``` +//! brew install rocksdb +//! ``` +//! +//! - llvm +//! +//! - download llvm 3.7 from http://llvm.org/apt/ +//! +//! ``` +//! cd llvm-3.7.0.src +//! mkdir build && cd $_ +//! cmake -G "Unix Makefiles" .. -DCMAKE_C_FLAGS_RELEASE= -DCMAKE_CXX_FLAGS_RELEASE= -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/llvm/3.7 -DCMAKE_BUILD_TYPE=Release +//! make && make install +//! ``` +//! - evmjit +//! +//! - download from https://github.com/debris/evmjit +//! +//! ``` +//! cd evmjit +//! mkdir build && cd $_ +//! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake .. +//! make && make install +//! ``` +//! +//! - Linux/Ubuntu +//! +//! - rocksdb +//! +//! ``` +//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz +//! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib +//! sudo make install +//! ``` +//! +//! - llvm +//! +//! - install using packages from http://llvm.org/apt/ +//! +//! - evmjit +//! +//! - download from https://github.com/debris/evmjit +//! +//! ``` +//! cd evmjit +//! mkdir build && cd $_ +//! cmake .. && make +//! sudo make install +//! sudo ldconfig +//! ``` + #[macro_use] extern crate log; extern crate ethcore_util;