Revert "[Trace] Distinguish between `create` and `create2` (#11311)" (#11427)

This reverts commit 87e1080581.
This commit is contained in:
David 2020-01-30 15:21:29 +01:00 committed by GitHub
parent bf44f024c6
commit 5d4993b0f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 148 additions and 290 deletions

View File

@ -42,7 +42,7 @@ use machine::{
Machine, Machine,
executed_block::ExecutedBlock, executed_block::ExecutedBlock,
}; };
use vm::{EnvInfo, Schedule, ActionType, ActionValue}; use vm::{EnvInfo, Schedule, CallType, ActionValue};
use crate::signer::EngineSigner; use crate::signer::EngineSigner;
@ -82,7 +82,7 @@ pub fn default_system_or_code_call<'a>(machine: &'a Machine, block: &'a mut Exec
Some(ActionValue::Apparent(U256::zero())), Some(ActionValue::Apparent(U256::zero())),
U256::max_value(), U256::max_value(),
Some(data), Some(data),
Some(ActionType::StaticCall), Some(CallType::StaticCall),
) )
}, },
}; };

View File

@ -33,7 +33,7 @@ use ethereum_types::{U256, U512, H256, Address, BigEndianHash};
use vm::{ use vm::{
self, ActionParams, ParamsType, ActionValue, ActionType, MessageCallResult, self, ActionParams, ParamsType, ActionValue, CallType, MessageCallResult,
ContractCreateResult, CreateContractAddress, ReturnData, GasLeft, Schedule, ContractCreateResult, CreateContractAddress, ReturnData, GasLeft, Schedule,
TrapKind, TrapError TrapKind, TrapError
}; };
@ -133,8 +133,8 @@ struct InterpreterParams {
pub value: ActionValue, pub value: ActionValue,
/// Input data. /// Input data.
pub data: Option<Bytes>, pub data: Option<Bytes>,
/// Type of action /// Type of call
pub action_type: ActionType, pub call_type: CallType,
/// Param types encoding /// Param types encoding
pub params_type: ParamsType, pub params_type: ParamsType,
} }
@ -152,7 +152,7 @@ impl From<ActionParams> for InterpreterParams {
gas_price: params.gas_price, gas_price: params.gas_price,
value: params.value, value: params.value,
data: params.data, data: params.data,
action_type: params.action_type, call_type: params.call_type,
params_type: params.params_type, params_type: params.params_type,
} }
} }
@ -532,9 +532,7 @@ impl<Cost: CostType> Interpreter<Cost> {
let init_size = self.stack.pop_back(); let init_size = self.stack.pop_back();
let address_scheme = match instruction { let address_scheme = match instruction {
instructions::CREATE => CreateContractAddress::FromSenderAndNonce, instructions::CREATE => CreateContractAddress::FromSenderAndNonce,
instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash( instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash(BigEndianHash::from_uint(&self.stack.pop_back())),
BigEndianHash::from_uint(&self.stack.pop_back())
),
_ => unreachable!("instruction can only be CREATE/CREATE2 checked above; qed"), _ => unreachable!("instruction can only be CREATE/CREATE2 checked above; qed"),
}; };
@ -555,14 +553,7 @@ impl<Cost: CostType> Interpreter<Cost> {
let contract_code = self.mem.read_slice(init_off, init_size); let contract_code = self.mem.read_slice(init_off, init_size);
let create_result = ext.create( let create_result = ext.create(&create_gas.as_u256(), &endowment, contract_code, &self.params.code_version, address_scheme, true);
&create_gas.as_u256(),
&endowment,
contract_code,
&self.params.code_version,
address_scheme,
true,
);
return match create_result { return match create_result {
Ok(ContractCreateResult::Created(address, gas_left)) => { Ok(ContractCreateResult::Created(address, gas_left)) => {
self.stack.push(address_to_u256(address)); self.stack.push(address_to_u256(address));
@ -616,14 +607,14 @@ impl<Cost: CostType> Interpreter<Cost> {
return Err(vm::Error::MutableCallInStaticContext); return Err(vm::Error::MutableCallInStaticContext);
} }
let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed"); let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed");
(&self.params.address, &code_address, has_balance, ActionType::Call) (&self.params.address, &code_address, has_balance, CallType::Call)
}, },
instructions::CALLCODE => { instructions::CALLCODE => {
let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed"); let has_balance = ext.balance(&self.params.address)? >= value.expect("value set for all but delegate call; qed");
(&self.params.address, &self.params.address, has_balance, ActionType::CallCode) (&self.params.address, &self.params.address, has_balance, CallType::CallCode)
}, },
instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, ActionType::DelegateCall), instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, CallType::DelegateCall),
instructions::STATICCALL => (&self.params.address, &code_address, true, ActionType::StaticCall), instructions::STATICCALL => (&self.params.address, &code_address, true, CallType::StaticCall),
_ => panic!(format!("Unexpected instruction {:?} in CALL branch.", instruction)) _ => panic!(format!("Unexpected instruction {:?} in CALL branch.", instruction))
}; };

View File

@ -47,7 +47,7 @@ mod instructions;
mod tests; mod tests;
pub use vm::{ pub use vm::{
Schedule, CleanDustMode, EnvInfo, ActionType, ActionParams, Ext, Schedule, CleanDustMode, EnvInfo, CallType, ActionParams, Ext,
ContractCreateResult, MessageCallResult, CreateContractAddress, ContractCreateResult, MessageCallResult, CreateContractAddress,
GasLeft, ReturnData GasLeft, ReturnData
}; };

View File

