Fixes after merge

This commit is contained in:
Tomusdrw 2016-01-15 02:16:04 +01:00
parent 7010e870a4
commit 5d0c294635
3 changed files with 20 additions and 24 deletions

View File

@ -4,6 +4,7 @@ use common::*;
use evm; use evm;
use super::instructions as instructions; use super::instructions as instructions;
use super::instructions::Instruction; use super::instructions::Instruction;
use std::num::wrapping::OverflowingOps;
type CodePosition = usize; type CodePosition = usize;
type Gas = U256; type Gas = U256;
@ -422,9 +423,7 @@ impl Interpreter {
let init_size = stack.pop_back(); let init_size = stack.pop_back();
let contract_code = mem.read_slice(init_off, init_size); let contract_code = mem.read_slice(init_off, init_size);
let (gas_left, maybe_address) = try!( let (gas_left, maybe_address) = ext.create(&gas, &endowment, &contract_code);
ext.create(&gas, &endowment, &contract_code)
);
match maybe_address { match maybe_address {
Some(address) => stack.push(address_to_u256(address)), Some(address) => stack.push(address_to_u256(address)),
None => stack.push(U256::zero()) None => stack.push(U256::zero())
@ -454,7 +453,7 @@ impl Interpreter {
let out_off = stack.pop_back(); let out_off = stack.pop_back();
let out_size = stack.pop_back(); let out_size = stack.pop_back();
let gas_left = { let (gas_left, call_successful) = {
// we need to write and read from memory in the same time // we need to write and read from memory in the same time
// and we don't want to copy // and we don't want to copy
let input = unsafe { ::std::mem::transmute(mem.read_slice(in_off, in_size)) }; let input = unsafe { ::std::mem::transmute(mem.read_slice(in_off, in_size)) };
@ -463,7 +462,11 @@ impl Interpreter {
ext.call(&gas, &call_gas, address, &value, input, &code_address, output) ext.call(&gas, &call_gas, address, &value, input, &code_address, output)
) )
}; };
stack.push(U256::one()); if call_successful {
stack.push(U256::one());
} else {
stack.push(U256::zero());
}
return Ok(InstructionResult::AdditionalGasCost( return Ok(InstructionResult::AdditionalGasCost(
gas - gas_left gas - gas_left
)); ));
@ -696,26 +699,26 @@ impl Interpreter {
instructions::ADD => { instructions::ADD => {
let a = stack.pop_back(); let a = stack.pop_back();
let b = stack.pop_back(); let b = stack.pop_back();
let (c, _overflow) = a.overflowing_add(a, b); let (c, _overflow) = a.overflowing_add(b);
stack.push(c); stack.push(c);
}, },
instructions::MUL => { instructions::MUL => {
let a = stack.pop_back(); let a = stack.pop_back();
let b = stack.pop_back(); let b = stack.pop_back();
let (c, _overflow) = a.overflowing_mul(a, b); let (c, _overflow) = a.overflowing_mul(b);
stack.push(c); stack.push(c);
}, },
instructions::SUB => { instructions::SUB => {
let a = stack.pop_back(); let a = stack.pop_back();
let b = stack.pop_back(); let b = stack.pop_back();
let (c, _overflow) = a.overflowing_sub(a, b); let (c, _overflow) = a.overflowing_sub(b);
stack.push(c); stack.push(c);
}, },
instructions::DIV => { instructions::DIV => {
let a = stack.pop_back(); let a = stack.pop_back();
let b = stack.pop_back(); let b = stack.pop_back();
stack.push(if !self.is_zero(&b) { stack.push(if !self.is_zero(&b) {
let (c, _overflow) = a.overflowing_div(a, b); let (c, _overflow) = a.overflowing_div(b);
c c
} else { } else {
U256::zero() U256::zero()
@ -725,7 +728,7 @@ impl Interpreter {
let a = stack.pop_back(); let a = stack.pop_back();
let b = stack.pop_back(); let b = stack.pop_back();
stack.push(if !self.is_zero(&b) { stack.push(if !self.is_zero(&b) {
let (c, _overflow) = a.overflowing_rem(a, b); let (c, _overflow) = a.overflowing_rem(b);
c c
} else { } else {
U256::zero() U256::zero()

View File

@ -290,14 +290,13 @@ impl<'a> Executive<'a> {
| Err(evm::Error::BadInstruction { instruction: _ }) | Err(evm::Error::BadInstruction { instruction: _ })
| Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _}) | Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _})
| Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => { | Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => {
*self.state = backup;
Ok(Executed { Ok(Executed {
gas: t.gas, gas: t.gas,
gas_used: t.gas, gas_used: t.gas,
refunded: U256::zero(), refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas, cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![], logs: vec![],
out_of_gas: true, excepted: true,
contracts_created: vec![] contracts_created: vec![]
}) })
}, },
@ -311,17 +310,6 @@ impl<'a> Executive<'a> {
excepted: substate.excepted, excepted: substate.excepted,
contracts_created: substate.contracts_created contracts_created: substate.contracts_created
}) })
},
_err => {
Ok(Executed {
gas: t.gas,
gas_used: t.gas,
refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![],
excepted: true,
contracts_created: vec![]
})
} }
} }
} }
@ -329,7 +317,11 @@ impl<'a> Executive<'a> {
fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate, backup: State) { fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate, backup: State) {
// TODO: handle other evm::Errors same as OutOfGas once they are implemented // TODO: handle other evm::Errors same as OutOfGas once they are implemented
match result { match result {
&Err(evm::Error::OutOfGas) => { &Err(evm::Error::OutOfGas)
| &Err(evm::Error::BadJumpDestination { destination: _ })
| &Err(evm::Error::BadInstruction { instruction: _ })
| &Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _})
| &Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => {
substate.excepted = true; substate.excepted = true;
self.state.revert(backup); self.state.revert(backup);
}, },

View File

@ -1,5 +1,6 @@
#![feature(cell_extras)] #![feature(cell_extras)]
#![feature(augmented_assignments)] #![feature(augmented_assignments)]
#![feature(wrapping)]
//#![feature(plugin)] //#![feature(plugin)]
//#![plugin(interpolate_idents)] //#![plugin(interpolate_idents)]
//! Ethcore's ethereum implementation //! Ethcore's ethereum implementation