vm ext ret function used u256 instead of u64
This commit is contained in:
parent
360e667a64
commit
48e74e5874
@ -48,7 +48,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]) -> Result<u64, Error>;
|
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, Error>;
|
||||||
|
|
||||||
/// Should be called when contract commits suicide.
|
/// Should be called when contract commits suicide.
|
||||||
/// Address to which funds should be refunded.
|
/// Address to which funds should be refunded.
|
||||||
|
@ -345,7 +345,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 => 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 => {
|
evmjit::ReturnCode::Suicide => {
|
||||||
ext.suicide(&Address::from_jit(&context.suicide_refund_address()));
|
ext.suicide(&Address::from_jit(&context.suicide_refund_address()));
|
||||||
Ok(U256::from(context.gas_left()))
|
Ok(U256::from(context.gas_left()))
|
||||||
|
@ -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!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,26 +422,26 @@ 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]) -> Result<u64, evm::Error> {
|
fn ret(&mut self, gas: &U256, data: &[u8]) -> Result<U256, evm::Error> {
|
||||||
match &mut self.output {
|
match &mut self.output {
|
||||||
&mut OutputPolicy::Return(BytesRef::Fixed(ref mut slice)) => unsafe {
|
&mut OutputPolicy::Return(BytesRef::Fixed(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);
|
||||||
Ok(gas)
|
Ok(*gas)
|
||||||
},
|
},
|
||||||
&mut OutputPolicy::Return(BytesRef::Flexible(ref mut vec)) => unsafe {
|
&mut OutputPolicy::Return(BytesRef::Flexible(ref mut vec)) => unsafe {
|
||||||
vec.clear();
|
vec.clear();
|
||||||
vec.reserve(data.len());
|
vec.reserve(data.len());
|
||||||
ptr::copy(data.as_ptr(), vec.as_mut_ptr(), data.len());
|
ptr::copy(data.as_ptr(), vec.as_mut_ptr(), data.len());
|
||||||
vec.set_len(data.len());
|
vec.set_len(data.len());
|
||||||
Ok(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 = U256::from(data.len()) * U256::from(self.schedule.create_data_gas);
|
||||||
if return_cost > gas {
|
if return_cost > *gas {
|
||||||
return match self.schedule.exceptional_failed_code_deposit {
|
return match self.schedule.exceptional_failed_code_deposit {
|
||||||
true => Err(evm::Error::OutOfGas),
|
true => Err(evm::Error::OutOfGas),
|
||||||
false => Ok(gas)
|
false => Ok(*gas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut code = vec![];
|
let mut code = vec![];
|
||||||
@ -453,7 +453,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);
|
||||||
self.substate.contracts_created.push(address.clone());
|
self.substate.contracts_created.push(address.clone());
|
||||||
Ok(gas - return_cost)
|
Ok(*gas - return_cost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
self.ext.log(topics, data)
|
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)
|
self.ext.ret(gas, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user