From 52355855fc86a62e891e10ece487355db25cbeda Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 3 Aug 2016 20:07:30 +0200 Subject: [PATCH 1/2] Fix up the VM trace. --- ethcore/src/executive.rs | 4 ++-- ethcore/src/trace/executive_tracer.rs | 17 +++++++++++++++-- ethcore/src/types/trace_types/trace.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 9a48f9d4a..9d5a8acf7 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -99,11 +99,11 @@ impl<'a> Executive<'a> { let check = options.check_nonce; match options.tracing { true => match options.vm_tracing { - true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::default()), + true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::toplevel()), false => self.transact_with_tracer(t, check, ExecutiveTracer::default(), NoopVMTracer), }, false => match options.vm_tracing { - true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::default()), + true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::toplevel()), false => self.transact_with_tracer(t, check, NoopTracer, NoopVMTracer), }, } diff --git a/ethcore/src/trace/executive_tracer.rs b/ethcore/src/trace/executive_tracer.rs index a64664095..5c2e158e9 100644 --- a/ethcore/src/trace/executive_tracer.rs +++ b/ethcore/src/trace/executive_tracer.rs @@ -160,11 +160,24 @@ impl Tracer for ExecutiveTracer { } /// Simple VM tracer. Traces all operations. -#[derive(Default)] pub struct ExecutiveVMTracer { data: VMTrace, } +impl ExecutiveVMTracer { + /// Create a new top-level instance. + pub fn toplevel() -> Self { + ExecutiveVMTracer { + data: VMTrace { + parent_step: 0, + code: vec![], + operations: vec![Default::default()], // prefill with a single entry so that prepare_subtrace can get the parent_step + subs: vec![], + } + } + } +} + impl VMTracer for ExecutiveVMTracer { fn trace_prepare_execute(&mut self, pc: usize, instruction: u8, gas_cost: &U256) -> bool { self.data.operations.push(VMOperation { @@ -188,7 +201,7 @@ impl VMTracer for ExecutiveVMTracer { fn prepare_subtrace(&self, code: &[u8]) -> Self { ExecutiveVMTracer { data: VMTrace { - parent_step: self.data.operations.len(), + parent_step: self.data.operations.len() - 1, // won't overflow since we must already have pushed an operation in trace_prepare_execute. code: code.to_vec(), operations: vec![], subs: vec![], diff --git a/ethcore/src/types/trace_types/trace.rs b/ethcore/src/types/trace_types/trace.rs index 346b99c06..8d251032c 100644 --- a/ethcore/src/types/trace_types/trace.rs +++ b/ethcore/src/types/trace_types/trace.rs @@ -473,7 +473,7 @@ impl Decodable for VMExecutedOperation { } } -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq, Binary, Default)] /// A record of the execution of a single VM operation. pub struct VMOperation { /// The program counter. From 9bb9a84d407e4f8af6f5b862fde492d7255b1830 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 3 Aug 2016 23:23:45 +0200 Subject: [PATCH 2/2] Fix test. --- ethcore/src/executive.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 9d5a8acf7..748582eba 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -634,7 +634,7 @@ mod tests { let engine = TestEngine::new(5); let mut substate = Substate::new(); let mut tracer = ExecutiveTracer::default(); - let mut vm_tracer = ExecutiveVMTracer::default(); + let mut vm_tracer = ExecutiveVMTracer::toplevel(); let gas_left = { let mut ex = Executive::new(&mut state, &info, &engine, &factory); @@ -693,7 +693,7 @@ mod tests { ], subs: vec![ VMTrace { - parent_step: 7, + parent_step: 6, code: 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], operations: vec![ VMOperation { pc: 0, instruction: 96, gas_cost: 3.into(), executed: Some(VMExecutedOperation { gas_used: 67976.into(), stack_push: vec_into![16], mem_diff: None, store_diff: None }) }, @@ -743,7 +743,7 @@ mod tests { let engine = TestEngine::new(5); let mut substate = Substate::new(); let mut tracer = ExecutiveTracer::default(); - let mut vm_tracer = ExecutiveVMTracer::default(); + let mut vm_tracer = ExecutiveVMTracer::toplevel(); let gas_left = { let mut ex = Executive::new(&mut state, &info, &engine, &factory);