vm ext ret function used u256 instead of u64

This commit is contained in:
debris 2016-01-13 22:16:24 +01:00
parent 360e667a64
commit 48e74e5874
5 changed files with 11 additions and 11 deletions

View File

@ -48,7 +48,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]) -> Result<u64, Error>;
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, Error>;
/// Should be called when contract commits suicide.
/// Address to which funds should be refunded.

View File

@ -345,7 +345,7 @@ impl evm::Evm for JitEvm {
match res {
evmjit::ReturnCode::Stop => Ok(U256::from(context.gas_left())),
evmjit::ReturnCode::Return => ext.ret(context.gas_left(), context.output_data()).map(|gas_left| U256::from(gas_left)),
evmjit::ReturnCode::Return => ext.ret(&U256::from(context.gas_left()), context.output_data()),
evmjit::ReturnCode::Suicide => {
ext.suicide(&Address::from_jit(&context.suicide_refund_address()));
Ok(U256::from(context.gas_left()))

View File

@ -68,7 +68,7 @@ impl Ext for FakeExt {
});
}
fn ret(&mut self, _gas: u64, _data: &[u8]) -> result::Result<u64, evm::Error> {
fn ret(&mut self, _gas: &U256, _data: &[u8]) -> result::Result<U256, evm::Error> {
unimplemented!();
}

View File

@ -422,26 +422,26 @@ impl<'a> Ext for Externalities<'a> {
self.state.code(address).unwrap_or(vec![])
}
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, evm::Error> {
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, evm::Error> {
match &mut self.output {
&mut OutputPolicy::Return(BytesRef::Fixed(ref mut slice)) => unsafe {
let len = cmp::min(slice.len(), data.len());
ptr::copy(data.as_ptr(), slice.as_mut_ptr(), len);
Ok(gas)
Ok(*gas)
},
&mut OutputPolicy::Return(BytesRef::Flexible(ref mut vec)) => unsafe {
vec.clear();
vec.reserve(data.len());
ptr::copy(data.as_ptr(), vec.as_mut_ptr(), data.len());
vec.set_len(data.len());
Ok(gas)
Ok(*gas)
},
&mut OutputPolicy::InitContract => {
let return_cost = data.len() as u64 * self.schedule.create_data_gas as u64;
if return_cost > gas {
let return_cost = U256::from(data.len()) * U256::from(self.schedule.create_data_gas);
if return_cost > *gas {
return match self.schedule.exceptional_failed_code_deposit {
true => Err(evm::Error::OutOfGas),
false => Ok(gas)
false => Ok(*gas)
}
}
let mut code = vec![];
@ -453,7 +453,7 @@ impl<'a> Ext for Externalities<'a> {
let address = &self.params.address;
self.state.init_code(address, code);
self.substate.contracts_created.push(address.clone());
Ok(gas - return_cost)
Ok(*gas - return_cost)
}
}
}

View File

@ -135,7 +135,7 @@ impl<'a> Ext for TestExt<'a> {
self.ext.log(topics, data)
}
fn ret(&mut self, gas: u64, data: &[u8]) -> Result<u64, evm::Error> {
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, evm::Error> {
self.ext.ret(gas, data)
}