@ -276,6 +276,7 @@ mod tests {
test_helpers::{get_temp_state, get_temp_state_db} test_helpers::{get_temp_state, get_temp_state_db}
}; };
use ethtrie; use ethtrie;
use evm::CallType;
use machine::Machine; use machine::Machine;
use pod::{self, PodAccount, PodState}; use pod::{self, PodAccount, PodState};
use rustc_hex::FromHex; use rustc_hex::FromHex;
@ -323,7 +324,6 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 77412.into(), gas: 77412.into(),
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
creation_method: Some(trace::CreationMethod::Create),
}), }),
result: trace::Res::Create(trace::CreateResult { result: trace::Res::Create(trace::CreateResult {
gas_used: U256::from(3224), gas_used: U256::from(3224),
@ -381,7 +381,6 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 78792.into(), gas: 78792.into(),
init: vec![91, 96, 0, 86], init: vec![91, 96, 0, 86],
creation_method: Some(trace::CreationMethod::Create),
}), }),
result: trace::Res::FailedCreate(TraceError::OutOfGas), result: trace::Res::FailedCreate(TraceError::OutOfGas),
subtraces: 0 subtraces: 0
@ -420,7 +419,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(3), gas_used: U256::from(3),
@ -461,7 +460,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(0), gas_used: U256::from(0),
@ -502,7 +501,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 79_000.into(), gas: 79_000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(3000), gas_used: U256::from(3000),
@ -544,7 +543,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(3_721), // in post-eip150 gas_used: U256::from(3_721), // in post-eip150
@ -588,7 +587,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 724.into(), // in post-eip150 gas_used: 724.into(), // in post-eip150
@ -603,7 +602,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 4096.into(), gas: 4096.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::CallCode), call_type: CallType::CallCode,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 3.into(), gas_used: 3.into(),
@ -647,7 +646,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(736), // in post-eip150 gas_used: U256::from(736), // in post-eip150
@ -662,7 +661,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 32768.into(), gas: 32768.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::DelegateCall), call_type: CallType::DelegateCall,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 18.into(), gas_used: 18.into(),
@ -703,7 +702,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::FailedCall(TraceError::OutOfGas), result: trace::Res::FailedCall(TraceError::OutOfGas),
subtraces: 0, subtraces: 0,
@ -745,7 +744,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(69), gas_used: U256::from(69),
@ -760,7 +759,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 78934.into(), gas: 78934.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(3), gas_used: U256::from(3),
@ -802,7 +801,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(31761), gas_used: U256::from(31761),
@ -817,7 +816,7 @@ mod tests {
value: 69.into(), value: 69.into(),
gas: 2300.into(), gas: 2300.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult::default()), result: trace::Res::Call(trace::CallResult::default()),
}]; }];
@ -856,7 +855,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(31761), gas_used: U256::from(31761),
@ -899,7 +898,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(79_000), gas_used: U256::from(79_000),
@ -914,7 +913,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 78934.into(), gas: 78934.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::FailedCall(TraceError::OutOfGas), result: trace::Res::FailedCall(TraceError::OutOfGas),
}]; }];
@ -955,7 +954,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(135), gas_used: U256::from(135),
@ -970,7 +969,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 78934.into(), gas: 78934.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(69), gas_used: U256::from(69),
@ -985,7 +984,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 78868.into(), gas: 78868.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(3), gas_used: U256::from(3),
@ -1030,7 +1029,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(79_000), gas_used: U256::from(79_000),
@ -1045,7 +1044,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 78934.into(), gas: 78934.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::FailedCall(TraceError::OutOfGas), result: trace::Res::FailedCall(TraceError::OutOfGas),
}, FlatTrace { }, FlatTrace {
@ -1056,7 +1055,7 @@ mod tests {
to: Address::from_low_u64_be(0xc), to: Address::from_low_u64_be(0xc),
value: 0.into(), value: 0.into(),
gas: 78868.into(), gas: 78868.into(),
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
input: vec![], input: vec![],
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
@ -1100,7 +1099,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 79000.into(), gas: 79000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 3.into(), gas_used: 3.into(),

View File

@ -26,7 +26,7 @@ use rlp::RlpStream;
use log::trace; use log::trace;
use account_state::{Backend as StateBackend, State, CleanupMode}; use account_state::{Backend as StateBackend, State, CleanupMode};
use evm::{ActionType, Finalize, FinalizationResult}; use evm::{CallType, Finalize, FinalizationResult};
use vm::{ use vm::{
self, EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams, self, EnvInfo, CreateContractAddress, ReturnData, CleanDustMode, ActionParams,
ActionValue, Schedule, TrapError, ResumeCall, ResumeCreate ActionValue, Schedule, TrapError, ResumeCall, ResumeCreate
@ -241,7 +241,7 @@ impl<'a> CallCreateExecutive<'a> {
trace!("Executive::call(params={:?}) self.env_info={:?}, parent_static={}", params, info, parent_static_flag); trace!("Executive::call(params={:?}) self.env_info={:?}, parent_static={}", params, info, parent_static_flag);
let gas = params.gas; let gas = params.gas;
let static_flag = parent_static_flag || params.action_type == ActionType::StaticCall; let static_flag = parent_static_flag || params.call_type == CallType::StaticCall;
// if destination is builtin, try to execute it // if destination is builtin, try to execute it
let kind = if let Some(builtin) = machine.builtin(&params.code_address, info.number) { let kind = if let Some(builtin) = machine.builtin(&params.code_address, info.number) {
@ -298,7 +298,7 @@ impl<'a> CallCreateExecutive<'a> {
} }
} else { } else {
if (static_flag && if (static_flag &&
(params.action_type == ActionType::StaticCall || params.action_type == ActionType::Call)) && (params.call_type == CallType::StaticCall || params.call_type == CallType::Call)) &&
params.value.value() > U256::zero() params.value.value() > U256::zero()
{ {
return Err(vm::Error::MutableCallInStaticContext); return Err(vm::Error::MutableCallInStaticContext);
@ -909,7 +909,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
code: Some(Arc::new(t.data.clone())), code: Some(Arc::new(t.data.clone())),
code_version: schedule.latest_version, code_version: schedule.latest_version,
data: None, data: None,
action_type: ActionType::Create, call_type: CallType::None,
params_type: vm::ParamsType::Embedded, params_type: vm::ParamsType::Embedded,
}; };
let res = self.create(params, &mut substate, &mut tracer, &mut vm_tracer); let res = self.create(params, &mut substate, &mut tracer, &mut vm_tracer);
@ -932,7 +932,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
code_hash: self.state.code_hash(address)?, code_hash: self.state.code_hash(address)?,
code_version: self.state.code_version(address)?, code_version: self.state.code_version(address)?,
data: Some(t.data.clone()), data: Some(t.data.clone()),
action_type: ActionType::Call, call_type: CallType::Call,
params_type: vm::ParamsType::Separate, params_type: vm::ParamsType::Separate,
}; };
let res = self.call(params, &mut substate, &mut tracer, &mut vm_tracer); let res = self.call(params, &mut substate, &mut tracer, &mut vm_tracer);
@ -1236,7 +1236,7 @@ mod tests {
use parity_crypto::publickey::{Generator, Random}; use parity_crypto::publickey::{Generator, Random};
use evm::{Factory, evm_test, evm_test_ignore}; use evm::{Factory, evm_test, evm_test_ignore};
use macros::vec_into; use macros::vec_into;
use vm::{ActionParams, ActionValue, EnvInfo, CreateContractAddress}; use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress};
use ::trace::{ use ::trace::{
trace, trace,
FlatTrace, Tracer, NoopTracer, ExecutiveTracer, FlatTrace, Tracer, NoopTracer, ExecutiveTracer,
@ -1414,7 +1414,7 @@ mod tests {
params.gas = U256::from(100_000); params.gas = U256::from(100_000);
params.code = Some(Arc::new(code)); params.code = Some(Arc::new(code));
params.value = ActionValue::Transfer(U256::from(100)); params.value = ActionValue::Transfer(U256::from(100));
params.action_type = ActionType::Call; params.call_type = CallType::Call;
let mut state = get_temp_state(); let mut state = get_temp_state();
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
let info = EnvInfo::default(); let info = EnvInfo::default();
@ -1434,7 +1434,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 100_000.into(), gas: 100_000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call) call_type: CallType::Call
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 33021.into(), gas_used: 33021.into(),
@ -1449,7 +1449,7 @@ mod tests {
value: 1.into(), value: 1.into(),
gas: 66560.into(), gas: 66560.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call) call_type: CallType::Call
}), result: trace::Res::Call(trace::CallResult { }), result: trace::Res::Call(trace::CallResult {
gas_used: 600.into(), gas_used: 600.into(),
output: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 17, 133, 165, 197, 233, 252, 84, 97, 40, 8, 151, 126, 232, 245, 72, 178, 37, 141, 49] output: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 17, 133, 165, 197, 233, 252, 84, 97, 40, 8, 151, 126, 232, 245, 72, 178, 37, 141, 49]
@ -1498,7 +1498,7 @@ mod tests {
params.gas = U256::from(100_000); params.gas = U256::from(100_000);
params.code = Some(Arc::new(code)); params.code = Some(Arc::new(code));
params.value = ActionValue::Transfer(U256::from(100)); params.value = ActionValue::Transfer(U256::from(100));
params.action_type = ActionType::Call; params.call_type = CallType::Call;
let mut state = get_temp_state(); let mut state = get_temp_state();
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
let info = EnvInfo::default(); let info = EnvInfo::default();
@ -1524,7 +1524,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 100000.into(), gas: 100000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(55_248), gas_used: U256::from(55_248),
@ -1537,8 +1537,7 @@ mod tests {
from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(),
value: 23.into(), value: 23.into(),
gas: 67979.into(), gas: 67979.into(),
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85]
creation_method: Some(trace::CreationMethod::Create),
}), }),
result: trace::Res::Create(trace::CreateResult { result: trace::Res::Create(trace::CreateResult {
gas_used: U256::from(3224), gas_used: U256::from(3224),
@ -1615,7 +1614,7 @@ mod tests {
params.gas = U256::from(100_000); params.gas = U256::from(100_000);
params.code = Some(Arc::new(code)); params.code = Some(Arc::new(code));
params.value = ActionValue::Transfer(U256::from(100)); params.value = ActionValue::Transfer(U256::from(100));
params.action_type = ActionType::Call; params.call_type = CallType::Call;
let mut state = get_temp_state(); let mut state = get_temp_state();
state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap(); state.add_balance(&sender, &U256::from(100), CleanupMode::NoEmpty).unwrap();
let info = EnvInfo::default(); let info = EnvInfo::default();
@ -1641,7 +1640,7 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: 100_000.into(), gas: 100_000.into(),
input: vec![], input: vec![],
call_type: Some(trace::CallType::Call), call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(37_033), gas_used: U256::from(37_033),
@ -1654,8 +1653,7 @@ mod tests {
from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(),
value: 23.into(), value: 23.into(),
gas: 66_917.into(), gas: 66_917.into(),
init: vec![0x60, 0x01, 0x60, 0x00, 0xfd], init: vec![0x60, 0x01, 0x60, 0x00, 0xfd]
creation_method: Some(trace::CreationMethod::Create),
}), }),
result: trace::Res::FailedCreate(vm::Error::Reverted.into()), result: trace::Res::FailedCreate(vm::Error::Reverted.into()),
}]; }];
@ -1713,7 +1711,6 @@ mod tests {
value: 100.into(), value: 100.into(),
gas: params.gas, gas: params.gas,
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
creation_method: Some(trace::CreationMethod::Create),
}), }),
result: trace::Res::Create(trace::CreateResult { result: trace::Res::Create(trace::CreateResult {
gas_used: U256::from(3224), gas_used: U256::from(3224),

View File

@ -29,7 +29,7 @@ use common_types::{
}; };
use trace::{Tracer, VMTracer}; use trace::{Tracer, VMTracer};
use vm::{ use vm::{
self, ActionParams, ActionValue, EnvInfo, ActionType, Schedule, self, ActionParams, ActionValue, EnvInfo, CallType, Schedule,
Ext, ContractCreateResult, MessageCallResult, CreateContractAddress, Ext, ContractCreateResult, MessageCallResult, CreateContractAddress,
ReturnData, TrapKind ReturnData, TrapKind
}; };
@ -193,7 +193,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
code_hash, code_hash,
code_version, code_version,
data: Some(data.as_bytes().to_vec()), data: Some(data.as_bytes().to_vec()),
action_type: ActionType::Call, call_type: CallType::Call,
params_type: vm::ParamsType::Separate, params_type: vm::ParamsType::Separate,
}; };
@ -241,12 +241,6 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
} }
}; };
let create_type = match address_scheme {
CreateContractAddress::FromSenderAndNonce => ActionType::Create,
CreateContractAddress::FromSenderSaltAndCodeHash(_) => ActionType::Create2,
CreateContractAddress::FromSenderAndCodeHash => ActionType::Create2,
};
// prepare the params // prepare the params
let params = ActionParams { let params = ActionParams {
code_address: address.clone(), code_address: address.clone(),
@ -260,7 +254,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
code_hash, code_hash,
code_version: *parent_version, code_version: *parent_version,
data: None, data: None,
action_type: create_type, call_type: CallType::None,
params_type: vm::ParamsType::Embedded, params_type: vm::ParamsType::Embedded,
}; };
@ -291,7 +285,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
value: Option<U256>, value: Option<U256>,
data: &[u8], data: &[u8],
code_address: &Address, code_address: &Address,
call_type: ActionType, call_type: CallType,
trap: bool, trap: bool,
) -> ::std::result::Result<MessageCallResult, TrapKind> { ) -> ::std::result::Result<MessageCallResult, TrapKind> {
trace!(target: "externalities", "call"); trace!(target: "externalities", "call");
@ -317,7 +311,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
code_hash, code_hash,
code_version, code_version,
data: Some(data.to_vec()), data: Some(data.to_vec()),
action_type: call_type, call_type,
params_type: vm::ParamsType::Separate, params_type: vm::ParamsType::Separate,
}; };
@ -463,7 +457,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
mod tests { mod tests {
use std::str::FromStr; use std::str::FromStr;
use ethereum_types::{U256, Address}; use ethereum_types::{U256, Address};
use evm::{EnvInfo, Ext, ActionType}; use evm::{EnvInfo, Ext, CallType};
use account_state::State; use account_state::State;
use ethcore::test_helpers::get_temp_state; use ethcore::test_helpers::get_temp_state;
use trace::{NoopTracer, NoopVMTracer}; use trace::{NoopTracer, NoopVMTracer};
@ -597,7 +591,7 @@ mod tests {
Some("0000000000000000000000000000000000000000000000000000000000150000".parse::<U256>().unwrap()), Some("0000000000000000000000000000000000000000000000000000000000150000".parse::<U256>().unwrap()),
&[], &[],
&Address::zero(), &Address::zero(),
ActionType::Call, CallType::Call,
false, false,
).ok().unwrap(); ).ok().unwrap();
} }

