From 7d49dd4727d88c7d45d146837e36c05409bd9907 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 17 Jan 2018 10:44:11 +0100 Subject: [PATCH] Fixed delegatecall's from/to (#7568) * Fixed delegatecall's from/to, closes #7166 * added tests for delegatecall traces, #7167 --- ethcore/src/state/mod.rs | 14 +++++++------- ethcore/src/trace/types/trace.rs | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index c2ea43e9f..a8d298440 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -1404,7 +1404,7 @@ mod tests { } #[test] - fn should_not_trace_delegatecall() { + fn should_trace_delegatecall_properly() { init_log(); let mut state = get_temp_state(); @@ -1424,7 +1424,7 @@ mod tests { }.sign(&secret(), None); state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&0xb.into(), FromHex::from_hex("60056000526001601ff3").unwrap()).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { @@ -1439,23 +1439,23 @@ mod tests { call_type: CallType::Call, }), result: trace::Res::Call(trace::CallResult { - gas_used: U256::from(721), // in post-eip150 + gas_used: U256::from(736), // in post-eip150 output: vec![] }), }, FlatTrace { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: 0xa.into(), + to: 0xb.into(), value: 0.into(), gas: 32768.into(), input: vec![], call_type: CallType::DelegateCall, }), result: trace::Res::Call(trace::CallResult { - gas_used: 3.into(), - output: vec![], + gas_used: 18.into(), + output: vec![5], }), }]; diff --git a/ethcore/src/trace/types/trace.rs b/ethcore/src/trace/types/trace.rs index e81fe3cfe..18fe329c4 100644 --- a/ethcore/src/trace/types/trace.rs +++ b/ethcore/src/trace/types/trace.rs @@ -70,13 +70,23 @@ pub struct Call { impl From for Call { fn from(p: ActionParams) -> Self { - Call { - from: p.sender, - to: p.address, - value: p.value.value(), - gas: p.gas, - input: p.data.unwrap_or_else(Vec::new), - call_type: p.call_type, + match p.call_type { + CallType::DelegateCall => Call { + from: p.address, + to: p.code_address, + value: p.value.value(), + gas: p.gas, + input: p.data.unwrap_or_else(Vec::new), + call_type: p.call_type, + }, + _ => Call { + from: p.sender, + to: p.address, + value: p.value.value(), + gas: p.gas, + input: p.data.unwrap_or_else(Vec::new), + call_type: p.call_type, + }, } } }