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 super::instructions as instructions;
use super::instructions::Instruction;
use std::num::wrapping::OverflowingOps;
type CodePosition = usize;
type Gas = U256;
@ -422,9 +423,7 @@ impl Interpreter {
let init_size = stack.pop_back();
let contract_code = mem.read_slice(init_off, init_size);
let (gas_left, maybe_address) = try!(
ext.create(&gas, &endowment, &contract_code)
);
let (gas_left, maybe_address) = ext.create(&gas, &endowment, &contract_code);
match maybe_address {
Some(address) => stack.push(address_to_u256(address)),
None => stack.push(U256::zero())
@ -454,7 +453,7 @@ impl Interpreter {
let out_off = 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
// and we don't want to copy
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)
)
};
stack.push(U256::one());
if call_successful {
stack.push(U256::one());
} else {
stack.push(U256::zero());
}
return Ok(InstructionResult::AdditionalGasCost(
gas - gas_left
));
@ -696,26 +699,26 @@ impl Interpreter {
instructions::ADD => {
let a = 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);
},
instructions::MUL => {
let a = 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);
},
instructions::SUB => {
let a = 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);
},
instructions::DIV => {
let a = stack.pop_back();
let b = stack.pop_back();
stack.push(if !self.is_zero(&b) {
let (c, _overflow) = a.overflowing_div(a, b);
let (c, _overflow) = a.overflowing_div(b);
c
} else {
U256::zero()
@ -725,7 +728,7 @@ impl Interpreter {
let a = stack.pop_back();
let b = stack.pop_back();
stack.push(if !self.is_zero(&b) {
let (c, _overflow) = a.overflowing_rem(a, b);
let (c, _overflow) = a.overflowing_rem(b);
c
} else {
U256::zero()

View File

@ -290,14 +290,13 @@ impl<'a> Executive<'a> {
| Err(evm::Error::BadInstruction { instruction: _ })
| Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _})
| Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => {
*self.state = backup;
Ok(Executed {
gas: t.gas,
gas_used: t.gas,
refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![],
out_of_gas: true,
excepted: true,
contracts_created: vec![]
})
},
@ -311,17 +310,6 @@ impl<'a> Executive<'a> {
excepted: substate.excepted,
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) {
// TODO: handle other evm::Errors same as OutOfGas once they are implemented
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;
self.state.revert(backup);
},

View File

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