View File

@ -34,7 +34,7 @@ use common_types::{
errors::{EngineError, EthcoreError as Error}, errors::{EngineError, EthcoreError as Error},
transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction}, transaction::{self, SYSTEM_ADDRESS, UNSIGNED_SENDER, UnverifiedTransaction, SignedTransaction},
}; };
use vm::{ActionType, ActionParams, ActionValue, ParamsType}; use vm::{CallType, ActionParams, ActionValue, ParamsType};
use vm::{EnvInfo, Schedule}; use vm::{EnvInfo, Schedule};
use account_state::CleanupMode; use account_state::CleanupMode;
@ -141,7 +141,7 @@ impl Machine {
value: Option<ActionValue>, value: Option<ActionValue>,
gas: U256, gas: U256,
data: Option<Vec<u8>>, data: Option<Vec<u8>>,
action_type: Option<ActionType>, call_type: Option<CallType>,
) -> Result<Vec<u8>, Error> { ) -> Result<Vec<u8>, Error> {
let env_info = { let env_info = {
let mut env_info = block.env_info(); let mut env_info = block.env_info();
@ -163,7 +163,7 @@ impl Machine {
code_hash, code_hash,
code_version: 0.into(), code_version: 0.into(),
data, data,
action_type: action_type.unwrap_or(ActionType::Call), call_type: call_type.unwrap_or(CallType::Call),
params_type: ParamsType::Separate, params_type: ParamsType::Separate,
}; };
let schedule = self.schedule(env_info.number); let schedule = self.schedule(env_info.number);

View File

@ -52,7 +52,7 @@ use pod::PodState;
use rlp::{Rlp, RlpStream}; use rlp::{Rlp, RlpStream};
use trace::{NoopTracer, NoopVMTracer}; use trace::{NoopTracer, NoopVMTracer};
use trie_vm_factories::Factories; use trie_vm_factories::Factories;
use vm::{EnvInfo, ActionType, ActionValue, ActionParams, ParamsType}; use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType};
use crate::{ use crate::{
Genesis, Genesis,
@ -163,7 +163,7 @@ fn run_constructors<T: Backend>(
value: ActionValue::Transfer(Default::default()), value: ActionValue::Transfer(Default::default()),
code: Some(Arc::new(constructor.clone())), code: Some(Arc::new(constructor.clone())),
data: None, data: None,
action_type: ActionType::Create, call_type: CallType::None,
params_type: ParamsType::Embedded, params_type: ParamsType::Embedded,
}; };

View File

@ -20,7 +20,7 @@ use super::test_common::*;
use account_state::{Backend as StateBackend, State}; use account_state::{Backend as StateBackend, State};
use evm::Finalize; use evm::Finalize;
use vm::{ use vm::{
self, ActionParams, ActionType, Schedule, Ext, self, ActionParams, CallType, Schedule, Ext,
ContractCreateResult, EnvInfo, MessageCallResult, ContractCreateResult, EnvInfo, MessageCallResult,
CreateContractAddress, ReturnData, CreateContractAddress, ReturnData,
}; };
@ -172,7 +172,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B>
value: Option<U256>, value: Option<U256>,
data: &[u8], data: &[u8],
_code_address: &Address, _code_address: &Address,
_call_type: ActionType, _call_type: CallType,
_trap: bool _trap: bool
) -> Result<MessageCallResult, vm::TrapKind> { ) -> Result<MessageCallResult, vm::TrapKind> {
self.callcreates.push(CallCreate { self.callcreates.push(CallCreate {

View File

@ -18,7 +18,7 @@
use std::sync::Arc; use std::sync::Arc;
use hash::keccak; use hash::keccak;
use vm::{EnvInfo, ActionParams, ActionValue, ActionType, ParamsType}; use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
use evm::Factory; use evm::Factory;
use machine::{ use machine::{
executive::Executive, executive::Executive,
@ -62,7 +62,7 @@ fn test_blockhash_eip210(factory: Factory) {
code_hash: Some(blockhash_contract_code_hash), code_hash: Some(blockhash_contract_code_hash),
code_version: 0.into(), code_version: 0.into(),
data: Some(H256::from_low_u64_be(i - 1).as_bytes().to_vec()), data: Some(H256::from_low_u64_be(i - 1).as_bytes().to_vec()),
action_type: ActionType::Call, call_type: CallType::Call,
params_type: ParamsType::Separate, params_type: ParamsType::Separate,
}; };
let schedule = machine.schedule(env_info.number); let schedule = machine.schedule(env_info.number);
@ -86,7 +86,7 @@ fn test_blockhash_eip210(factory: Factory) {
code_hash: Some(get_prev_hash_code_hash), code_hash: Some(get_prev_hash_code_hash),
code_version: 0.into(), code_version: 0.into(),
data: None, data: None,
action_type: ActionType::Call, call_type: CallType::Call,
params_type: ParamsType::Separate, params_type: ParamsType::Separate,
}; };
let schedule = machine.schedule(env_info.number); let schedule = machine.schedule(env_info.number);

View File

@ -374,12 +374,13 @@ mod tests {
use ethcore::test_helpers::new_db; use ethcore::test_helpers::new_db;
use ethereum_types::{H256, U256, Address}; use ethereum_types::{H256, U256, Address};
use evm::CallType;
use kvdb::DBTransaction; use kvdb::DBTransaction;
use crate::{ use crate::{
BlockNumber, Config, TraceDB, Database as TraceDatabase, ImportRequest, DatabaseExtras, BlockNumber, Config, TraceDB, Database as TraceDatabase, ImportRequest, DatabaseExtras,
Filter, LocalizedTrace, AddressesFilter, TraceError, Filter, LocalizedTrace, AddressesFilter, TraceError,
trace::{Call, CallType, Action, Res}, trace::{Call, Action, Res},
flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces} flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}
}; };
@ -464,7 +465,7 @@ mod tests {
value: 3.into(), value: 3.into(),
gas: 4.into(), gas: 4.into(),
input: vec![], input: vec![],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::FailedCall(TraceError::OutOfGas), result: Res::FailedCall(TraceError::OutOfGas),
}])]), }])]),
@ -486,7 +487,7 @@ mod tests {
value: 3.into(), value: 3.into(),
gas: 4.into(), gas: 4.into(),
input: vec![], input: vec![],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::FailedCall(TraceError::OutOfGas), result: Res::FailedCall(TraceError::OutOfGas),
}])]), }])]),
@ -505,7 +506,7 @@ mod tests {
value: U256::from(3), value: U256::from(3),
gas: U256::from(4), gas: U256::from(4),
input: vec![], input: vec![],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::FailedCall(TraceError::OutOfGas), result: Res::FailedCall(TraceError::OutOfGas),
trace_address: vec![], trace_address: vec![],

View File

@ -125,9 +125,10 @@ impl Filter {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ethereum_types::{Address, Bloom, BloomInput}; use ethereum_types::{Address, Bloom, BloomInput};
use evm::CallType;
use crate::{ use crate::{
Filter, AddressesFilter, TraceError, RewardType, Filter, AddressesFilter, TraceError, RewardType,
trace::{Action, Call, CallType, Res, Create, CreationMethod, CreateResult, Suicide, Reward}, trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward},
flat::FlatTrace, flat::FlatTrace,
}; };
@ -272,7 +273,7 @@ mod tests {
value: 3.into(), value: 3.into(),
gas: 4.into(), gas: 4.into(),
input: vec![0x5], input: vec![0x5],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::FailedCall(TraceError::OutOfGas), result: Res::FailedCall(TraceError::OutOfGas),
trace_address: vec![0].into_iter().collect(), trace_address: vec![0].into_iter().collect(),
@ -293,7 +294,6 @@ mod tests {
value: 3.into(), value: 3.into(),
gas: 4.into(), gas: 4.into(),
init: vec![0x5], init: vec![0x5],
creation_method: Some(CreationMethod::Create),
}), }),
result: Res::Create(CreateResult { result: Res::Create(CreateResult {
gas_used: 10.into(), gas_used: 10.into(),
@ -413,7 +413,6 @@ mod tests {
gas: 4.into(), gas: 4.into(),
init: vec![0x5], init: vec![0x5],
value: 3.into(), value: 3.into(),
creation_method: Some(CreationMethod::Create),
}), }),
result: Res::FailedCall(TraceError::BadInstruction), result: Res::FailedCall(TraceError::BadInstruction),
trace_address: vec![].into_iter().collect(), trace_address: vec![].into_iter().collect(),

View File

@ -123,8 +123,9 @@ mod tests {
use rlp::*; use rlp::*;
use crate::{ use crate::{
FlatBlockTraces, FlatTransactionTraces, FlatTrace, FlatBlockTraces, FlatTransactionTraces, FlatTrace,
trace::{Action, Res, CallResult, Call, CallType, Suicide, Reward, RewardType} trace::{Action, Res, CallResult, Call, Suicide, Reward, RewardType}
}; };
use evm::CallType;
#[test] #[test]
fn encode_flat_transaction_traces() { fn encode_flat_transaction_traces() {
@ -161,7 +162,7 @@ mod tests {
value: "3627e8f712373c0000".parse().unwrap(), value: "3627e8f712373c0000".parse().unwrap(),
gas: 0x03e8.into(), gas: 0x03e8.into(),
input: vec![], input: vec![],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::Call(CallResult { result: Res::Call(CallResult {
gas_used: 0.into(), gas_used: 0.into(),
@ -178,7 +179,7 @@ mod tests {
value: 0.into(), value: 0.into(),
gas: 0x010c78.into(), gas: 0x010c78.into(),
input: vec![0x41, 0xc0, 0xe1, 0xb5], input: vec![0x41, 0xc0, 0xe1, 0xb5],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::Call(CallResult { result: Res::Call(CallResult {
gas_used: 0x0127.into(), gas_used: 0x0127.into(),

View File

@ -16,13 +16,12 @@
//! Tracing data types. //! Tracing data types.
use std::convert::TryFrom;
use ethereum_types::{U256, Address, Bloom, BloomInput}; use ethereum_types::{U256, Address, Bloom, BloomInput};
use parity_bytes::Bytes; use parity_bytes::Bytes;
use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable}; use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable};
use rlp_derive::{RlpEncodable, RlpDecodable}; use rlp_derive::{RlpEncodable, RlpDecodable};
use vm::ActionParams; use vm::ActionParams;
use evm::ActionType; use evm::CallType;
use super::error::Error; use super::error::Error;
/// `Call` result. /// `Call` result.
@ -34,57 +33,6 @@ pub struct CallResult {
pub output: Bytes, pub output: Bytes,
} }
/// `Call` type. Distinguish between different types of contract interactions.
#[derive(Debug, Clone, PartialEq)]
pub enum CallType {
/// Call
Call,
/// Call code
CallCode,
/// Delegate call
DelegateCall,
/// Static call
StaticCall,
}
impl TryFrom<ActionType> for CallType {
type Error = &'static str;
fn try_from(action_type: ActionType) -> Result<Self, Self::Error> {
match action_type {
ActionType::Call => Ok(CallType::Call),
ActionType::CallCode => Ok(CallType::CallCode),
ActionType::DelegateCall => Ok(CallType::DelegateCall),
ActionType::StaticCall => Ok(CallType::StaticCall),
ActionType::Create => Err("Create cannot be converted to CallType"),
ActionType::Create2 => Err("Create2 cannot be converted to CallType"),
}
}
}
impl Encodable for CallType {
fn rlp_append(&self, s: &mut RlpStream) {
let v = match *self {
CallType::Call => 0u32,
CallType::CallCode => 1,
CallType::DelegateCall => 2,
CallType::StaticCall => 3,
};
Encodable::rlp_append(&v, s);
}
}
impl Decodable for CallType {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
rlp.as_val().and_then(|v| Ok(match v {
0u32 => CallType::Call,
1 => CallType::CallCode,
2 => CallType::DelegateCall,
3 => CallType::StaticCall,
_ => return Err(DecoderError::Custom("Invalid value of RewardType item")),
}))
}
}
/// `Create` result. /// `Create` result.
#[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)] #[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)]
pub struct CreateResult { pub struct CreateResult {
@ -103,49 +51,6 @@ impl CreateResult {
} }
} }
/// `Create` method. Distinguish between use of `CREATE` and `CREATE2` opcodes in an action.
#[derive(Debug, Clone, PartialEq)]
pub enum CreationMethod {
/// Create
Create,
/// Create2
Create2,
}
impl TryFrom<ActionType> for CreationMethod {
type Error = &'static str;
fn try_from(action_type: ActionType) -> Result<Self, Self::Error> {
match action_type {
ActionType::Call => Err("Call cannot be converted to CreationMethod"),
ActionType::CallCode => Err("CallCode cannot be converted to CreationMethod"),
ActionType::DelegateCall => Err("DelegateCall cannot be converted to CreationMethod"),
ActionType::StaticCall => Err("StaticCall cannot be converted to CreationMethod"),
ActionType::Create => Ok(CreationMethod::Create),
ActionType::Create2 => Ok(CreationMethod::Create2),
}
}
}
impl Encodable for CreationMethod {
fn rlp_append(&self, s: &mut RlpStream) {
let v = match *self {
CreationMethod::Create => 0u32,
CreationMethod::Create2 => 1,
};
Encodable::rlp_append(&v, s);
}
}
impl Decodable for CreationMethod {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
rlp.as_val().and_then(|v| Ok(match v {
0u32 => CreationMethod::Create,
1 => CreationMethod::Create2,
_ => return Err(DecoderError::Custom("Invalid value of RewardType item")),
}))
}
}
/// Description of a _call_ action, either a `CALL` operation or a message transaction. /// Description of a _call_ action, either a `CALL` operation or a message transaction.
#[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)] #[derive(Debug, Clone, PartialEq, RlpEncodable, RlpDecodable)]
pub struct Call { pub struct Call {
@ -160,19 +65,19 @@ pub struct Call {
/// The input data provided to the call. /// The input data provided to the call.
pub input: Bytes, pub input: Bytes,
/// The type of the call. /// The type of the call.
pub call_type: Option<CallType>, pub call_type: CallType,
} }
impl From<ActionParams> for Call { impl From<ActionParams> for Call {
fn from(p: ActionParams) -> Self { fn from(p: ActionParams) -> Self {
match p.action_type { match p.call_type {
ActionType::DelegateCall | ActionType::CallCode => Call { CallType::DelegateCall | CallType::CallCode => Call {
from: p.address, from: p.address,
to: p.code_address, to: p.code_address,
value: p.value.value(), value: p.value.value(),
gas: p.gas, gas: p.gas,
input: p.data.unwrap_or_else(Vec::new), input: p.data.unwrap_or_else(Vec::new),
call_type: CallType::try_from(p.action_type).ok(), call_type: p.call_type,
}, },
_ => Call { _ => Call {
from: p.sender, from: p.sender,
@ -180,7 +85,7 @@ impl From<ActionParams> for Call {
value: p.value.value(), value: p.value.value(),
gas: p.gas, gas: p.gas,
input: p.data.unwrap_or_else(Vec::new), input: p.data.unwrap_or_else(Vec::new),
call_type: CallType::try_from(p.action_type).ok(), call_type: p.call_type,
}, },
} }
} }
@ -208,8 +113,6 @@ pub struct Create {
pub gas: U256, pub gas: U256,
/// The init code. /// The init code.
pub init: Bytes, pub init: Bytes,
/// Creation method (CREATE vs CREATE2).
pub creation_method: Option<CreationMethod>,
} }
impl From<ActionParams> for Create { impl From<ActionParams> for Create {
@ -219,7 +122,6 @@ impl From<ActionParams> for Create {
value: p.value.value(), value: p.value.value(),
gas: p.gas, gas: p.gas,
init: p.code.map_or_else(Vec::new, |c| (*c).clone()), init: p.code.map_or_else(Vec::new, |c| (*c).clone()),
creation_method: CreationMethod::try_from(p.action_type).ok(),
} }
} }
} }

View File

@ -20,7 +20,7 @@ use bytes::Bytes;
use hash::{keccak, KECCAK_EMPTY}; use hash::{keccak, KECCAK_EMPTY};
use ethjson; use ethjson;
use action_type::ActionType; use call_type::CallType;
use std::sync::Arc; use std::sync::Arc;
@ -88,8 +88,8 @@ pub struct ActionParams {
pub code_version: U256, pub code_version: U256,
/// Input data. /// Input data.
pub data: Option<Bytes>, pub data: Option<Bytes>,
/// Type of action (e.g. CALL, DELEGATECALL, CREATE, etc.) /// Type of call
pub action_type: ActionType, pub call_type: CallType,
/// Param types encoding /// Param types encoding
pub params_type: ParamsType, pub params_type: ParamsType,
} }
@ -109,7 +109,7 @@ impl Default for ActionParams {
code: None, code: None,
code_version: U256::zero(), code_version: U256::zero(),
data: None, data: None,
action_type: ActionType::Create, call_type: CallType::None,
params_type: ParamsType::Separate, params_type: ParamsType::Separate,
} }
} }
@ -130,7 +130,7 @@ impl From<ethjson::vm::Transaction> for ActionParams {
gas: t.gas.into(), gas: t.gas.into(),
gas_price: t.gas_price.into(), gas_price: t.gas_price.into(),
value: ActionValue::Transfer(t.value.into()), value: ActionValue::Transfer(t.value.into()),
action_type: ActionType::Call, call_type: match address.is_zero() { true => CallType::None, false => CallType::Call }, // TODO @debris is this correct?
params_type: ParamsType::Separate, params_type: ParamsType::Separate,
} }
} }

View File

@ -14,51 +14,47 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>. // along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! EVM action types. //! EVM call types.
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp}; use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp};
/// The type of the instruction. /// The type of the call-like instruction.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum ActionType { pub enum CallType {
/// CREATE. /// Not a CALL.
Create, None,
/// CALL. /// CALL.
Call, Call,
/// CALLCODE. /// CALLCODE.
CallCode, CallCode,
/// DELEGATECALL. /// DELEGATECALL.
DelegateCall, DelegateCall,
/// STATICCALL. /// STATICCALL
StaticCall, StaticCall,
/// CREATE2.
Create2
} }
impl Encodable for ActionType { impl Encodable for CallType {
fn rlp_append(&self, s: &mut RlpStream) { fn rlp_append(&self, s: &mut RlpStream) {
let v = match *self { let v = match *self {
ActionType::Create => 0u32, CallType::None => 0u32,
ActionType::Call => 1, CallType::Call => 1,
ActionType::CallCode => 2, CallType::CallCode => 2,
ActionType::DelegateCall => 3, CallType::DelegateCall => 3,
ActionType::StaticCall => 4, CallType::StaticCall => 4,
ActionType::Create2 => 5,
}; };
Encodable::rlp_append(&v, s); Encodable::rlp_append(&v, s);
} }
} }
impl Decodable for ActionType { impl Decodable for CallType {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> { fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
rlp.as_val().and_then(|v| Ok(match v { rlp.as_val().and_then(|v| Ok(match v {
0u32 => ActionType::Create, 0u32 => CallType::None,
1 => ActionType::Call, 1 => CallType::Call,
2 => ActionType::CallCode, 2 => CallType::CallCode,
3 => ActionType::DelegateCall, 3 => CallType::DelegateCall,
4 => ActionType::StaticCall, 4 => CallType::StaticCall,
5 => ActionType::Create2, _ => return Err(DecoderError::Custom("Invalid value of CallType item")),
_ => return Err(DecoderError::Custom("Invalid value of ActionType item")),
})) }))
} }
} }
@ -66,11 +62,11 @@ impl Decodable for ActionType {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rlp::*; use rlp::*;
use super::ActionType; use super::CallType;
#[test] #[test]
fn encode_call_type() { fn encode_call_type() {
let ct = ActionType::Call; let ct = CallType::Call;
let mut s = RlpStream::new_list(2); let mut s = RlpStream::new_list(2);
s.append(&ct); s.append(&ct);
@ -82,9 +78,9 @@ mod tests {
#[test] #[test]
fn should_encode_and_decode_call_type() { fn should_encode_and_decode_call_type() {
let original = ActionType::Call; let original = CallType::Call;
let encoded = encode(&original); let encoded = encode(&original);
let decoded = decode(&encoded).expect("failure decoding ActionType"); let decoded = decode(&encoded).expect("failure decoding CallType");
assert_eq!(original, decoded); assert_eq!(original, decoded);
} }
} }

View File

@ -19,7 +19,7 @@
use std::sync::Arc; use std::sync::Arc;
use ethereum_types::{U256, H256, Address}; use ethereum_types::{U256, H256, Address};
use bytes::Bytes; use bytes::Bytes;
use action_type::ActionType; use call_type::CallType;
use env_info::EnvInfo; use env_info::EnvInfo;
use schedule::Schedule; use schedule::Schedule;
use return_data::ReturnData; use return_data::ReturnData;
@ -115,7 +115,7 @@ pub trait Ext {
value: Option<U256>, value: Option<U256>,
data: &[u8], data: &[u8],
code_address: &Address, code_address: &Address,
call_type: ActionType, call_type: CallType,
trap: bool trap: bool
) -> ::std::result::Result<MessageCallResult, TrapKind>; ) -> ::std::result::Result<MessageCallResult, TrapKind>;

View File

@ -24,7 +24,7 @@ extern crate keccak_hash as hash;
extern crate patricia_trie_ethereum as ethtrie; extern crate patricia_trie_ethereum as ethtrie;
mod action_params; mod action_params;
mod action_type; mod call_type;
mod env_info; mod env_info;
mod schedule; mod schedule;
mod ext; mod ext;
@ -34,7 +34,7 @@ mod error;
pub mod tests; pub mod tests;
pub use action_params::{ActionParams, ActionValue, ParamsType}; pub use action_params::{ActionParams, ActionValue, ParamsType};
pub use action_type::ActionType; pub use call_type::CallType;
pub use env_info::{EnvInfo, LastHashes}; pub use env_info::{EnvInfo, LastHashes};
pub use schedule::{Schedule, VersionedSchedule, CleanDustMode, WasmCosts}; pub use schedule::{Schedule, VersionedSchedule, CleanDustMode, WasmCosts};
pub use ext::{Ext, MessageCallResult, ContractCreateResult, CreateContractAddress}; pub use ext::{Ext, MessageCallResult, ContractCreateResult, CreateContractAddress};

View File

@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet};
use ethereum_types::{U256, H256, Address}; use ethereum_types::{U256, H256, Address};
use bytes::Bytes; use bytes::Bytes;
use { use {
ActionType, Schedule, EnvInfo, CallType, Schedule, EnvInfo,
ReturnData, Ext, ContractCreateResult, MessageCallResult, ReturnData, Ext, ContractCreateResult, MessageCallResult,
CreateContractAddress, Result, GasLeft, CreateContractAddress, Result, GasLeft,
}; };
@ -185,7 +185,7 @@ impl Ext for FakeExt {
value: Option<U256>, value: Option<U256>,
data: &[u8], data: &[u8],
code_address: &Address, code_address: &Address,
_call_type: ActionType, _call_type: CallType,
_trap: bool, _trap: bool,
) -> ::std::result::Result<MessageCallResult, TrapKind> { ) -> ::std::result::Result<MessageCallResult, TrapKind> {
self.calls.insert(FakeCall { self.calls.insert(FakeCall {

View File

@ -16,7 +16,7 @@
use std::cmp; use std::cmp;
use ethereum_types::{BigEndianHash, U256, H256, Address}; use ethereum_types::{BigEndianHash, U256, H256, Address};
use vm::{self, ActionType}; use vm::{self, CallType};
use wasmi::{self, MemoryRef, RuntimeArgs, RuntimeValue, Error as InterpreterError, Trap, TrapKind}; use wasmi::{self, MemoryRef, RuntimeArgs, RuntimeValue, Error as InterpreterError, Trap, TrapKind};
use super::panic_payload; use super::panic_payload;
@ -384,7 +384,7 @@ impl<'a> Runtime<'a> {
fn do_call( fn do_call(
&mut self, &mut self,
use_val: bool, use_val: bool,
call_type: ActionType, call_type: CallType,
args: RuntimeArgs, args: RuntimeArgs,
) )
-> Result<RuntimeValue> -> Result<RuntimeValue>
@ -445,8 +445,8 @@ impl<'a> Runtime<'a> {
let call_result = self.ext.call( let call_result = self.ext.call(
&gas.into(), &gas.into(),
match call_type { ActionType::DelegateCall => &self.context.sender, _ => &self.context.address }, match call_type { CallType::DelegateCall => &self.context.sender, _ => &self.context.address },
match call_type { ActionType::Call | ActionType::StaticCall => &address, _ => &self.context.address }, match call_type { CallType::Call | CallType::StaticCall => &address, _ => &self.context.address },
val, val,
&payload, &payload,
&address, &address,
@ -487,17 +487,17 @@ impl<'a> Runtime<'a> {
/// Message call /// Message call
fn ccall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> { fn ccall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> {
self.do_call(true, ActionType::Call, args) self.do_call(true, CallType::Call, args)
} }
/// Delegate call /// Delegate call
fn dcall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> { fn dcall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> {
self.do_call(false, ActionType::DelegateCall, args) self.do_call(false, CallType::DelegateCall, args)
} }
/// Static call /// Static call
fn scall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> { fn scall(&mut self, args: RuntimeArgs) -> Result<RuntimeValue> {
self.do_call(false, ActionType::StaticCall, args) self.do_call(false, CallType::StaticCall, args)
} }
fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()> fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()>

View File

@ -45,7 +45,7 @@ use ethereum_types::{U256, Address};
use ethcore::{json_tests, test_helpers::TrieSpec}; use ethcore::{json_tests, test_helpers::TrieSpec};
use spec; use spec;
use serde::Deserialize; use serde::Deserialize;
use vm::{ActionParams, ActionType}; use vm::{ActionParams, CallType};
mod info; mod info;
mod display; mod display;
@ -314,7 +314,7 @@ fn run_call<T: Informant>(args: Args, informant: T) {
} }
let mut params = ActionParams::default(); let mut params = ActionParams::default();
params.action_type = if code.is_none() { ActionType::Call } else { ActionType::Create }; params.call_type = if code.is_none() { CallType::Call } else { CallType::None };
params.code = code.map(Arc::new); params.code = code.map(Arc::new);
params.code_address = to; params.code_address = to;
params.address = to; params.address = to;

View File

@ -23,7 +23,7 @@ use ethcore::test_helpers::TestBlockChainClient;
use ethereum_types::{Address, H256}; use ethereum_types::{Address, H256};
use types::transaction::CallError; use types::transaction::CallError;
use trace::trace::CallType; use vm::CallType;
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
use v1::tests::helpers::{TestMinerService}; use v1::tests::helpers::{TestMinerService};
@ -44,7 +44,7 @@ fn io() -> Tester {
value: 0x1.into(), value: 0x1.into(),
gas: 0x100.into(), gas: 0x100.into(),
input: vec![1, 2, 3], input: vec![1, 2, 3],
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::None, result: Res::None,
subtraces: 0, subtraces: 0,

View File

@ -24,6 +24,7 @@ use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use types::account_diff; use types::account_diff;
use types::state_diff; use types::state_diff;
use vm;
use v1::types::Bytes; use v1::types::Bytes;
@ -213,7 +214,6 @@ impl From<state_diff::StateDiff> for StateDiff {
/// Create response /// Create response
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Create { pub struct Create {
/// Sender /// Sender
from: H160, from: H160,
@ -223,9 +223,6 @@ pub struct Create {
gas: U256, gas: U256,
/// Initialization code /// Initialization code
init: Bytes, init: Bytes,
// Create Type
#[serde(skip_serializing_if="Option::is_none")]
creation_method: Option<CreationMethod>,
} }
impl From<trace::Create> for Create { impl From<trace::Create> for Create {
@ -235,7 +232,6 @@ impl From<trace::Create> for Create {
value: c.value, value: c.value,
gas: c.gas, gas: c.gas,
init: Bytes::new(c.init), init: Bytes::new(c.init),
creation_method: c.creation_method.map(|c| c.into()),
} }
} }
} }
@ -244,6 +240,8 @@ impl From<trace::Create> for Create {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum CallType { pub enum CallType {
/// None
None,
/// Call /// Call
Call, Call,
/// Call code /// Call code
@ -254,32 +252,14 @@ pub enum CallType {
StaticCall, StaticCall,
} }
impl From<trace::CallType> for CallType { impl From<vm::CallType> for CallType {
fn from(c: trace::CallType) -> Self { fn from(c: vm::CallType) -> Self {
match c { match c {
trace::CallType::Call => CallType::Call, vm::CallType::None => CallType::None,
trace::CallType::CallCode => CallType::CallCode, vm::CallType::Call => CallType::Call,
trace::CallType::DelegateCall => CallType::DelegateCall, vm::CallType::CallCode => CallType::CallCode,
trace::CallType::StaticCall => CallType::StaticCall, vm::CallType::DelegateCall => CallType::DelegateCall,
} vm::CallType::StaticCall => CallType::StaticCall,
}
}
/// Create type.
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum CreationMethod {
/// Create
Create,
/// Create2
Create2,
}
impl From<trace::CreationMethod> for CreationMethod {
fn from(c: trace::CreationMethod) -> Self {
match c {
trace::CreationMethod::Create => CreationMethod::Create,
trace::CreationMethod::Create2 => CreationMethod::Create2,
} }
} }
} }
@ -299,7 +279,7 @@ pub struct Call {
/// Input data /// Input data
input: Bytes, input: Bytes,
/// The type of the call. /// The type of the call.
call_type: Option<CallType>, call_type: CallType,
} }
impl From<trace::Call> for Call { impl From<trace::Call> for Call {
@ -310,7 +290,7 @@ impl From<trace::Call> for Call {
value: c.value, value: c.value,
gas: c.gas, gas: c.gas,
input: c.input.into(), input: c.input.into(),
call_type: c.call_type.map(|c| c.into()), call_type: c.call_type.into(),
} }
} }
} }
@ -701,7 +681,7 @@ mod tests {
value: 6.into(), value: 6.into(),
gas: 7.into(), gas: 7.into(),
input: Bytes::new(vec![0x12, 0x34]), input: Bytes::new(vec![0x12, 0x34]),
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::Call(CallResult { result: Res::Call(CallResult {
gas_used: 8.into(), gas_used: 8.into(),
@ -727,7 +707,7 @@ mod tests {
value: 6.into(), value: 6.into(),
gas: 7.into(), gas: 7.into(),
input: Bytes::new(vec![0x12, 0x34]), input: Bytes::new(vec![0x12, 0x34]),
call_type: Some(CallType::Call), call_type: CallType::Call,
}), }),
result: Res::FailedCall(TraceError::OutOfGas), result: Res::FailedCall(TraceError::OutOfGas),
trace_address: vec![10], trace_address: vec![10],
@ -749,7 +729,6 @@ mod tests {
value: 6.into(), value: 6.into(),
gas: 7.into(), gas: 7.into(),
init: Bytes::new(vec![0x12, 0x34]), init: Bytes::new(vec![0x12, 0x34]),
creation_method: Some(CreationMethod::Create),
}), }),
result: Res::Create(CreateResult { result: Res::Create(CreateResult {
gas_used: 8.into(), gas_used: 8.into(),
@ -764,7 +743,7 @@ mod tests {
block_hash: H256::from_low_u64_be(14), block_hash: H256::from_low_u64_be(14),
}; };
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234","creationMethod":"create"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
} }
#[test] #[test]
@ -775,7 +754,6 @@ mod tests {
value: 6.into(), value: 6.into(),
gas: 7.into(), gas: 7.into(),
init: Bytes::new(vec![0x12, 0x34]), init: Bytes::new(vec![0x12, 0x34]),
creation_method: Some(CreationMethod::Create),
}), }),
result: Res::FailedCreate(TraceError::OutOfGas), result: Res::FailedCreate(TraceError::OutOfGas),
trace_address: vec![10], trace_address: vec![10],
@ -786,7 +764,7 @@ mod tests {
block_hash: H256::from_low_u64_be(14), block_hash: H256::from_low_u64_be(14),
}; };
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234","creationMethod":"create"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
} }
#[test] #[test]