vm ext call function uses u256 instead of u64, ext works entirely on u256
This commit is contained in:
parent
6f17b7b44b
commit
5a072d1b4b
@ -6,7 +6,6 @@ use util::bytes::*;
|
|||||||
use evm::{Schedule, Error};
|
use evm::{Schedule, Error};
|
||||||
use env_info::*;
|
use env_info::*;
|
||||||
|
|
||||||
// TODO: replace all u64 with u256
|
|
||||||
pub trait Ext {
|
pub trait Ext {
|
||||||
/// Returns a value for given key.
|
/// Returns a value for given key.
|
||||||
fn sload(&self, key: &H256) -> H256;
|
fn sload(&self, key: &H256) -> H256;
|
||||||
@ -32,13 +31,13 @@ pub trait Ext {
|
|||||||
/// If call is successfull, returns gas left.
|
/// If call is successfull, returns gas left.
|
||||||
/// otherwise `Error`.
|
/// otherwise `Error`.
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
gas: u64,
|
gas: &U256,
|
||||||
call_gas: u64,
|
call_gas: &U256,
|
||||||
receive_address: &Address,
|
receive_address: &Address,
|
||||||
value: &U256,
|
value: &U256,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
code_address: &Address,
|
code_address: &Address,
|
||||||
output: &mut [u8]) -> Result<u64, Error>;
|
output: &mut [u8]) -> Result<U256, Error>;
|
||||||
|
|
||||||
/// Returns code at given address
|
/// Returns code at given address
|
||||||
fn extcode(&self, address: &Address) -> Vec<u8>;
|
fn extcode(&self, address: &Address) -> Vec<u8>;
|
||||||
|
@ -240,8 +240,8 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
|
|||||||
out_size: u64,
|
out_size: u64,
|
||||||
code_address: *const evmjit::H256) -> bool {
|
code_address: *const evmjit::H256) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = self.ext.call(*io_gas,
|
let res = self.ext.call(&U256::from(*io_gas),
|
||||||
call_gas,
|
&U256::from(call_gas),
|
||||||
&Address::from_jit(&*receive_address),
|
&Address::from_jit(&*receive_address),
|
||||||
&U256::from_jit(&*value),
|
&U256::from_jit(&*value),
|
||||||
slice::from_raw_parts(in_beg, in_size as usize),
|
slice::from_raw_parts(in_beg, in_size as usize),
|
||||||
@ -250,7 +250,7 @@ impl<'a> evmjit::Ext for ExtAdapter<'a> {
|
|||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(gas_left) => {
|
Ok(gas_left) => {
|
||||||
*io_gas = gas_left;
|
*io_gas = gas_left.low_u64();
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
Err(err @ evm::Error::OutOfGas) => {
|
Err(err @ evm::Error::OutOfGas) => {
|
||||||
|
@ -47,13 +47,13 @@ impl Ext for FakeExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
_gas: u64,
|
_gas: &U256,
|
||||||
_call_gas: u64,
|
_call_gas: &U256,
|
||||||
_receive_address: &Address,
|
_receive_address: &Address,
|
||||||
_value: &U256,
|
_value: &U256,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_code_address: &Address,
|
_code_address: &Address,
|
||||||
_output: &mut [u8]) -> result::Result<u64, evm::Error> {
|
_output: &mut [u8]) -> result::Result<U256, evm::Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,26 +375,26 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
ex.create(¶ms, self.substate).map(|gas_left| (gas_left, Some(address)))
|
ex.create(¶ms, self.substate).map(|gas_left| (gas_left, Some(address)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address, output: &mut [u8]) -> Result<u64, evm::Error> {
|
fn call(&mut self, gas: &U256, call_gas: &U256, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address, output: &mut [u8]) -> Result<U256, evm::Error> {
|
||||||
let mut gas_cost = call_gas;
|
let mut gas_cost = *call_gas;
|
||||||
let mut call_gas = call_gas;
|
let mut call_gas = *call_gas;
|
||||||
|
|
||||||
let is_call = receive_address == code_address;
|
let is_call = receive_address == code_address;
|
||||||
if is_call && !self.state.exists(&code_address) {
|
if is_call && !self.state.exists(&code_address) {
|
||||||
gas_cost = gas_cost + self.schedule.call_new_account_gas as u64;
|
gas_cost = gas_cost + U256::from(self.schedule.call_new_account_gas);
|
||||||
}
|
}
|
||||||
|
|
||||||
if *value > U256::zero() {
|
if *value > U256::zero() {
|
||||||
assert!(self.schedule.call_value_transfer_gas > self.schedule.call_stipend, "overflow possible");
|
assert!(self.schedule.call_value_transfer_gas > self.schedule.call_stipend, "overflow possible");
|
||||||
gas_cost = gas_cost + self.schedule.call_value_transfer_gas as u64;
|
gas_cost = gas_cost + U256::from(self.schedule.call_value_transfer_gas);
|
||||||
call_gas = call_gas + self.schedule.call_stipend as u64;
|
call_gas = call_gas + U256::from(self.schedule.call_stipend);
|
||||||
}
|
}
|
||||||
|
|
||||||
if gas_cost > gas {
|
if gas_cost > *gas {
|
||||||
return Err(evm::Error::OutOfGas)
|
return Err(evm::Error::OutOfGas)
|
||||||
}
|
}
|
||||||
|
|
||||||
let gas = gas - gas_cost;
|
let gas = *gas - gas_cost;
|
||||||
|
|
||||||
// if balance is insufficient or we are to deep, return
|
// if balance is insufficient or we are to deep, return
|
||||||
if self.state.balance(&self.params.address) < *value || self.depth >= self.schedule.stack_limit {
|
if self.state.balance(&self.params.address) < *value || self.depth >= self.schedule.stack_limit {
|
||||||
@ -405,7 +405,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
address: receive_address.clone(),
|
address: receive_address.clone(),
|
||||||
sender: self.params.address.clone(),
|
sender: self.params.address.clone(),
|
||||||
origin: self.params.origin.clone(),
|
origin: self.params.origin.clone(),
|
||||||
gas: U256::from(call_gas),
|
gas: call_gas,
|
||||||
gas_price: self.params.gas_price.clone(),
|
gas_price: self.params.gas_price.clone(),
|
||||||
value: value.clone(),
|
value: value.clone(),
|
||||||
code: self.state.code(code_address).unwrap_or(vec![]),
|
code: self.state.code(code_address).unwrap_or(vec![]),
|
||||||
@ -413,9 +413,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut ex = Executive::from_parent(self.state, self.info, self.engine, self.depth);
|
let mut ex = Executive::from_parent(self.state, self.info, self.engine, self.depth);
|
||||||
ex.call(¶ms, self.substate, BytesRef::Fixed(output)).map(|gas_left| {
|
ex.call(¶ms, self.substate, BytesRef::Fixed(output))
|
||||||
gas + gas_left.low_u64()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extcode(&self, address: &Address) -> Vec<u8> {
|
fn extcode(&self, address: &Address) -> Vec<u8> {
|
||||||
|
@ -104,13 +104,13 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
gas: u64,
|
gas: &U256,
|
||||||
call_gas: u64,
|
call_gas: &U256,
|
||||||
receive_address: &Address,
|
receive_address: &Address,
|
||||||
value: &U256,
|
value: &U256,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
code_address: &Address,
|
code_address: &Address,
|
||||||
output: &mut [u8]) -> Result<u64, evm::Error> {
|
output: &mut [u8]) -> Result<U256, evm::Error> {
|
||||||
let res = self.ext.call(gas, call_gas, receive_address, value, data, code_address, output);
|
let res = self.ext.call(gas, call_gas, receive_address, value, data, code_address, output);
|
||||||
let ext = &self.ext;
|
let ext = &self.ext;
|
||||||
match res {
|
match res {
|
||||||
@ -118,7 +118,7 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
self.callcreates.push(CallCreate {
|
self.callcreates.push(CallCreate {
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
destination: receive_address.clone(),
|
destination: receive_address.clone(),
|
||||||
_gas_limit: U256::from(call_gas),
|
_gas_limit: *call_gas,
|
||||||
value: *value
|
value: *value
|
||||||
});
|
});
|
||||||
Ok(gas_left)
|
Ok(gas_left)
|
||||||
|
Loading…
Reference in New Issue
Block a user