From 7586a2262249c438ffc1ad58b345b57c52c5b233 Mon Sep 17 00:00:00 2001 From: Stan Kladko <13399135+kladkogex@users.noreply.github.com> Date: Sun, 15 Oct 2023 17:38:58 +0100 Subject: [PATCH] 1664 adding call trace --- libevm/LegacyVM.h | 4 ++++ libevm/LegacyVMCalls.cpp | 3 +++ libhistoric/AlethTraceBase.cpp | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libevm/LegacyVM.h b/libevm/LegacyVM.h index abbd9c52f..f8ab3df13 100644 --- a/libevm/LegacyVM.h +++ b/libevm/LegacyVM.h @@ -83,6 +83,10 @@ class LegacyVM : public VMFace { /// RETURNDATA buffer for memory returned from direct subcalls. bytes m_returnData; +public: + const bytes& getMReturnData() const; + +private: // space for data stack, grows towards smaller addresses from the end u256 m_stack[1024]; u256* m_stackEnd = &m_stack[1024]; diff --git a/libevm/LegacyVMCalls.cpp b/libevm/LegacyVMCalls.cpp index a399a9b10..8e6b3dd39 100644 --- a/libevm/LegacyVMCalls.cpp +++ b/libevm/LegacyVMCalls.cpp @@ -271,3 +271,6 @@ evmc_status_code LegacyVM::getAndClearLastCallStatus() const { return ret; } +const bytes& LegacyVM::getMReturnData() const { + return m_returnData; +} diff --git a/libhistoric/AlethTraceBase.cpp b/libhistoric/AlethTraceBase.cpp index a8db59ee2..128af3b90 100644 --- a/libhistoric/AlethTraceBase.cpp +++ b/libhistoric/AlethTraceBase.cpp @@ -187,7 +187,7 @@ void AlethTraceBase::processFunctionCallOrReturnIfHappened( functionCalled( _ext.caller, _ext.myAddress, _gasRemaining, data, _ext.value ); } else if ( currentDepth == m_lastOp.m_depth - 1 ) { auto status = _vm->getAndClearLastCallStatus(); - functionReturned( status ); + functionReturned( status, _vm->getMReturnData() ); } else { // we should not have skipped frames STATE_CHECK( currentDepth == m_lastOp.m_depth ) @@ -228,11 +228,13 @@ void AlethTraceBase::functionCalled( const Address& _from, const Address& _to, u } -void AlethTraceBase::functionReturned( evmc_status_code _status ) { +void AlethTraceBase::functionReturned( evmc_status_code _status, const vector< uint8_t >& _returnData ) { STATE_CHECK( m_lastOp.m_gasRemaining >= m_lastOp.m_opGas ) uint64_t gasRemainingOnReturn = m_lastOp.m_gasRemaining - m_lastOp.m_opGas; + m_lastOp.m_returnData = _returnData; + if ( m_lastOp.m_op == Instruction::INVALID ) { // invalid instruction consumers all gas gasRemainingOnReturn = 0;