diff --git a/src/evm/executive.rs b/src/evm/executive.rs index 383e79fc5..6fef7a6ba 100644 --- a/src/evm/executive.rs +++ b/src/evm/executive.rs @@ -47,13 +47,6 @@ impl Substate { pub fn logs(&self) -> &[LogEntry] { &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. @@ -425,17 +418,17 @@ impl<'a> Ext for Externalities<'a> { self.state.code(address).unwrap_or(vec![]) } - fn ret(&mut self, gas: u64, data: &[u8]) -> Option { + fn ret(&mut self, gas: u64, data: &[u8]) -> Result { match &mut self.output { &mut OutputPolicy::Return(ref mut slice) => unsafe { let len = cmp::min(slice.len(), data.len()); ptr::copy(data.as_ptr(), slice.as_mut_ptr(), len); - Some(gas) + Ok(gas) }, &mut OutputPolicy::InitContract => { let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64; if return_cost > gas { - return None; + return Err(EvmError::OutOfGas); } let mut code = vec![]; code.reserve(data.len()); @@ -445,7 +438,7 @@ impl<'a> Ext for Externalities<'a> { } let address = &self.params.address; self.state.init_code(address, code); - Some(gas - return_cost) + Ok(gas - return_cost) } } } diff --git a/src/evm/ext.rs b/src/evm/ext.rs index 9ffebc605..33f89e32f 100644 --- a/src/evm/ext.rs +++ b/src/evm/ext.rs @@ -47,7 +47,7 @@ pub trait Ext { /// Should be called when transaction calls `RETURN` opcode. /// Returns gas_left if cost of returning the data is not too high. - fn ret(&mut self, gas: u64, data: &[u8]) -> Option; + fn ret(&mut self, gas: u64, data: &[u8]) -> Result; /// Should be called when contract commits suicide. fn suicide(&mut self); diff --git a/src/evm/jit.rs b/src/evm/jit.rs index 6272d87f7..3f0dff6ed 100644 --- a/src/evm/jit.rs +++ b/src/evm/jit.rs @@ -347,10 +347,7 @@ impl evm::Evm for JitEvm { match res { evmjit::ReturnCode::Stop => Ok(U256::from(context.gas_left())), - evmjit::ReturnCode::Return => match ext.ret(context.gas_left(), context.output_data()) { - Some(gas_left) => Ok(U256::from(gas_left)), - None => Err(evm::EvmError::OutOfGas) - }, + evmjit::ReturnCode::Return => ext.ret(context.gas_left(), context.output_data()).map(|gas_left| U256::from(gas_left)), evmjit::ReturnCode::Suicide => { // what if there is a suicide and we run out of gas just after? ext.suicide();