changes in executive return

This commit is contained in:
debris 2016-01-11 14:14:35 +01:00
parent bbb25fb6ce
commit 22859a04b6
3 changed files with 6 additions and 16 deletions

View File

@ -47,13 +47,6 @@ impl Substate {
pub fn logs(&self) -> &[LogEntry] { pub fn logs(&self) -> &[LogEntry] {
&self.logs &self.logs
} }
/// Appends another substate to this substate.
fn accrue(&mut self, s: Substate) {
self.suicides.extend(s.suicides.into_iter());
self.logs.extend(s.logs.into_iter());
self.refunds_count = self.refunds_count + s.refunds_count;
}
} }
/// Transaction execution result. /// Transaction execution result.
@ -425,17 +418,17 @@ impl<'a> Ext for Externalities<'a> {
self.state.code(address).unwrap_or(vec![]) self.state.code(address).unwrap_or(vec![])
} }
fn ret(&mut self, gas: u64, data: &[u8]) -> Option<u64> { fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError> {
match &mut self.output { match &mut self.output {
&mut OutputPolicy::Return(ref mut slice) => unsafe { &mut OutputPolicy::Return(ref mut slice) => unsafe {
let len = cmp::min(slice.len(), data.len()); let len = cmp::min(slice.len(), data.len());
ptr::copy(data.as_ptr(), slice.as_mut_ptr(), len); ptr::copy(data.as_ptr(), slice.as_mut_ptr(), len);
Some(gas) Ok(gas)
}, },
&mut OutputPolicy::InitContract => { &mut OutputPolicy::InitContract => {
let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64; let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64;
if return_cost > gas { if return_cost > gas {
return None; return Err(EvmError::OutOfGas);
} }
let mut code = vec![]; let mut code = vec![];
code.reserve(data.len()); code.reserve(data.len());
@ -445,7 +438,7 @@ impl<'a> Ext for Externalities<'a> {
} }
let address = &self.params.address; let address = &self.params.address;
self.state.init_code(address, code); self.state.init_code(address, code);
Some(gas - return_cost) Ok(gas - return_cost)
} }
} }
} }

View File

@ -47,7 +47,7 @@ pub trait Ext {
/// Should be called when transaction calls `RETURN` opcode. /// Should be called when transaction calls `RETURN` opcode.
/// Returns gas_left if cost of returning the data is not too high. /// Returns gas_left if cost of returning the data is not too high.
fn ret(&mut self, gas: u64, data: &[u8]) -> Option<u64>; fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, EvmError>;
/// Should be called when contract commits suicide. /// Should be called when contract commits suicide.
fn suicide(&mut self); fn suicide(&mut self);

View File

@ -347,10 +347,7 @@ impl evm::Evm for JitEvm {
match res { match res {
evmjit::ReturnCode::Stop => Ok(U256::from(context.gas_left())), evmjit::ReturnCode::Stop => Ok(U256::from(context.gas_left())),
evmjit::ReturnCode::Return => match ext.ret(context.gas_left(), context.output_data()) { evmjit::ReturnCode::Return => ext.ret(context.gas_left(), context.output_data()).map(|gas_left| U256::from(gas_left)),
Some(gas_left) => Ok(U256::from(gas_left)),
None => Err(evm::EvmError::OutOfGas)
},
evmjit::ReturnCode::Suicide => { evmjit::ReturnCode::Suicide => {
// what if there is a suicide and we run out of gas just after? // what if there is a suicide and we run out of gas just after?
ext.suicide(); ext.suicide();