Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixed delegatecall's from/to (#7568)
Browse files Browse the repository at this point in the history
* Fixed delegatecall's from/to, closes #7166

* added tests for delegatecall traces, #7167
  • Loading branch information
debris authored Jan 17, 2018
1 parent 25b1983 commit 7d49dd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
14 changes: 7 additions & 7 deletions ethcore/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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],
}),
}];

Expand Down
24 changes: 17 additions & 7 deletions ethcore/src/trace/types/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ pub struct Call {

impl From<ActionParams> 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,
},
}
}
}
Expand Down

0 comments on commit 7d49dd4

Please sign in to comment.