[Trace] Distinguish between create
and create2
(#11311)
* adding a CreateType to ActionParams * rename calltype to action type * comments & line lengths * rebame ActionParams.call_type * Making call/create type optional * Moving strict create/call type into trace package instead of storing loosely typed action type * fix build * Deriving ActionType from address_scheme in ext.create * trigger build * more detailed comments * Change actions_type to call in vmtests * skipping serialization for Option::None and using TryFrom instead of maybe_new * retrigger build * trigger build
This commit is contained in:
parent
e95bbe36cb
commit
87e1080581
@ -42,7 +42,7 @@ use machine::{
|
|||||||
Machine,
|
Machine,
|
||||||
executed_block::ExecutedBlock,
|
executed_block::ExecutedBlock,
|
||||||
};
|
};
|
||||||
use vm::{EnvInfo, Schedule, CallType, ActionValue};
|
use vm::{EnvInfo, Schedule, ActionType, 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(CallType::StaticCall),
|
Some(ActionType::StaticCall),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ use ethereum_types::{U256, U512, H256, Address, BigEndianHash};
|
|||||||
|
|
||||||
|
|
||||||
use vm::{
|
use vm::{
|
||||||
self, ActionParams, ParamsType, ActionValue, CallType, MessageCallResult,
|
self, ActionParams, ParamsType, ActionValue, ActionType, 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 call
|
/// Type of action
|
||||||
pub call_type: CallType,
|
pub action_type: ActionType,
|
||||||
/// 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,
|
||||||
call_type: params.call_type,
|
action_type: params.action_type,
|
||||||
params_type: params.params_type,
|
params_type: params.params_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,7 +532,9 @@ 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(BigEndianHash::from_uint(&self.stack.pop_back())),
|
instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash(
|
||||||
|
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"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -553,7 +555,14 @@ 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(&create_gas.as_u256(), &endowment, contract_code, &self.params.code_version, address_scheme, true);
|
let create_result = ext.create(
|
||||||
|
&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));
|
||||||
@ -607,14 +616,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, CallType::Call)
|
(&self.params.address, &code_address, has_balance, ActionType::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, CallType::CallCode)
|
(&self.params.address, &self.params.address, has_balance, ActionType::CallCode)
|
||||||
},
|
},
|
||||||
instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, CallType::DelegateCall),
|
instructions::DELEGATECALL => (&self.params.sender, &self.params.address, true, ActionType::DelegateCall),
|
||||||
instructions::STATICCALL => (&self.params.address, &code_address, true, CallType::StaticCall),
|
instructions::STATICCALL => (&self.params.address, &code_address, true, ActionType::StaticCall),
|
||||||
_ => panic!(format!("Unexpected instruction {:?} in CALL branch.", instruction))
|
_ => panic!(format!("Unexpected instruction {:?} in CALL branch.", instruction))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ mod instructions;
|
|||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub use vm::{
|
pub use vm::{
|
||||||
Schedule, CleanDustMode, EnvInfo, CallType, ActionParams, Ext,
|
Schedule, CleanDustMode, EnvInfo, ActionType, ActionParams, Ext,
|
||||||
ContractCreateResult, MessageCallResult, CreateContractAddress,
|
ContractCreateResult, MessageCallResult, CreateContractAddress,
|
||||||
GasLeft, ReturnData
|
GasLeft, ReturnData
|
||||||
};
|
};
|
||||||
|
@ -276,7 +276,6 @@ 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;
|
||||||
@ -324,6 +323,7 @@ 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,6 +381,7 @@ 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
|
||||||
@ -419,7 +420,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(3),
|
gas_used: U256::from(3),
|
||||||
@ -460,7 +461,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(0),
|
gas_used: U256::from(0),
|
||||||
@ -501,7 +502,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 79_000.into(),
|
gas: 79_000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(3000),
|
gas_used: U256::from(3000),
|
||||||
@ -543,7 +544,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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
|
||||||
@ -587,7 +588,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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
|
||||||
@ -602,7 +603,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 4096.into(),
|
gas: 4096.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::CallCode,
|
call_type: Some(trace::CallType::CallCode),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: 3.into(),
|
gas_used: 3.into(),
|
||||||
@ -646,7 +647,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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
|
||||||
@ -661,7 +662,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 32768.into(),
|
gas: 32768.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::DelegateCall,
|
call_type: Some(trace::CallType::DelegateCall),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: 18.into(),
|
gas_used: 18.into(),
|
||||||
@ -702,7 +703,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
@ -744,7 +745,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(69),
|
gas_used: U256::from(69),
|
||||||
@ -759,7 +760,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 78934.into(),
|
gas: 78934.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(3),
|
gas_used: U256::from(3),
|
||||||
@ -801,7 +802,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(31761),
|
gas_used: U256::from(31761),
|
||||||
@ -816,7 +817,7 @@ mod tests {
|
|||||||
value: 69.into(),
|
value: 69.into(),
|
||||||
gas: 2300.into(),
|
gas: 2300.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult::default()),
|
result: trace::Res::Call(trace::CallResult::default()),
|
||||||
}];
|
}];
|
||||||
@ -855,7 +856,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(31761),
|
gas_used: U256::from(31761),
|
||||||
@ -898,7 +899,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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),
|
||||||
@ -913,7 +914,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 78934.into(),
|
gas: 78934.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
||||||
}];
|
}];
|
||||||
@ -954,7 +955,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(135),
|
gas_used: U256::from(135),
|
||||||
@ -969,7 +970,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 78934.into(),
|
gas: 78934.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(69),
|
gas_used: U256::from(69),
|
||||||
@ -984,7 +985,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 78868.into(),
|
gas: 78868.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: U256::from(3),
|
gas_used: U256::from(3),
|
||||||
@ -1029,7 +1030,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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),
|
||||||
@ -1044,7 +1045,7 @@ mod tests {
|
|||||||
value: 0.into(),
|
value: 0.into(),
|
||||||
gas: 78934.into(),
|
gas: 78934.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
result: trace::Res::FailedCall(TraceError::OutOfGas),
|
||||||
}, FlatTrace {
|
}, FlatTrace {
|
||||||
@ -1055,7 +1056,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: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
@ -1099,7 +1100,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 79000.into(),
|
gas: 79000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: trace::Res::Call(trace::CallResult {
|
result: trace::Res::Call(trace::CallResult {
|
||||||
gas_used: 3.into(),
|
gas_used: 3.into(),
|
||||||
|
@ -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::{CallType, Finalize, FinalizationResult};
|
use evm::{ActionType, 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.call_type == CallType::StaticCall;
|
let static_flag = parent_static_flag || params.action_type == ActionType::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(¶ms.code_address, info.number) {
|
let kind = if let Some(builtin) = machine.builtin(¶ms.code_address, info.number) {
|
||||||
@ -298,7 +298,7 @@ impl<'a> CallCreateExecutive<'a> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (static_flag &&
|
if (static_flag &&
|
||||||
(params.call_type == CallType::StaticCall || params.call_type == CallType::Call)) &&
|
(params.action_type == ActionType::StaticCall || params.action_type == ActionType::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,
|
||||||
call_type: CallType::None,
|
action_type: ActionType::Create,
|
||||||
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()),
|
||||||
call_type: CallType::Call,
|
action_type: ActionType::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, CallType, EnvInfo, CreateContractAddress};
|
use vm::{ActionParams, ActionValue, 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.call_type = CallType::Call;
|
params.action_type = ActionType::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: CallType::Call
|
call_type: Some(trace::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: CallType::Call
|
call_type: Some(trace::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.call_type = CallType::Call;
|
params.action_type = ActionType::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: CallType::Call,
|
call_type: Some(trace::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,7 +1537,8 @@ 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),
|
||||||
@ -1614,7 +1615,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.call_type = CallType::Call;
|
params.action_type = ActionType::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();
|
||||||
@ -1640,7 +1641,7 @@ mod tests {
|
|||||||
value: 100.into(),
|
value: 100.into(),
|
||||||
gas: 100_000.into(),
|
gas: 100_000.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(trace::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),
|
||||||
@ -1653,7 +1654,8 @@ 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()),
|
||||||
}];
|
}];
|
||||||
@ -1711,6 +1713,7 @@ 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),
|
||||||
|
@ -29,7 +29,7 @@ use common_types::{
|
|||||||
};
|
};
|
||||||
use trace::{Tracer, VMTracer};
|
use trace::{Tracer, VMTracer};
|
||||||
use vm::{
|
use vm::{
|
||||||
self, ActionParams, ActionValue, EnvInfo, CallType, Schedule,
|
self, ActionParams, ActionValue, EnvInfo, ActionType, 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()),
|
||||||
call_type: CallType::Call,
|
action_type: ActionType::Call,
|
||||||
params_type: vm::ParamsType::Separate,
|
params_type: vm::ParamsType::Separate,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,6 +241,12 @@ 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(),
|
||||||
@ -254,7 +260,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,
|
||||||
call_type: CallType::None,
|
action_type: create_type,
|
||||||
params_type: vm::ParamsType::Embedded,
|
params_type: vm::ParamsType::Embedded,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -285,7 +291,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: CallType,
|
call_type: ActionType,
|
||||||
trap: bool,
|
trap: bool,
|
||||||
) -> ::std::result::Result<MessageCallResult, TrapKind> {
|
) -> ::std::result::Result<MessageCallResult, TrapKind> {
|
||||||
trace!(target: "externalities", "call");
|
trace!(target: "externalities", "call");
|
||||||
@ -311,7 +317,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()),
|
||||||
call_type,
|
action_type: call_type,
|
||||||
params_type: vm::ParamsType::Separate,
|
params_type: vm::ParamsType::Separate,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -457,7 +463,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, CallType};
|
use evm::{EnvInfo, Ext, ActionType};
|
||||||
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};
|
||||||
@ -591,7 +597,7 @@ mod tests {
|
|||||||
Some("0000000000000000000000000000000000000000000000000000000000150000".parse::<U256>().unwrap()),
|
Some("0000000000000000000000000000000000000000000000000000000000150000".parse::<U256>().unwrap()),
|
||||||
&[],
|
&[],
|
||||||
&Address::zero(),
|
&Address::zero(),
|
||||||
CallType::Call,
|
ActionType::Call,
|
||||||
false,
|
false,
|
||||||
).ok().unwrap();
|
).ok().unwrap();
|
||||||
}
|
}
|
||||||
|
@ -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::{CallType, ActionParams, ActionValue, ParamsType};
|
use vm::{ActionType, 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>>,
|
||||||
call_type: Option<CallType>,
|
action_type: Option<ActionType>,
|
||||||
) -> 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,
|
||||||
call_type: call_type.unwrap_or(CallType::Call),
|
action_type: action_type.unwrap_or(ActionType::Call),
|
||||||
params_type: ParamsType::Separate,
|
params_type: ParamsType::Separate,
|
||||||
};
|
};
|
||||||
let schedule = self.schedule(env_info.number);
|
let schedule = self.schedule(env_info.number);
|
||||||
|
@ -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, CallType, ActionValue, ActionParams, ParamsType};
|
use vm::{EnvInfo, ActionType, 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,
|
||||||
call_type: CallType::None,
|
action_type: ActionType::Create,
|
||||||
params_type: ParamsType::Embedded,
|
params_type: ParamsType::Embedded,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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, CallType, Schedule, Ext,
|
self, ActionParams, ActionType, 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: CallType,
|
_call_type: ActionType,
|
||||||
_trap: bool
|
_trap: bool
|
||||||
) -> Result<MessageCallResult, vm::TrapKind> {
|
) -> Result<MessageCallResult, vm::TrapKind> {
|
||||||
self.callcreates.push(CallCreate {
|
self.callcreates.push(CallCreate {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use vm::{EnvInfo, ActionParams, ActionValue, CallType, ParamsType};
|
use vm::{EnvInfo, ActionParams, ActionValue, ActionType, 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()),
|
||||||
call_type: CallType::Call,
|
action_type: ActionType::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,
|
||||||
call_type: CallType::Call,
|
action_type: ActionType::Call,
|
||||||
params_type: ParamsType::Separate,
|
params_type: ParamsType::Separate,
|
||||||
};
|
};
|
||||||
let schedule = machine.schedule(env_info.number);
|
let schedule = machine.schedule(env_info.number);
|
||||||
|
@ -374,13 +374,12 @@ 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, Action, Res},
|
trace::{Call, CallType, Action, Res},
|
||||||
flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}
|
flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -465,7 +464,7 @@ mod tests {
|
|||||||
value: 3.into(),
|
value: 3.into(),
|
||||||
gas: 4.into(),
|
gas: 4.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
}])]),
|
}])]),
|
||||||
@ -487,7 +486,7 @@ mod tests {
|
|||||||
value: 3.into(),
|
value: 3.into(),
|
||||||
gas: 4.into(),
|
gas: 4.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
}])]),
|
}])]),
|
||||||
@ -506,7 +505,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: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
trace_address: vec![],
|
trace_address: vec![],
|
||||||
|
@ -125,10 +125,9 @@ 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, Res, Create, CreateResult, Suicide, Reward},
|
trace::{Action, Call, CallType, Res, Create, CreationMethod, CreateResult, Suicide, Reward},
|
||||||
flat::FlatTrace,
|
flat::FlatTrace,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -273,7 +272,7 @@ mod tests {
|
|||||||
value: 3.into(),
|
value: 3.into(),
|
||||||
gas: 4.into(),
|
gas: 4.into(),
|
||||||
input: vec![0x5],
|
input: vec![0x5],
|
||||||
call_type: CallType::Call,
|
call_type: Some(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(),
|
||||||
@ -294,6 +293,7 @@ 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,6 +413,7 @@ 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(),
|
||||||
|
@ -123,9 +123,8 @@ mod tests {
|
|||||||
use rlp::*;
|
use rlp::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
FlatBlockTraces, FlatTransactionTraces, FlatTrace,
|
FlatBlockTraces, FlatTransactionTraces, FlatTrace,
|
||||||
trace::{Action, Res, CallResult, Call, Suicide, Reward, RewardType}
|
trace::{Action, Res, CallResult, Call, CallType, Suicide, Reward, RewardType}
|
||||||
};
|
};
|
||||||
use evm::CallType;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_flat_transaction_traces() {
|
fn encode_flat_transaction_traces() {
|
||||||
@ -162,7 +161,7 @@ mod tests {
|
|||||||
value: "3627e8f712373c0000".parse().unwrap(),
|
value: "3627e8f712373c0000".parse().unwrap(),
|
||||||
gas: 0x03e8.into(),
|
gas: 0x03e8.into(),
|
||||||
input: vec![],
|
input: vec![],
|
||||||
call_type: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::Call(CallResult {
|
result: Res::Call(CallResult {
|
||||||
gas_used: 0.into(),
|
gas_used: 0.into(),
|
||||||
@ -179,7 +178,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: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::Call(CallResult {
|
result: Res::Call(CallResult {
|
||||||
gas_used: 0x0127.into(),
|
gas_used: 0x0127.into(),
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
//! 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::CallType;
|
use evm::ActionType;
|
||||||
use super::error::Error;
|
use super::error::Error;
|
||||||
|
|
||||||
/// `Call` result.
|
/// `Call` result.
|
||||||
@ -33,6 +34,57 @@ 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 {
|
||||||
@ -51,6 +103,49 @@ 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 {
|
||||||
@ -65,19 +160,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: CallType,
|
pub call_type: Option<CallType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ActionParams> for Call {
|
impl From<ActionParams> for Call {
|
||||||
fn from(p: ActionParams) -> Self {
|
fn from(p: ActionParams) -> Self {
|
||||||
match p.call_type {
|
match p.action_type {
|
||||||
CallType::DelegateCall | CallType::CallCode => Call {
|
ActionType::DelegateCall | ActionType::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: p.call_type,
|
call_type: CallType::try_from(p.action_type).ok(),
|
||||||
},
|
},
|
||||||
_ => Call {
|
_ => Call {
|
||||||
from: p.sender,
|
from: p.sender,
|
||||||
@ -85,7 +180,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: p.call_type,
|
call_type: CallType::try_from(p.action_type).ok(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,6 +208,8 @@ 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 {
|
||||||
@ -122,6 +219,7 @@ 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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use bytes::Bytes;
|
|||||||
use hash::{keccak, KECCAK_EMPTY};
|
use hash::{keccak, KECCAK_EMPTY};
|
||||||
use ethjson;
|
use ethjson;
|
||||||
|
|
||||||
use call_type::CallType;
|
use action_type::ActionType;
|
||||||
|
|
||||||
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 call
|
/// Type of action (e.g. CALL, DELEGATECALL, CREATE, etc.)
|
||||||
pub call_type: CallType,
|
pub action_type: ActionType,
|
||||||
/// 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,
|
||||||
call_type: CallType::None,
|
action_type: ActionType::Create,
|
||||||
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()),
|
||||||
call_type: match address.is_zero() { true => CallType::None, false => CallType::Call }, // TODO @debris is this correct?
|
action_type: ActionType::Call,
|
||||||
params_type: ParamsType::Separate,
|
params_type: ParamsType::Separate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,47 +14,51 @@
|
|||||||
// 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 call types.
|
//! EVM action types.
|
||||||
|
|
||||||
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp};
|
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp};
|
||||||
|
|
||||||
/// The type of the call-like instruction.
|
/// The type of the instruction.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum CallType {
|
pub enum ActionType {
|
||||||
/// Not a CALL.
|
/// CREATE.
|
||||||
None,
|
Create,
|
||||||
/// CALL.
|
/// CALL.
|
||||||
Call,
|
Call,
|
||||||
/// CALLCODE.
|
/// CALLCODE.
|
||||||
CallCode,
|
CallCode,
|
||||||
/// DELEGATECALL.
|
/// DELEGATECALL.
|
||||||
DelegateCall,
|
DelegateCall,
|
||||||
/// STATICCALL
|
/// STATICCALL.
|
||||||
StaticCall,
|
StaticCall,
|
||||||
|
/// CREATE2.
|
||||||
|
Create2
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encodable for CallType {
|
impl Encodable for ActionType {
|
||||||
fn rlp_append(&self, s: &mut RlpStream) {
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
let v = match *self {
|
let v = match *self {
|
||||||
CallType::None => 0u32,
|
ActionType::Create => 0u32,
|
||||||
CallType::Call => 1,
|
ActionType::Call => 1,
|
||||||
CallType::CallCode => 2,
|
ActionType::CallCode => 2,
|
||||||
CallType::DelegateCall => 3,
|
ActionType::DelegateCall => 3,
|
||||||
CallType::StaticCall => 4,
|
ActionType::StaticCall => 4,
|
||||||
|
ActionType::Create2 => 5,
|
||||||
};
|
};
|
||||||
Encodable::rlp_append(&v, s);
|
Encodable::rlp_append(&v, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Decodable for CallType {
|
impl Decodable for ActionType {
|
||||||
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 => CallType::None,
|
0u32 => ActionType::Create,
|
||||||
1 => CallType::Call,
|
1 => ActionType::Call,
|
||||||
2 => CallType::CallCode,
|
2 => ActionType::CallCode,
|
||||||
3 => CallType::DelegateCall,
|
3 => ActionType::DelegateCall,
|
||||||
4 => CallType::StaticCall,
|
4 => ActionType::StaticCall,
|
||||||
_ => return Err(DecoderError::Custom("Invalid value of CallType item")),
|
5 => ActionType::Create2,
|
||||||
|
_ => return Err(DecoderError::Custom("Invalid value of ActionType item")),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,11 +66,11 @@ impl Decodable for CallType {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use rlp::*;
|
use rlp::*;
|
||||||
use super::CallType;
|
use super::ActionType;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_call_type() {
|
fn encode_call_type() {
|
||||||
let ct = CallType::Call;
|
let ct = ActionType::Call;
|
||||||
|
|
||||||
let mut s = RlpStream::new_list(2);
|
let mut s = RlpStream::new_list(2);
|
||||||
s.append(&ct);
|
s.append(&ct);
|
||||||
@ -78,9 +82,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_encode_and_decode_call_type() {
|
fn should_encode_and_decode_call_type() {
|
||||||
let original = CallType::Call;
|
let original = ActionType::Call;
|
||||||
let encoded = encode(&original);
|
let encoded = encode(&original);
|
||||||
let decoded = decode(&encoded).expect("failure decoding CallType");
|
let decoded = decode(&encoded).expect("failure decoding ActionType");
|
||||||
assert_eq!(original, decoded);
|
assert_eq!(original, decoded);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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 call_type::CallType;
|
use action_type::ActionType;
|
||||||
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: CallType,
|
call_type: ActionType,
|
||||||
trap: bool
|
trap: bool
|
||||||
) -> ::std::result::Result<MessageCallResult, TrapKind>;
|
) -> ::std::result::Result<MessageCallResult, TrapKind>;
|
||||||
|
|
||||||
|
@ -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 call_type;
|
mod action_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 call_type::CallType;
|
pub use action_type::ActionType;
|
||||||
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};
|
||||||
|
@ -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 {
|
||||||
CallType, Schedule, EnvInfo,
|
ActionType, 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: CallType,
|
_call_type: ActionType,
|
||||||
_trap: bool,
|
_trap: bool,
|
||||||
) -> ::std::result::Result<MessageCallResult, TrapKind> {
|
) -> ::std::result::Result<MessageCallResult, TrapKind> {
|
||||||
self.calls.insert(FakeCall {
|
self.calls.insert(FakeCall {
|
||||||
|
@ -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, CallType};
|
use vm::{self, ActionType};
|
||||||
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: CallType,
|
call_type: ActionType,
|
||||||
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 { CallType::DelegateCall => &self.context.sender, _ => &self.context.address },
|
match call_type { ActionType::DelegateCall => &self.context.sender, _ => &self.context.address },
|
||||||
match call_type { CallType::Call | CallType::StaticCall => &address, _ => &self.context.address },
|
match call_type { ActionType::Call | ActionType::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, CallType::Call, args)
|
self.do_call(true, ActionType::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, CallType::DelegateCall, args)
|
self.do_call(false, ActionType::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, CallType::StaticCall, args)
|
self.do_call(false, ActionType::StaticCall, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()>
|
fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()>
|
||||||
|
@ -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, CallType};
|
use vm::{ActionParams, ActionType};
|
||||||
|
|
||||||
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.call_type = if code.is_none() { CallType::Call } else { CallType::None };
|
params.action_type = if code.is_none() { ActionType::Call } else { ActionType::Create };
|
||||||
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;
|
||||||
|
@ -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 vm::CallType;
|
use trace::trace::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: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::None,
|
result: Res::None,
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
|
@ -24,7 +24,6 @@ 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;
|
||||||
|
|
||||||
@ -214,6 +213,7 @@ 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,6 +223,9 @@ 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 {
|
||||||
@ -232,6 +235,7 @@ 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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,8 +244,6 @@ 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
|
||||||
@ -252,14 +254,32 @@ pub enum CallType {
|
|||||||
StaticCall,
|
StaticCall,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<vm::CallType> for CallType {
|
impl From<trace::CallType> for CallType {
|
||||||
fn from(c: vm::CallType) -> Self {
|
fn from(c: trace::CallType) -> Self {
|
||||||
match c {
|
match c {
|
||||||
vm::CallType::None => CallType::None,
|
trace::CallType::Call => CallType::Call,
|
||||||
vm::CallType::Call => CallType::Call,
|
trace::CallType::CallCode => CallType::CallCode,
|
||||||
vm::CallType::CallCode => CallType::CallCode,
|
trace::CallType::DelegateCall => CallType::DelegateCall,
|
||||||
vm::CallType::DelegateCall => CallType::DelegateCall,
|
trace::CallType::StaticCall => CallType::StaticCall,
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,7 +299,7 @@ pub struct Call {
|
|||||||
/// Input data
|
/// Input data
|
||||||
input: Bytes,
|
input: Bytes,
|
||||||
/// The type of the call.
|
/// The type of the call.
|
||||||
call_type: CallType,
|
call_type: Option<CallType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<trace::Call> for Call {
|
impl From<trace::Call> for Call {
|
||||||
@ -290,7 +310,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.into(),
|
call_type: c.call_type.map(|c| c.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -681,7 +701,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: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::Call(CallResult {
|
result: Res::Call(CallResult {
|
||||||
gas_used: 8.into(),
|
gas_used: 8.into(),
|
||||||
@ -707,7 +727,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: CallType::Call,
|
call_type: Some(CallType::Call),
|
||||||
}),
|
}),
|
||||||
result: Res::FailedCall(TraceError::OutOfGas),
|
result: Res::FailedCall(TraceError::OutOfGas),
|
||||||
trace_address: vec![10],
|
trace_address: vec![10],
|
||||||
@ -729,6 +749,7 @@ 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(),
|
||||||
@ -743,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"},"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","creationMethod":"create"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -754,6 +775,7 @@ 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],
|
||||||
@ -764,7 +786,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"},"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","creationMethod":"create"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user