Merge branch 'master' into rustfmt

Conflicts:
	ethash/src/sizes.rs
	util/src/uint.rs
This commit is contained in:
Tomasz Drwięga
2016-03-23 16:55:54 +01:00
252 changed files with 25911 additions and 6611 deletions

View File

@@ -65,7 +65,7 @@ pub enum Error {
/// Evm result.
///
/// Returns gas_left if execution is successfull, otherwise error.
/// Returns gas_left if execution is successful, otherwise error.
pub type Result = result::Result<U256, Error>;
/// Evm interface.

View File

@@ -16,9 +16,7 @@
//! Interface for Evm externalities.
use common::Bytes;
use util::hash::*;
use util::uint::*;
use util::common::*;
use evm::{Schedule, Error};
use env_info::*;
@@ -60,22 +58,23 @@ pub trait Ext {
fn blockhash(&self, number: &U256) -> H256;
/// Creates new contract.
///
///
/// Returns gas_left and contract address if contract creation was succesfull.
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult;
/// Message call.
///
///
/// Returns Err, if we run out of gas.
/// Otherwise returns call_result which contains gas left
/// Otherwise returns call_result which contains gas left
/// and true if subcall was successfull.
fn call(&mut self,
gas: &U256,
sender_address: &Address,
receive_address: &Address,
#[cfg_attr(feature="dev", allow(too_many_arguments))]
fn call(&mut self,
gas: &U256,
sender_address: &Address,
receive_address: &Address,
value: Option<U256>,
data: &[u8],
code_address: &Address,
data: &[u8],
code_address: &Address,
output: &mut [u8]) -> MessageCallResult;
/// Returns code at given address
@@ -99,7 +98,7 @@ pub trait Ext {
fn env_info(&self) -> &EnvInfo;
/// Returns current depth of execution.
///
///
/// If contract A calls contract B, and contract B calls C,
/// then A depth is 0, B is 1, C is 2 and so on.
fn depth(&self) -> usize;

View File

@@ -25,7 +25,7 @@ use evm::Evm;
/// Type of EVM to use.
pub enum VMType {
/// JIT EVM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
Jit,
/// RUST EVM
Interpreter
@@ -52,13 +52,13 @@ impl fmt::Display for VMType {
#[cfg(feature = "json-tests")]
impl VMType {
/// Return all possible VMs (JIT, Interpreter)
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn all() -> Vec<VMType> {
vec![VMType::Jit, VMType::Interpreter]
}
/// Return all possible VMs (Interpreter)
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn all() -> Vec<VMType> {
vec![VMType::Interpreter]
}
@@ -66,12 +66,12 @@ impl VMType {
/// Evm factory. Creates appropriate Evm.
pub struct Factory {
evm : VMType
evm: VMType
}
impl Factory {
/// Create fresh instance of VM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Jit => {
@@ -84,7 +84,7 @@ impl Factory {
}
/// Create fresh instance of VM
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Interpreter => {

View File

@@ -243,7 +243,7 @@ struct CodeReader<'a> {
code: &'a Bytes
}
#[allow(len_without_is_empty)]
#[cfg_attr(feature="dev", allow(len_without_is_empty))]
impl<'a> CodeReader<'a> {
/// Get `no_of_bytes` from code and convert to U256. Move PC
fn read(&mut self, no_of_bytes: usize) -> U256 {
@@ -258,7 +258,7 @@ impl<'a> CodeReader<'a> {
}
}
#[allow(enum_variant_names)]
#[cfg_attr(feature="dev", allow(enum_variant_names))]
enum InstructionCost {
Gas(U256),
GasMem(U256, U256),
@@ -299,7 +299,7 @@ impl evm::Evm for Interpreter {
let (gas_cost, mem_size) = try!(self.get_gas_cost_mem(ext, instruction, &mut mem, &stack));
try!(self.verify_gas(&current_gas, &gas_cost));
mem.expand(mem_size);
current_gas -= gas_cost;
current_gas = current_gas - gas_cost; //TODO: use operator -=
evm_debug!({
println!("[0x{:x}][{}(0x{:x}) Gas: {:x}\n Gas Before: {:x}",
@@ -320,7 +320,7 @@ impl evm::Evm for Interpreter {
match result {
InstructionResult::Ok => {},
InstructionResult::UnusedGas(gas) => {
current_gas += gas;
current_gas = current_gas + gas; //TODO: use operator +=
},
InstructionResult::UseAllGas => {
current_gas = U256::zero();
@@ -347,13 +347,14 @@ impl evm::Evm for Interpreter {
}
impl Interpreter {
#[allow(cyclomatic_complexity)]
fn get_gas_cost_mem(&self,
ext: &evm::Ext,
instruction: Instruction,
mem: &mut Memory,
stack: &Stack<U256>
) -> Result<(U256, usize), evm::Error> {
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
fn get_gas_cost_mem(
&self,
ext: &evm::Ext,
instruction: Instruction,
mem: &mut Memory,
stack: &Stack<U256>
) -> Result<(U256, usize), evm::Error> {
let schedule = ext.schedule();
let info = instructions::get_info(instruction);
@@ -521,15 +522,17 @@ impl Interpreter {
Ok(overflowing!(offset.overflowing_add(size.clone())))
}
fn exec_instruction(&self,
gas: Gas,
params: &ActionParams,
ext: &mut evm::Ext,
instruction: Instruction,
code: &mut CodeReader,
mem: &mut Memory,
stack: &mut Stack<U256>
) -> Result<InstructionResult, evm::Error> {
#[cfg_attr(feature="dev", allow(too_many_arguments))]
fn exec_instruction(
&self,
gas: Gas,
params: &ActionParams,
ext: &mut evm::Ext,
instruction: Instruction,
code: &mut CodeReader,
mem: &mut Memory,
stack: &mut Stack<U256>
) -> Result<InstructionResult, evm::Error> {
match instruction {
instructions::JUMP => {
let jump = stack.pop_back();
@@ -581,9 +584,10 @@ impl Interpreter {
let code_address = stack.pop_back();
let code_address = u256_to_address(&code_address);
let value = match instruction == instructions::DELEGATECALL {
true => None,
false => Some(stack.pop_back())
let value = if instruction == instructions::DELEGATECALL {
None
} else {
Some(stack.pop_back())
};
let in_off = stack.pop_back();

View File

@@ -25,9 +25,8 @@ struct FakeLogEntry {
}
#[derive(PartialEq, Eq, Hash, Debug)]
#[allow(enum_variant_names)] // Common prefix is C ;)
enum FakeCallType {
CALL, CREATE
Call, Create
}
#[derive(PartialEq, Eq, Hash, Debug)]
@@ -56,7 +55,7 @@ struct FakeExt {
info: EnvInfo,
schedule: Schedule,
balances: HashMap<Address, U256>,
calls: HashSet<FakeCall>
calls: HashSet<FakeCall>,
}
impl FakeExt {
@@ -94,7 +93,7 @@ impl Ext for FakeExt {
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult {
self.calls.insert(FakeCall {
call_type: FakeCallType::CREATE,
call_type: FakeCallType::Create,
gas: *gas,
sender_address: None,
receive_address: None,
@@ -115,7 +114,7 @@ impl Ext for FakeExt {
_output: &mut [u8]) -> MessageCallResult {
self.calls.insert(FakeCall {
call_type: FakeCallType::CALL,
call_type: FakeCallType::Call,
gas: *gas,
sender_address: Some(sender_address.clone()),
receive_address: Some(receive_address.clone()),
@@ -347,7 +346,7 @@ fn test_log_empty(factory: super::Factory) {
assert_eq!(gas_left, U256::from(99_619));
assert_eq!(ext.logs.len(), 1);
assert_eq!(ext.logs[0].topics.len(), 0);
assert_eq!(ext.logs[0].data, vec![]);
assert!(ext.logs[0].data.is_empty());
}
evm_test!{test_log_sender: test_log_sender_jit, test_log_sender_int}
@@ -909,7 +908,7 @@ fn test_calls(factory: super::Factory) {
};
assert_set_contains(&ext.calls, &FakeCall {
call_type: FakeCallType::CALL,
call_type: FakeCallType::Call,
gas: U256::from(2556),
sender_address: Some(address.clone()),
receive_address: Some(code_address.clone()),
@@ -918,7 +917,7 @@ fn test_calls(factory: super::Factory) {
code_address: Some(code_address.clone())
});
assert_set_contains(&ext.calls, &FakeCall {
call_type: FakeCallType::CALL,
call_type: FakeCallType::Call,
gas: U256::from(2556),
sender_address: Some(address.clone()),
receive_address: Some(address.clone()),