evm params

This commit is contained in:
debris 2016-01-09 00:51:09 +01:00
parent bed4bfce1c
commit 4932720d58
7 changed files with 324 additions and 223 deletions

View File

@ -1,6 +1,6 @@
//! Evm interface.
use evm::{RuntimeData, ExtFace};
use evm::Ext;
#[derive(Debug, Eq, PartialEq)]
pub enum ReturnCode {
@ -12,5 +12,5 @@ pub enum ReturnCode {
}
pub trait Evm {
fn exec(&self, data: RuntimeData, ext: &mut ExtFace) -> ReturnCode;
fn exec(&self, ext: &mut Ext) -> ReturnCode;
}

View File

@ -2,12 +2,14 @@ use util::hash::*;
use util::uint::*;
use util::rlp::*;
use util::sha3::*;
use util::bytes::*;
use state::*;
use env_info::*;
use engine::*;
use transaction::*;
use evm::{VmFactory, ExtFace, Ext, RuntimeData};
use evm::{VmFactory, Ext, LogEntry, EvmParams, ParamsKind};
/// Returns new address created from address and given nonce.
pub fn contract_address(address: &Address, nonce: &U256) -> Address {
let mut stream = RlpStream::new_list(2);
stream.append(address);
@ -23,57 +25,193 @@ pub struct Executive<'a> {
state: &'a mut State,
info: &'a EnvInfo,
engine: &'a Engine,
depth: usize
depth: usize,
params: EvmParams,
logs: Vec<LogEntry>,
refunds: U256,
}
impl<'a> Executive<'a> {
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, depth: usize) -> Self {
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, t: &Transaction) -> Self {
// TODO: validate nonce ?
let sender = t.sender();
let params = match t.kind() {
TransactionKind::ContractCreation => EvmParams {
address: contract_address(&sender, &t.nonce),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: t.data.clone(),
data: vec![],
kind: ParamsKind::Create
},
TransactionKind::MessageCall => EvmParams {
address: t.to.clone().unwrap(),
sender: sender.clone(),
origin: sender.clone(),
gas: t.gas,
gas_price: t.gas_price,
value: t.value,
code: state.code(&t.to.clone().unwrap()).unwrap_or(vec![]),
data: t.data.clone(),
kind: ParamsKind::Call
}
};
Executive::new_from_params(state, info, engine, params)
}
pub fn new_from_params(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, params: EvmParams) -> Self {
Executive {
state: state,
info: info,
engine: engine,
depth: depth
depth: 0,
params: params,
logs: vec![],
refunds: U256::zero(),
}
}
pub fn exec(&mut self, transaction: &Transaction) -> ExecutiveResult {
fn new_populated_from(e: &'a mut Executive, params: EvmParams) -> Self {
Executive {
state: e.state,
info: e.info,
engine: e.engine,
depth: e.depth + 1,
params: params,
logs: vec![],
refunds: U256::zero(),
}
}
pub fn exec(&mut self) -> ExecutiveResult {
// TODO: validate that we have enough funds
self.state.inc_nonce(&transaction.sender());
match transaction.kind() {
TransactionKind::MessageCall => self.call(transaction),
TransactionKind::ContractCreation => self.create(&transaction.sender(),
&transaction.value,
&transaction.gas_price,
&transaction.gas,
&transaction.data,
&transaction.sender())
match &self.params.kind() {
&ParamsKind::Call => {
self.state.inc_nonce(&self.params.address);
self.call()
},
&ParamsKind::Create => self.create()
}
}
fn call(&mut self, transaction: &Transaction) -> ExecutiveResult {
fn call(&mut self) -> ExecutiveResult {
ExecutiveResult::Ok
}
fn create(&mut self, sender: &Address, endowment: &U256, gas_price: &U256, gas: &U256, init: &[u8], origin: &Address) -> ExecutiveResult {
let new_address = contract_address(&sender, &(self.state.nonce(sender) - U256::one()));
fn create(&mut self) -> ExecutiveResult {
let address = self.params.address.clone();
//let new_address = contract_address(&address, &self.state.nonce(&address));
let new_address = self.params.address.clone();
self.state.inc_nonce(&address);
{
let mut ext = Ext::new(self.state, self.info, self.engine, self.depth, new_address.clone());
let mut data = RuntimeData::new();
// TODO: init runtime data
data.gas = *gas;
data.gas_price = *gas_price;
let evm = VmFactory::create();
evm.exec(data, &mut ext);
// TODO: valdidate that exec returns proper code
evm.exec(self);
}
self.state.transfer_balance(sender, &new_address, endowment);
self.state.transfer_balance(&address, &new_address, &self.params.value);
ExecutiveResult::Ok
}
pub fn logs(&self) -> &[LogEntry] {
&self.logs
}
}
impl<'a> Ext for Executive<'a> {
fn params(&self) -> &EvmParams {
&self.params
}
fn sload(&self, key: &H256) -> H256 {
self.state.storage_at(&self.params.address, key)
}
fn sstore(&mut self, key: H256, value: H256) {
if value == H256::new() && self.state.storage_at(&self.params.address, &key) != H256::new() {
self.refunds = self.refunds + U256::from(self.engine.evm_schedule(self.info).sstore_refund_gas);
}
self.state.set_storage(&self.params.address, key, value)
}
fn balance(&self, address: &Address) -> U256 {
self.state.balance(address)
}
fn blockhash(&self, number: &U256) -> H256 {
match *number < self.info.number {
false => H256::from(&U256::zero()),
true => {
let index = self.info.number - *number - U256::one();
self.info.last_hashes[index.low_u32() as usize].clone()
}
}
}
fn create(&mut self, gas: u64, endowment: &U256, code: &[u8]) -> (Address, u64) {
match self.state.balance(&self.params.address) > *endowment && self.depth < 1024 {
false => (Address::new(), gas),
true => {
let params = EvmParams {
address: contract_address(&self.params.address, &self.state.nonce(&self.params.address)),
sender: self.params.address.clone(),
origin: self.params.origin.clone(),
gas: U256::from(gas),
gas_price: self.params.gas_price.clone(),
value: endowment.clone(),
code: code.to_vec(),
data: vec![],
kind: ParamsKind::Create
};
let mut ex = Executive::new_populated_from(self, params);
ex.create();
unimplemented!()
}
}
}
fn call(&mut self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address) -> Option<(Vec<u8>, u64)>{
// TODO: validation of the call
let params = EvmParams {
address: code_address.clone(),
sender: receive_address.clone(),
origin: self.params.origin.clone(),
gas: U256::from(call_gas), // TODO:
gas_price: self.params.gas_price.clone(),
value: value.clone(),
code: self.state.code(code_address).unwrap_or(vec![]),
data: data.to_vec(),
kind: ParamsKind::Call
};
{
let mut ex = Executive::new_populated_from(self, params);
ex.call();
unimplemented!();
}
}
fn extcode(&self, address: &Address) -> Vec<u8> {
self.state.code(address).unwrap_or(vec![])
}
fn log(&mut self, topics: Vec<H256>, data: Bytes) {
let address = self.params.address.clone();
self.logs.push(LogEntry::new(address, topics, data));
}
}
#[cfg(test)]

View File

@ -1,34 +1,14 @@
//! Contract execution environment.
use std::collections::HashSet;
use util::hash::*;
use util::uint::*;
use util::bytes::*;
use state::*;
use env_info::*;
use evm::LogEntry;
use engine::*;
use evm::EvmParams;
struct SubState {
// any accounts that have suicided
suicides: HashSet<Address>,
// any logs
logs: Vec<LogEntry>,
// refund counter of SSTORE nonzero->zero
refunds: U256
}
pub trait Ext {
/// Returns evm params.
fn params(&self) -> &EvmParams;
impl SubState {
fn new() -> SubState {
SubState {
suicides: HashSet::new(),
logs: vec![],
refunds: U256::zero()
}
}
}
pub trait ExtFace {
/// Returns a value for given key.
fn sload(&self, key: &H256) -> H256;
@ -43,11 +23,11 @@ pub trait ExtFace {
/// Creates new contract.
/// Returns new contract address and gas used.
fn create(&self, gas: u64, endowment: &U256, code: &[u8]) -> (Address, u64);
fn create(&mut self, gas: u64, endowment: &U256, code: &[u8]) -> (Address, u64);
/// Calls existing contract.
/// Returns call output and gas used.
fn call(&self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address) -> Option<(Vec<u8>, u64)>;
fn call(&mut self, gas: u64, call_gas: u64, receive_address: &Address, value: &U256, data: &[u8], code_address: &Address) -> Option<(Vec<u8>, u64)>;
/// Returns code at given address
fn extcode(&self, address: &Address) -> Vec<u8>;
@ -55,90 +35,3 @@ pub trait ExtFace {
/// Creates log entry with given topics and data
fn log(&mut self, topics: Vec<H256>, data: Bytes);
}
/// Externality interface for the Virtual Machine providing access to
/// world state.
///
/// ```markdown
/// extern crate ethcore_util as util;
/// extern crate ethcore;
/// use util::hash::*;
/// use ethcore::state::*;
/// use ethcore::env_info::*;
/// use ethcore::evm::*;
///
/// fn main() {
/// let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
/// let mut state = State::new_temp();
/// let info = EnvInfo::new();
/// let ext = Ext::new(&mut state, &info, address);
/// }
/// ```
pub struct Ext<'a> {
state: &'a mut State,
info: &'a EnvInfo,
engine: &'a Engine,
depth: usize,
address: Address,
substate: SubState
}
impl<'a> Ext<'a> {
/// Creates new evm environment object with backing state.
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine, depth: usize, address: Address) -> Self {
Ext {
state: state,
info: info,
engine: engine,
depth: depth,
address: address,
substate: SubState::new(),
}
}
/// Returns substate logs.
pub fn logs(&self) -> &[LogEntry] {
&self.substate.logs
}
}
impl<'a> ExtFace for Ext<'a> {
fn sload(&self, key: &H256) -> H256 {
self.state.storage_at(&self.address, key)
}
fn sstore(&mut self, key: H256, value: H256) {
self.state.set_storage(&self.address, key, value)
}
fn balance(&self, address: &Address) -> U256 {
self.state.balance(address)
}
fn blockhash(&self, number: &U256) -> H256 {
match *number < self.info.number {
false => H256::from(&U256::zero()),
true => {
let index = self.info.number - *number - U256::one();
self.info.last_hashes[index.low_u32() as usize].clone()
}
}
}
fn create(&self, _gas: u64, _endowment: &U256, _code: &[u8]) -> (Address, u64) {
unimplemented!();
}
fn call(&self, _gas: u64, _call_gas: u64, _receive_address: &Address, _value: &U256, _data: &[u8], _code_address: &Address) -> Option<(Vec<u8>, u64)>{
unimplemented!();
}
fn extcode(&self, address: &Address) -> Vec<u8> {
self.state.code(address).unwrap_or(vec![])
}
fn log(&mut self, topics: Vec<H256>, data: Bytes) {
let address = self.address.clone();
self.substate.logs.push(LogEntry::new(address, topics, data));
}
}

View File

@ -122,11 +122,11 @@ impl IntoJit<evmjit::RuntimeDataHandle> for evm::RuntimeData {
}
struct ExtAdapter<'a> {
ext: &'a mut evm::ExtFace
ext: &'a mut evm::Ext
}
impl<'a> ExtAdapter<'a> {
fn new(ext: &'a mut evm::ExtFace) -> Self {
fn new(ext: &'a mut evm::Ext) -> Self {
ExtAdapter {
ext: ext
}
@ -264,10 +264,28 @@ impl From<evmjit::ReturnCode> for evm::ReturnCode {
pub struct JitEvm;
impl evm::Evm for JitEvm {
fn exec(&self, data: evm::RuntimeData, ext: &mut evm::ExtFace) -> evm::ReturnCode {
fn exec(&self, ext: &mut evm::Ext) -> evm::ReturnCode {
// Dirty hack. This is unsafe, but we interact with ffi, so it's justified.
let ext_adapter: ExtAdapter<'static> = unsafe { ::std::mem::transmute(ExtAdapter::new(ext)) };
let mut ext_handle = evmjit::ExtHandle::new(ext_adapter);
let mut data = evm::RuntimeData::new();
let params = ext.params();
data.gas = params.gas;
data.gas_price = params.gas_price;
data.call_data = params.data.clone();
data.address = params.address.clone();
data.caller = params.sender.clone();
data.origin = params.origin.clone();
data.call_value = params.value;
data.code = params.code.clone();
// TODO:
data.coinbase = Address::new();
data.difficulty = U256::zero();
data.gas_limit = U256::zero();
data.number = 0;
data.timestamp = 0;
let mut context = unsafe { evmjit::ContextHandle::new(data.into_jit(), &mut ext_handle) };
From::from(context.exec())
}
@ -339,19 +357,19 @@ mod tests {
#[test]
fn test_ext_add() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&address, &H256::new()),
@ -361,19 +379,19 @@ mod tests {
#[test]
fn test_ext_sha3_0() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "6000600020600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "6000600020600055".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&address, &H256::new()),
@ -383,19 +401,19 @@ mod tests {
#[test]
fn test_ext_sha3_1() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "6005600420600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "6005600420600055".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&address, &H256::new()),
@ -405,43 +423,43 @@ mod tests {
#[test]
fn test_origin() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.origin = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "32600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.origin = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "32600055".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
}
#[test]
fn test_caller() {
fn test_sender() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "32600055".from_hex().unwrap();
data.code = "33600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "32600055".from_hex().unwrap();
params.code = "33600055".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
@ -449,11 +467,11 @@ mod tests {
#[test]
fn test_extcode_copy0() {
// 33 - caller
// 33 - sender
// 3b - extcodesize
// 60 00 - push 0
// 60 00 - push 0
// 33 - caller
// 33 - sender
// 3c - extcodecopy
// 60 00 - push 0
// 51 - load word from memory
@ -461,40 +479,40 @@ mod tests {
// 55 - sstore
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let caller = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
let address_code = "333b60006000333c600051600055".from_hex().unwrap();
let caller_code = "6005600055".from_hex().unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = caller.clone();
data.origin = caller.clone();
data.gas = U256::from(0x174876e800u64);
data.code = address_code.clone();
let sender_code = "6005600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.sender = sender.clone();
params.origin = sender.clone();
params.gas = U256::from(0x174876e800u64);
params.code = address_code.clone();
let mut state = State::new_temp();
state.set_code(&address, address_code);
state.set_code(&caller, caller_code);
state.set_code(&sender, sender_code);
let info = EnvInfo::new();
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, caller.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&caller, &H256::new()),
assert_eq!(state.storage_at(&address, &H256::new()),
H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap());
}
#[test]
fn test_balance() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "3331600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "3331600055".from_hex().unwrap();
let mut state = State::new_temp();
state.add_balance(&address, &U256::from(0x10));
@ -502,9 +520,9 @@ mod tests {
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
@ -513,18 +531,17 @@ mod tests {
#[test]
fn test_empty_log() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "60006000a0".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "60006000a0".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
let logs = ext.logs();
assert_eq!(logs.len(), 1);
let log = &logs[0];
@ -538,24 +555,24 @@ mod tests {
// 60 ff - push ff
// 60 00 - push 00
// 53 - mstore
// 33 - caller
// 33 - sender
// 60 20 - push 20
// 60 00 - push 0
// a1 - log with 1 topic
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "60ff6000533360206000a1".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.sender = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "60ff6000533360206000a1".from_hex().unwrap();
let mut state = State::new_temp();
let info = EnvInfo::new();
let engine = TestEngine::new();
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
let logs = ext.logs();
assert_eq!(logs.len(), 1);
let log = &logs[0];
@ -570,11 +587,10 @@ mod tests {
#[test]
fn test_blockhash() {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
let mut data = RuntimeData::new();
data.address = address.clone();
data.caller = address.clone();
data.gas = U256::from(0x174876e800u64);
data.code = "600040600055".from_hex().unwrap();
let mut params = EvmParams::new_create();
params.address = address.clone();
params.gas = U256::from(0x174876e800u64);
params.code = "600040600055".from_hex().unwrap();
let mut state = State::new_temp();
let mut info = EnvInfo::new();
@ -583,9 +599,9 @@ mod tests {
let engine = TestEngine::new();
{
let mut ext = Ext::new(&mut state, &info, &engine, 0, address.clone());
let mut ext = Executive::new_from_params(&mut state, &info, &engine, params);
let evm = JitEvm;
assert_eq!(evm.exec(data, &mut ext), ReturnCode::Stop);
assert_eq!(evm.exec(&mut ext), ReturnCode::Stop);
}
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));

View File

@ -6,12 +6,14 @@ pub mod evm;
pub mod vmfactory;
pub mod logentry;
pub mod executive;
pub mod params;
#[cfg(feature = "jit" )]
mod jit;
pub use self::evm::{Evm, ReturnCode};
pub use self::ext::{ExtFace, Ext};
pub use self::ext::{Ext};
pub use self::runtime_data::RuntimeData;
pub use self::logentry::LogEntry;
pub use self::vmfactory::VmFactory;
pub use self::executive::Executive;
pub use self::params::{EvmParams, ParamsKind};

51
src/evm/params.rs Normal file
View File

@ -0,0 +1,51 @@
use util::hash::*;
use util::uint::*;
use util::bytes::*;
#[derive(Eq, PartialEq, Clone)]
pub enum ParamsKind {
Create,
Call
}
#[derive(Clone)]
pub struct EvmParams {
pub address: Address,
pub sender: Address,
pub origin: Address,
pub gas: U256,
pub gas_price: U256,
pub value: U256,
pub code: Bytes,
pub data: Bytes,
pub kind: ParamsKind
}
impl EvmParams {
pub fn new(kind: ParamsKind) -> EvmParams {
EvmParams {
address: Address::new(),
sender: Address::new(),
origin: Address::new(),
gas: U256::zero(),
gas_price: U256::zero(),
value: U256::zero(),
code: vec![],
data: vec![],
kind: kind
}
}
pub fn new_call() -> EvmParams {
EvmParams::new(ParamsKind::Call)
}
pub fn new_create() -> EvmParams {
EvmParams::new(ParamsKind::Create)
}
pub fn kind(&self) -> ParamsKind {
//TODO
ParamsKind::Create
}
}

View File

@ -3,6 +3,7 @@
use util::hash::*;
use util::uint::*;
// call_data
pub struct RuntimeData {
pub gas: U256,
pub gas_price: U256,