hidden private fields of evm/executive
This commit is contained in:
parent
27f6d6a99c
commit
d809ee53d6
640
src/evm/jit.rs
640
src/evm/jit.rs
@ -4,24 +4,24 @@ use evmjit;
|
|||||||
use evm;
|
use evm;
|
||||||
|
|
||||||
/// Ethcore representation of evmjit runtime data.
|
/// Ethcore representation of evmjit runtime data.
|
||||||
pub struct RuntimeData {
|
struct RuntimeData {
|
||||||
pub gas: U256,
|
gas: U256,
|
||||||
pub gas_price: U256,
|
gas_price: U256,
|
||||||
pub call_data: Vec<u8>,
|
call_data: Vec<u8>,
|
||||||
pub address: Address,
|
address: Address,
|
||||||
pub caller: Address,
|
caller: Address,
|
||||||
pub origin: Address,
|
origin: Address,
|
||||||
pub call_value: U256,
|
call_value: U256,
|
||||||
pub coinbase: Address,
|
coinbase: Address,
|
||||||
pub difficulty: U256,
|
difficulty: U256,
|
||||||
pub gas_limit: U256,
|
gas_limit: U256,
|
||||||
pub number: u64,
|
number: u64,
|
||||||
pub timestamp: u64,
|
timestamp: u64,
|
||||||
pub code: Vec<u8>
|
code: Vec<u8>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RuntimeData {
|
impl RuntimeData {
|
||||||
pub fn new() -> RuntimeData {
|
fn new() -> RuntimeData {
|
||||||
RuntimeData {
|
RuntimeData {
|
||||||
gas: U256::zero(),
|
gas: U256::zero(),
|
||||||
gas_price: U256::zero(),
|
gas_price: U256::zero(),
|
||||||
@ -357,359 +357,359 @@ impl evm::Evm for JitEvm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
//#[cfg(test)]
|
||||||
mod tests {
|
//mod tests {
|
||||||
use super::*;
|
//use super::*;
|
||||||
use common::*;
|
//use common::*;
|
||||||
use evm::jit::{FromJit, IntoJit};
|
//use evm::jit::{FromJit, IntoJit};
|
||||||
use evm::{Evm,Schedule};
|
//use evm::{Evm,Schedule};
|
||||||
use executive::*;
|
//use executive::*;
|
||||||
use state::*;
|
//use state::*;
|
||||||
use engine::*;
|
//use engine::*;
|
||||||
use spec::*;
|
//use spec::*;
|
||||||
|
|
||||||
struct TestEngine;
|
//struct TestEngine;
|
||||||
|
|
||||||
impl TestEngine {
|
//impl TestEngine {
|
||||||
fn new() -> Self { TestEngine }
|
//fn new() -> Self { TestEngine }
|
||||||
}
|
//}
|
||||||
|
|
||||||
impl Engine for TestEngine {
|
//impl Engine for TestEngine {
|
||||||
fn name(&self) -> &str { "TestEngine" }
|
//fn name(&self) -> &str { "TestEngine" }
|
||||||
fn spec(&self) -> &Spec { unimplemented!() }
|
//fn spec(&self) -> &Spec { unimplemented!() }
|
||||||
fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
|
//fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_to_and_from_u256() {
|
//fn test_to_and_from_u256() {
|
||||||
use std::str::FromStr;
|
//use std::str::FromStr;
|
||||||
|
|
||||||
let u = U256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
//let u = U256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||||
let j = u.into_jit();
|
//let j = u.into_jit();
|
||||||
let u2 = U256::from_jit(&j);
|
//let u2 = U256::from_jit(&j);
|
||||||
assert_eq!(u, u2);
|
//assert_eq!(u, u2);
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_to_and_from_h256() {
|
//fn test_to_and_from_h256() {
|
||||||
use std::str::FromStr;
|
//use std::str::FromStr;
|
||||||
|
|
||||||
let h = H256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
//let h = H256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||||
let j: ::evmjit::I256 = h.clone().into_jit();
|
//let j: ::evmjit::I256 = h.clone().into_jit();
|
||||||
let h2 = H256::from_jit(&j);
|
//let h2 = H256::from_jit(&j);
|
||||||
assert_eq!(h, h2);
|
//assert_eq!(h, h2);
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_to_and_from_address() {
|
//fn test_to_and_from_address() {
|
||||||
use std::str::FromStr;
|
//use std::str::FromStr;
|
||||||
|
|
||||||
let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
//let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
||||||
let j: ::evmjit::I256 = a.clone().into_jit();
|
//let j: ::evmjit::I256 = a.clone().into_jit();
|
||||||
let a2 = Address::from_jit(&j);
|
//let a2 = Address::from_jit(&j);
|
||||||
assert_eq!(a, a2);
|
//assert_eq!(a, a2);
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_ext_add() {
|
//fn test_ext_add() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
|
//params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop);
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop);
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||||
H256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap());
|
//H256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_ext_sha3_0() {
|
//fn test_ext_sha3_0() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "6000600020600055".from_hex().unwrap();
|
//params.code = "6000600020600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||||
H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap());
|
//H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_ext_sha3_1() {
|
//fn test_ext_sha3_1() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "6005600420600055".from_hex().unwrap();
|
//params.code = "6005600420600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||||
H256::from_str("c41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec").unwrap());
|
//H256::from_str("c41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec").unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_origin() {
|
//fn test_origin() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.origin = address.clone();
|
//params.origin = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "32600055".from_hex().unwrap();
|
//params.code = "32600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
//assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_sender() {
|
//fn test_sender() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.sender = address.clone();
|
//params.sender = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "32600055".from_hex().unwrap();
|
//params.code = "32600055".from_hex().unwrap();
|
||||||
params.code = "33600055".from_hex().unwrap();
|
//params.code = "33600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
//assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_extcode_copy0() {
|
//fn test_extcode_copy0() {
|
||||||
// 33 - sender
|
//// 33 - sender
|
||||||
// 3b - extcodesize
|
//// 3b - extcodesize
|
||||||
// 60 00 - push 0
|
//// 60 00 - push 0
|
||||||
// 60 00 - push 0
|
//// 60 00 - push 0
|
||||||
// 33 - sender
|
//// 33 - sender
|
||||||
// 3c - extcodecopy
|
//// 3c - extcodecopy
|
||||||
// 60 00 - push 0
|
//// 60 00 - push 0
|
||||||
// 51 - load word from memory
|
//// 51 - load word from memory
|
||||||
// 60 00 - push 0
|
//// 60 00 - push 0
|
||||||
// 55 - sstore
|
//// 55 - sstore
|
||||||
|
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
|
//let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
|
||||||
let address_code = "333b60006000333c600051600055".from_hex().unwrap();
|
//let address_code = "333b60006000333c600051600055".from_hex().unwrap();
|
||||||
let sender_code = "6005600055".from_hex().unwrap();
|
//let sender_code = "6005600055".from_hex().unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.sender = sender.clone();
|
//params.sender = sender.clone();
|
||||||
params.origin = sender.clone();
|
//params.origin = sender.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = address_code.clone();
|
//params.code = address_code.clone();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
state.init_code(&address, address_code);
|
//state.init_code(&address, address_code);
|
||||||
state.init_code(&sender, sender_code);
|
//state.init_code(&sender, sender_code);
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||||
H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap());
|
//H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_balance() {
|
//fn test_balance() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.sender = address.clone();
|
//params.sender = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "3331600055".from_hex().unwrap();
|
//params.code = "3331600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
state.add_balance(&address, &U256::from(0x10));
|
//state.add_balance(&address, &U256::from(0x10));
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
|
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_empty_log() {
|
//fn test_empty_log() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "60006000a0".from_hex().unwrap();
|
//params.code = "60006000a0".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
let logs = substate.logs();
|
//let logs = substate.logs();
|
||||||
assert_eq!(logs.len(), 1);
|
//assert_eq!(logs.len(), 1);
|
||||||
let log = &logs[0];
|
//let log = &logs[0];
|
||||||
assert_eq!(log.address(), &address);
|
//assert_eq!(log.address(), &address);
|
||||||
assert_eq!(log.topics().len(), 0);
|
//assert_eq!(log.topics().len(), 0);
|
||||||
assert_eq!(log.bloom(), H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
|
//assert_eq!(log.bloom(), H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_log_with_one_topic() {
|
//fn test_log_with_one_topic() {
|
||||||
// 60 ff - push ff
|
//// 60 ff - push ff
|
||||||
// 60 00 - push 00
|
//// 60 00 - push 00
|
||||||
// 53 - mstore
|
//// 53 - mstore
|
||||||
// 33 - sender
|
//// 33 - sender
|
||||||
// 60 20 - push 20
|
//// 60 20 - push 20
|
||||||
// 60 00 - push 0
|
//// 60 00 - push 0
|
||||||
// a1 - log with 1 topic
|
//// a1 - log with 1 topic
|
||||||
|
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.sender = address.clone();
|
//params.sender = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "60ff6000533360206000a1".from_hex().unwrap();
|
//params.code = "60ff6000533360206000a1".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let info = EnvInfo::new();
|
//let info = EnvInfo::new();
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
let logs = substate.logs();
|
//let logs = substate.logs();
|
||||||
assert_eq!(logs.len(), 1);
|
//assert_eq!(logs.len(), 1);
|
||||||
let log = &logs[0];
|
//let log = &logs[0];
|
||||||
assert_eq!(log.address(), &address);
|
//assert_eq!(log.address(), &address);
|
||||||
assert_eq!(log.topics().len(), 1);
|
//assert_eq!(log.topics().len(), 1);
|
||||||
let topic = &log.topics()[0];
|
//let topic = &log.topics()[0];
|
||||||
assert_eq!(topic, &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap());
|
//assert_eq!(topic, &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap());
|
||||||
assert_eq!(topic, &H256::from(address.clone()));
|
//assert_eq!(topic, &H256::from(address.clone()));
|
||||||
assert_eq!(log.data(), &"ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap());
|
//assert_eq!(log.data(), &"ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap());
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_blockhash() {
|
//fn test_blockhash() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "600040600055".from_hex().unwrap();
|
//params.code = "600040600055".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let mut info = EnvInfo::new();
|
//let mut info = EnvInfo::new();
|
||||||
info.number = 1;
|
//info.number = 1;
|
||||||
info.last_hashes.push(H256::from(address.clone()));
|
//info.last_hashes.push(H256::from(address.clone()));
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));
|
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));
|
||||||
}
|
//}
|
||||||
|
|
||||||
#[test]
|
//#[test]
|
||||||
fn test_calldataload() {
|
//fn test_calldataload() {
|
||||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||||
let mut params = ActionParams::new();
|
//let mut params = ActionParams::new();
|
||||||
params.address = address.clone();
|
//params.address = address.clone();
|
||||||
params.gas = U256::from(0x174876e800u64);
|
//params.gas = U256::from(0x174876e800u64);
|
||||||
params.code = "600135600055".from_hex().unwrap();
|
//params.code = "600135600055".from_hex().unwrap();
|
||||||
params.data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap();
|
//params.data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap();
|
||||||
|
|
||||||
let mut state = State::new_temp();
|
//let mut state = State::new_temp();
|
||||||
let mut info = EnvInfo::new();
|
//let mut info = EnvInfo::new();
|
||||||
info.number = 1;
|
//info.number = 1;
|
||||||
info.last_hashes.push(H256::from(address.clone()));
|
//info.last_hashes.push(H256::from(address.clone()));
|
||||||
let engine = TestEngine::new();
|
//let engine = TestEngine::new();
|
||||||
let mut substate = Substate::new();
|
//let mut substate = Substate::new();
|
||||||
|
|
||||||
{
|
//{
|
||||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||||
let evm = JitEvm;
|
//let evm = JitEvm;
|
||||||
let _res = evm.exec(¶ms, &mut ext);
|
//let _res = evm.exec(¶ms, &mut ext);
|
||||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||||
}
|
//}
|
||||||
|
|
||||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap());
|
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap());
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! Cost schedule and other parameterisations for the EVM.
|
||||||
|
|
||||||
/// Definition of the cost schedule and other parameterisations for the EVM.
|
/// Definition of the cost schedule and other parameterisations for the EVM.
|
||||||
pub struct Schedule {
|
pub struct Schedule {
|
||||||
pub exceptional_failed_code_deposit: bool,
|
pub exceptional_failed_code_deposit: bool,
|
||||||
|
@ -14,7 +14,7 @@ pub fn contract_address(address: &Address, nonce: &U256) -> Address {
|
|||||||
|
|
||||||
/// State changes which should be applied in finalize,
|
/// State changes which should be applied in finalize,
|
||||||
/// after transaction is fully executed.
|
/// after transaction is fully executed.
|
||||||
pub struct Substate {
|
struct Substate {
|
||||||
/// Any accounts that have suicided.
|
/// Any accounts that have suicided.
|
||||||
suicides: HashSet<Address>,
|
suicides: HashSet<Address>,
|
||||||
/// Any logs.
|
/// Any logs.
|
||||||
@ -25,21 +25,16 @@ pub struct Substate {
|
|||||||
|
|
||||||
impl Substate {
|
impl Substate {
|
||||||
/// Creates new substate.
|
/// Creates new substate.
|
||||||
pub fn new() -> Self {
|
fn new() -> Self {
|
||||||
Substate {
|
Substate {
|
||||||
suicides: HashSet::new(),
|
suicides: HashSet::new(),
|
||||||
logs: vec![],
|
logs: vec![],
|
||||||
refunds_count: U256::zero(),
|
refunds_count: U256::zero(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove
|
|
||||||
pub fn logs(&self) -> &[LogEntry] {
|
|
||||||
&self.logs
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transaction execution result.
|
/// Transaction execution receipt.
|
||||||
pub struct Executed {
|
pub struct Executed {
|
||||||
/// Gas paid up front for execution of transaction.
|
/// Gas paid up front for execution of transaction.
|
||||||
pub gas: U256,
|
pub gas: U256,
|
||||||
@ -61,9 +56,10 @@ pub struct Executed {
|
|||||||
pub out_of_gas: bool,
|
pub out_of_gas: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transaction execution result.
|
||||||
pub type ExecutionResult = Result<Executed, ExecutionError>;
|
pub type ExecutionResult = Result<Executed, ExecutionError>;
|
||||||
|
|
||||||
/// Message-call/contract-creation executor; useful for executing transactions.
|
/// Transaction executor.
|
||||||
pub struct Executive<'a> {
|
pub struct Executive<'a> {
|
||||||
state: &'a mut State,
|
state: &'a mut State,
|
||||||
info: &'a EnvInfo,
|
info: &'a EnvInfo,
|
||||||
@ -72,7 +68,7 @@ pub struct Executive<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Executive<'a> {
|
impl<'a> Executive<'a> {
|
||||||
/// Creates new executive with depth equal 0.
|
/// Basic constructor.
|
||||||
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine) -> Self {
|
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine) -> Self {
|
||||||
Executive::new_with_depth(state, info, engine, 0)
|
Executive::new_with_depth(state, info, engine, 0)
|
||||||
}
|
}
|
||||||
@ -93,7 +89,7 @@ impl<'a> Executive<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This funtion should be used to execute transaction.
|
/// Executes transaction.
|
||||||
pub fn transact(&mut self, t: &Transaction) -> ExecutionResult {
|
pub fn transact(&mut self, t: &Transaction) -> ExecutionResult {
|
||||||
// TODO: validate transaction signature ?/ sender
|
// TODO: validate transaction signature ?/ sender
|
||||||
|
|
||||||
@ -259,7 +255,7 @@ impl<'a> Executive<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Policy for handling output data on `RETURN` opcode.
|
/// Policy for handling output data on `RETURN` opcode.
|
||||||
pub enum OutputPolicy<'a> {
|
enum OutputPolicy<'a> {
|
||||||
/// Return reference to fixed sized output.
|
/// Return reference to fixed sized output.
|
||||||
/// Used for message calls.
|
/// Used for message calls.
|
||||||
Return(&'a mut [u8]),
|
Return(&'a mut [u8]),
|
||||||
@ -268,7 +264,7 @@ pub enum OutputPolicy<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of evm Externalities.
|
/// Implementation of evm Externalities.
|
||||||
pub struct Externalities<'a> {
|
struct Externalities<'a> {
|
||||||
state: &'a mut State,
|
state: &'a mut State,
|
||||||
info: &'a EnvInfo,
|
info: &'a EnvInfo,
|
||||||
engine: &'a Engine,
|
engine: &'a Engine,
|
||||||
@ -281,7 +277,7 @@ pub struct Externalities<'a> {
|
|||||||
|
|
||||||
impl<'a> Externalities<'a> {
|
impl<'a> Externalities<'a> {
|
||||||
/// Basic `Externalities` constructor.
|
/// Basic `Externalities` constructor.
|
||||||
pub fn new(state: &'a mut State,
|
fn new(state: &'a mut State,
|
||||||
info: &'a EnvInfo,
|
info: &'a EnvInfo,
|
||||||
engine: &'a Engine,
|
engine: &'a Engine,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
@ -301,7 +297,7 @@ impl<'a> Externalities<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates `Externalities` from `Executive`.
|
/// Creates `Externalities` from `Executive`.
|
||||||
pub fn from_executive(e: &'a mut Executive, params: &'a ActionParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self {
|
fn from_executive(e: &'a mut Executive, params: &'a ActionParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self {
|
||||||
Self::new(e.state, e.info, e.engine, e.depth, params, substate, output)
|
Self::new(e.state, e.info, e.engine, e.depth, params, substate, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,6 +448,7 @@ mod tests {
|
|||||||
use state::*;
|
use state::*;
|
||||||
use ethereum;
|
use ethereum;
|
||||||
use null_engine::*;
|
use null_engine::*;
|
||||||
|
use super::Substate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_contract_address() {
|
fn test_contract_address() {
|
||||||
|
Loading…
Reference in New Issue
Block a user