Merge branch 'master' of github.com:gavofyork/ethcore
This commit is contained in:
		
						commit
						12f6534fa5
					
				@ -10,3 +10,7 @@ authors = ["Ethcore <admin@ethcore.io>"]
 | 
				
			|||||||
log = "0.3"
 | 
					log = "0.3"
 | 
				
			||||||
env_logger = "0.3"
 | 
					env_logger = "0.3"
 | 
				
			||||||
ethcore-util = "0.1.0"
 | 
					ethcore-util = "0.1.0"
 | 
				
			||||||
 | 
					evmjit = { path = "rust-evmjit", optional = true }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[features]
 | 
				
			||||||
 | 
					jit = ["evmjit"]
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								rust-evmjit/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								rust-evmjit/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					target
 | 
				
			||||||
 | 
					Cargo.lock
 | 
				
			||||||
 | 
					*.swp
 | 
				
			||||||
							
								
								
									
										7
									
								
								rust-evmjit/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								rust-evmjit/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "evmjit"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					authors = ["debris <marek.kotewicz@gmail.com>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					libc = "0.2.2"
 | 
				
			||||||
							
								
								
									
										95
									
								
								rust-evmjit/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								rust-evmjit/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@ -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);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										145
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										145
									
								
								src/lib.rs
									
									
									
									
									
								
							@ -1,28 +1,107 @@
 | 
				
			|||||||
#[macro_use] extern crate log;
 | 
					//! Ethcore's ethereum implementation
 | 
				
			||||||
extern crate ethcore_util;
 | 
					//! 
 | 
				
			||||||
 | 
					//! ### 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 env_logger;
 | 
				
			||||||
 | 
					extern crate ethcore_util;
 | 
				
			||||||
 | 
					#[cfg(feature = "jit" )]
 | 
				
			||||||
 | 
					extern crate evmjit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//use ethcore_util::error::*;
 | 
				
			||||||
use ethcore_util::hash::*;
 | 
					use ethcore_util::hash::*;
 | 
				
			||||||
use ethcore_util::uint::*;
 | 
					use ethcore_util::uint::*;
 | 
				
			||||||
 | 
					use ethcore_util::bytes::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub type LogBloom = Hash4096;
 | 
					pub type LogBloom = H2048;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub mod state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
 | 
					pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
 | 
				
			||||||
pub static ZERO_HASH256: Hash256 = Hash256([0x00; 32]);
 | 
					pub static ZERO_H256: H256 = H256([0x00; 32]);
 | 
				
			||||||
pub static ZERO_LOGBLOOM: LogBloom = Hash4096([0x00; 512]);
 | 
					pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug)]
 | 
					#[derive(Debug)]
 | 
				
			||||||
pub struct Header {
 | 
					pub struct Header {
 | 
				
			||||||
	parent_hash: Hash256,
 | 
						parent_hash: H256,
 | 
				
			||||||
	timestamp: U256,
 | 
						timestamp: U256,
 | 
				
			||||||
	number: U256,
 | 
						number: U256,
 | 
				
			||||||
	author: Address,
 | 
						author: Address,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	transactions_root: Hash256,
 | 
						transactions_root: H256,
 | 
				
			||||||
	uncles_hash: Hash256,
 | 
						uncles_hash: H256,
 | 
				
			||||||
	extra_data_hash: Hash256,
 | 
						extra_data_hash: H256,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	state_root: Hash256,
 | 
						state_root: H256,
 | 
				
			||||||
	receipts_root: Hash256,
 | 
						receipts_root: H256,
 | 
				
			||||||
	log_bloom: LogBloom,
 | 
						log_bloom: LogBloom,
 | 
				
			||||||
	gas_used: U256,
 | 
						gas_used: U256,
 | 
				
			||||||
	gas_limit: U256,
 | 
						gas_limit: U256,
 | 
				
			||||||
@ -34,22 +113,22 @@ pub struct Header {
 | 
				
			|||||||
impl Header {
 | 
					impl Header {
 | 
				
			||||||
	pub fn new() -> Header {
 | 
						pub fn new() -> Header {
 | 
				
			||||||
		Header {
 | 
							Header {
 | 
				
			||||||
			parent_hash: ZERO_HASH256,
 | 
								parent_hash: ZERO_H256.clone(),
 | 
				
			||||||
			timestamp: BAD_U256,
 | 
								timestamp: BAD_U256.clone(),
 | 
				
			||||||
			number: ZERO_U256,
 | 
								number: ZERO_U256.clone(),
 | 
				
			||||||
			author: ZERO_ADDRESS,
 | 
								author: ZERO_ADDRESS.clone(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			transactions_root: ZERO_HASH256,
 | 
								transactions_root: ZERO_H256.clone(),
 | 
				
			||||||
			uncles_hash: ZERO_HASH256,
 | 
								uncles_hash: ZERO_H256.clone(),
 | 
				
			||||||
			extra_data_hash: ZERO_HASH256,
 | 
								extra_data_hash: ZERO_H256.clone(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			state_root: ZERO_HASH256,
 | 
								state_root: ZERO_H256.clone(),
 | 
				
			||||||
			receipts_root: ZERO_HASH256,
 | 
								receipts_root: ZERO_H256.clone(),
 | 
				
			||||||
			log_bloom: ZERO_LOGBLOOM,
 | 
								log_bloom: ZERO_LOGBLOOM.clone(),
 | 
				
			||||||
			gas_used: ZERO_U256,
 | 
								gas_used: ZERO_U256.clone(),
 | 
				
			||||||
			gas_limit: ZERO_U256,
 | 
								gas_limit: ZERO_U256.clone(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			difficulty: ZERO_U256,
 | 
								difficulty: ZERO_U256.clone(),
 | 
				
			||||||
			seal: vec![],
 | 
								seal: vec![],
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -61,21 +140,3 @@ pub struct Transaction {
 | 
				
			|||||||
	pub data: Bytes,
 | 
						pub data: Bytes,
 | 
				
			||||||
	pub code: Bytes,
 | 
						pub code: Bytes,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
#[test]
 | 
					 | 
				
			||||||
fn memorydb() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// Silly function to return 69.
 | 
					 | 
				
			||||||
///
 | 
					 | 
				
			||||||
/// # Example
 | 
					 | 
				
			||||||
///
 | 
					 | 
				
			||||||
/// ```
 | 
					 | 
				
			||||||
/// assert_eq!(ethcore::sixtynine(), 69);
 | 
					 | 
				
			||||||
/// ```
 | 
					 | 
				
			||||||
pub fn sixtynine() -> i32 {
 | 
					 | 
				
			||||||
	debug!("Hello world!");
 | 
					 | 
				
			||||||
	69
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user