From 7d8372f07d4a3f999c258c879e12e19785ea9cfc Mon Sep 17 00:00:00 2001 From: Matt Solomon Date: Thu, 21 Apr 2022 07:53:08 -0700 Subject: [PATCH] feat: show hardhat console.logs in traces (#1367) * feat: show hardhat console.logs in traces * chore: better rust --- evm/src/executor/inspector/tracer.rs | 37 +++++++++++----------------- evm/src/trace/decoder.rs | 19 +++++++++----- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/evm/src/executor/inspector/tracer.rs b/evm/src/executor/inspector/tracer.rs index 4bc3971de7c3..38edf05b4d40 100644 --- a/evm/src/executor/inspector/tracer.rs +++ b/evm/src/executor/inspector/tracer.rs @@ -1,8 +1,5 @@ use crate::{ - executor::{ - inspector::utils::{gas_used, get_create_address}, - HARDHAT_CONSOLE_ADDRESS, - }, + executor::inspector::utils::{gas_used, get_create_address}, trace::{ CallTrace, CallTraceArena, LogCallOrder, RawOrDecodedCall, RawOrDecodedLog, RawOrDecodedReturnData, @@ -75,15 +72,13 @@ where call: &mut CallInputs, _: bool, ) -> (Return, Gas, Bytes) { - if call.contract != HARDHAT_CONSOLE_ADDRESS { - self.start_trace( - data.subroutine.depth() as usize, - call.context.code_address, - call.input.to_vec(), - call.transfer.value, - call.context.scheme.into(), - ); - } + self.start_trace( + data.subroutine.depth() as usize, + call.context.code_address, + call.input.to_vec(), + call.transfer.value, + call.context.scheme.into(), + ); (Return::Continue, Gas::new(call.gas_limit), Bytes::new()) } @@ -98,20 +93,18 @@ where fn call_end( &mut self, data: &mut EVMData<'_, DB>, - call: &CallInputs, + _call: &CallInputs, gas: Gas, status: Return, retdata: Bytes, _: bool, ) -> (Return, Gas, Bytes) { - if call.contract != HARDHAT_CONSOLE_ADDRESS { - self.fill_trace( - matches!(status, return_ok!()), - gas_used(data.env.cfg.spec_id, gas.spend(), gas.refunded() as u64), - retdata.to_vec(), - None, - ); - } + self.fill_trace( + matches!(status, return_ok!()), + gas_used(data.env.cfg.spec_id, gas.spend(), gas.refunded() as u64), + retdata.to_vec(), + None, + ); (status, gas, retdata) } diff --git a/evm/src/trace/decoder.rs b/evm/src/trace/decoder.rs index 0d06177b7e1e..7083f09039bb 100644 --- a/evm/src/trace/decoder.rs +++ b/evm/src/trace/decoder.rs @@ -3,7 +3,7 @@ use super::{ RawOrDecodedReturnData, }; use crate::{ - abi::{CHEATCODE_ADDRESS, CONSOLE_ABI, HEVM_ABI}, + abi::{CHEATCODE_ADDRESS, CONSOLE_ABI, HARDHAT_CONSOLE_ABI, HARDHAT_CONSOLE_ADDRESS, HEVM_ABI}, trace::{node::CallTraceNode, utils}, }; use ethers::{ @@ -79,6 +79,12 @@ impl CallTraceDecoder { /// The call trace decoder always knows how to decode calls to the cheatcode address, as well /// as DSTest-style logs. pub fn new() -> Self { + let functions = HARDHAT_CONSOLE_ABI + .functions() + .map(|func| (func.short_signature(), vec![func.clone()])) + .chain(HEVM_ABI.functions().map(|func| (func.short_signature(), vec![func.clone()]))) + .collect::>>(); + Self { // TODO: These are the Ethereum precompiles. We should add a way to support precompiles // for other networks, too. @@ -153,11 +159,12 @@ impl CallTraceDecoder { ] .into(), contracts: Default::default(), - labels: [(CHEATCODE_ADDRESS, "VM".to_string())].into(), - functions: HEVM_ABI - .functions() - .map(|func| (func.short_signature(), vec![func.clone()])) - .collect::>>(), + labels: [ + (CHEATCODE_ADDRESS, "VM".to_string()), + (HARDHAT_CONSOLE_ADDRESS, "console".to_string()), + ] + .into(), + functions, events: CONSOLE_ABI .events() .map(|event| ((event.signature(), indexed_inputs(event)), vec![event.clone()]))