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

Fix json tracer overflow #9873

Merged
merged 5 commits into from
Nov 7, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions evmbin/src/display/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl trace::VMTracer for Informant {
fn trace_executed(&mut self, gas_used: U256, stack_push: &[U256], mem: &[u8]) {
cheme marked this conversation as resolved.
Show resolved Hide resolved
let subdepth = self.subdepth;
Self::with_informant_in_depth(self, subdepth, |informant: &mut Informant| {
let mem_diff = informant.mem_written.clone().map(|(o, s)| (o, &(mem[o..o+s])));
let store_diff = informant.store_written.clone();
let info = ::evm::Instruction::from_u8(informant.instruction).map(|i| i.info());

Expand All @@ -151,11 +150,11 @@ impl trace::VMTracer for Informant {
informant.stack.extend_from_slice(stack_push);

// TODO [ToDr] Align memory?
if let Some((pos, data)) = mem_diff {
if informant.memory.len() < (pos + data.len()) {
informant.memory.resize(pos + data.len(), 0);
if let Some((pos, size)) = informant.mem_written.clone() {
if informant.memory.len() < (pos + size) {
informant.memory.resize(pos + size, 0);
}
informant.memory[pos..pos + data.len()].copy_from_slice(data);
informant.memory[pos..(pos + size)].copy_from_slice(&mem[pos..(pos + size)]);
}

if let Some((pos, val)) = store_diff {
Expand Down Expand Up @@ -195,7 +194,24 @@ impl trace::VMTracer for Informant {
// print last line with final state:
self.gas_cost = 0.into();
let gas_used = self.gas_used;
self.trace_executed(gas_used, &[], &[]);
let subdepth = self.subdepth;

Self::with_informant_in_depth(&mut self, subdepth, |informant: &mut Informant| {
let info = ::evm::Instruction::from_u8(informant.instruction).map(|i| i.info());

let trace = json!({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we could get rid of this duplication? It's not strongly typed and having two places where this is generated is imho error prone in the long term.

"pc": informant.pc,
"op": informant.instruction,
"opName": info.map(|i| i.name).unwrap_or(""),
"gas": format!("{:#x}", gas_used.saturating_add(informant.gas_cost)),
"gasCost": format!("{:#x}", informant.gas_cost),
"memory": format!("0x{}", informant.memory.to_hex()),
"stack": informant.stack,
"storage": informant.storage,
"depth": informant.depth,
});
informant.traces.push(trace.to_string());
});
} else if !self.subtraces.is_empty() {
self.traces.extend(mem::replace(&mut self.subtraces, vec![]));
}
Expand Down