Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1767 fix geth skaled trace inconsistencies #1804

Merged
merged 87 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
36a18b3
#1751 case where no contract is called
kladkogex Jan 22, 2024
966169e
#1767 enforce transactions in block and refactor for clarity
kladkogex Jan 22, 2024
c586bc6
#1767 enforce transactions in block and refactor for clarity
kladkogex Jan 22, 2024
80d5bd0
#1767 enforce transactions in block and refactor for clarity
kladkogex Jan 22, 2024
e2de353
#1767 enforce transactions in block and refactor for clarity
kladkogex Jan 22, 2024
a75f38e
#1767 fix exception log
kladkogex Jan 23, 2024
5bbe977
#1767 add error printing for call trace
kladkogex Jan 23, 2024
0620b0f
#1767 make error message same as geth
kladkogex Jan 23, 2024
603fa9c
#1767 make error message same as geth
kladkogex Jan 23, 2024
ee78dc4
#1767 fixed default tracer
kladkogex Jan 23, 2024
499208a
#1767 cleaing up API
kladkogex Jan 24, 2024
4c045ca
#1767 cleaing up API
kladkogex Jan 24, 2024
2b25746
#1749 Fix tests
kladkogex Jan 26, 2024
353869b
#1749 Fix tests
kladkogex Jan 26, 2024
8b1ec08
#1767 Add tests
kladkogex Jan 26, 2024
d9aeb6f
#1767 Add tests
kladkogex Jan 26, 2024
db5c06c
#1767 Add tests
kladkogex Jan 26, 2024
d1458a1
#1767 Add tests
kladkogex Jan 26, 2024
5f73aba
#1767 Add tests
kladkogex Jan 26, 2024
d734268
#1767 Add tests
kladkogex Jan 26, 2024
ab2364f
#1767 Figured out the case for contract nonce
kladkogex Jan 26, 2024
b98da94
#1767 Figured out the case for contract nonce
kladkogex Jan 26, 2024
5eb5947
#1767 Figured out the case for contract nonce
kladkogex Jan 26, 2024
08be2f3
#1767 Adding deploy tests
kladkogex Jan 28, 2024
91b9372
#1767 Figured out the case for contract nonce
kladkogex Jan 28, 2024
2e28252
#1767 Figured out the case for contract nonce
kladkogex Jan 28, 2024
2dd28e2
#1767 Figured out the case for contract nonce
kladkogex Jan 28, 2024
8e2dce1
#1767 Figured out the case for contract nonce
kladkogex Jan 28, 2024
f279b35
#1767 Call trace for deploy
kladkogex Jan 28, 2024
93be658
#1767 fixed call tracer for deploy
kladkogex Jan 29, 2024
c148e32
#1767 fixed call tracer for deploy
kladkogex Jan 29, 2024
d8d7658
#1767 fixed call tracer for deploy
kladkogex Jan 29, 2024
2b6076a
#1767 fixed fourbyte tracer diffs
kladkogex Jan 29, 2024
959960e
#1767 fixing tests
kladkogex Jan 29, 2024
124d7c0
#1767 fix prestate trace for contract deployment
kladkogex Jan 30, 2024
4c72c56
#1767 fix prestate trace for contract deployment
kladkogex Jan 30, 2024
898077a
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
6a87833
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
5cf9371
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
abef9a4
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
d3d9e25
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
e27d988
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
46e41ff
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 30, 2024
03002b9
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
39c4028
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
0356762
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
47bcff1
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
1574ee4
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
c9857e1
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
e7e6776
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
4f6c417
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
36d4ab6
#1767 fix prestate diff trace for contract deployment
kladkogex Jan 31, 2024
7c62b78
#1767 fix from balance
kladkogex Feb 1, 2024
a6dcfc6
#1767 fix from balance
kladkogex Feb 1, 2024
eb4feaa
#1767 fix from balance
kladkogex Feb 1, 2024
4c0d3c5
#1767 fix from balance
kladkogex Feb 1, 2024
92d7d49
#1767 fix from balance
kladkogex Feb 1, 2024
e18f6cb
#1767 fix from balance
kladkogex Feb 1, 2024
8c888fd
#1767 fix from balance
kladkogex Feb 1, 2024
ed10fae
#1767 fix from balance
kladkogex Feb 1, 2024
019e0cf
#1767 fix from balance
kladkogex Feb 1, 2024
7b025f7
#1767 fix second mint
kladkogex Feb 1, 2024
2ae83b3
#1767 fix to in create contract
kladkogex Feb 2, 2024
8f7dfdf
#1767 fix to in create contract
kladkogex Feb 2, 2024
f1ee327
#1767 fix input output in create create2
kladkogex Feb 2, 2024
a70849b
#1767 fix 4byte trace for constructor
kladkogex Feb 2, 2024
48e937b
#1767 fix default trace verification
kladkogex Feb 2, 2024
997010a
#1767 fix default trace verification
kladkogex Feb 2, 2024
475134a
#1767 fix default trace
kladkogex Feb 2, 2024
8dff539
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
088bd9e
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
718bca5
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
81e5915
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
9bc01ed
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
6068c80
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
4ebe0f0
#1767 prestate diff for newly created contract
kladkogex Feb 2, 2024
f9a9b4e
#1767 fix clang format
kladkogex Feb 2, 2024
babfd62
#1767 fix clang format
kladkogex Feb 2, 2024
659e8cb
#1767 fix clang format
kladkogex Feb 2, 2024
fad2815
#1767 fix clang format
kladkogex Feb 2, 2024
224291c
#1767 fix clang format
kladkogex Feb 2, 2024
de133d7
#1767 fix clang format
kladkogex Feb 2, 2024
4843beb
#1767 fix clang format
kladkogex Feb 2, 2024
7f44620
#1767 fix clang format
kladkogex Feb 2, 2024
6325d48
Merge branch 'v3.17.2' into 1767_tracer_fields
kladkogex Feb 23, 2024
026ce59
1767 Fixed test crash
kladkogex Feb 23, 2024
dbac33c
Merge branch 'v3.17.2' into 1767_tracer_fields
kladkogex Feb 23, 2024
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
5 changes: 3 additions & 2 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,9 @@

auto resultReceipt = m_state.mutableHistoricState().execute(
envInfo, *m_sealEngine, _t, skale::Permanence::Uncommitted, onOp );
HistoricState stateAfter( m_state.mutableHistoricState() );
_tracer->finalizeAndPrintTrace( resultReceipt.first, stateBefore, stateAfter );

_tracer->finalizeAndPrintTrace(

Check warning on line 825 in libethereum/Block.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Block.cpp#L825

Added line #L825 was not covered by tests
resultReceipt.first, stateBefore, m_state.mutableHistoricState() );
// for tracing the entire block is traced therefore, we save transaction receipt
// as it is used for execution of the next transaction
m_receipts.push_back( resultReceipt.second );
Expand Down
12 changes: 12 additions & 0 deletions libethereum/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
case TransactionException::InvalidContractDeployer:
_out << "InvalidContractDeployer";
break;
case TransactionException::RevertInstruction:
_out << "RevertInstruction";
break;
case TransactionException::InvalidZeroSignatureFormat:
_out << "InvalidZeroSignatureFormat";
break;
case TransactionException::AddressAlreadyUsed:
_out << "AddressAlreadyUsed";
break;
case TransactionException::WouldNotBeInBlock:
_out << "WouldNotBeInBlock";
break;

Check warning on line 137 in libethereum/Transaction.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Transaction.cpp#L126-L137

Added lines #L126 - L137 were not covered by tests
default:
_out << "Unknown";
break;
Expand Down
13 changes: 11 additions & 2 deletions libhistoric/AlethExtVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
_e.go( _onOp );
} catch ( ... ) {
exception = boost::current_exception(); // Catch all exceptions to be rethrown in
// parent thread.
// parent thread.
}
}
}.join();
Expand Down Expand Up @@ -88,9 +88,15 @@
case TransactionException::RevertInstruction:
return EVMC_REVERT;

case TransactionException::OutOfGasIntrinsic:
return EVMC_OUT_OF_GAS;

Check warning on line 92 in libhistoric/AlethExtVM.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethExtVM.cpp#L91-L92

Added lines #L91 - L92 were not covered by tests

case TransactionException::OutOfGas:
return EVMC_OUT_OF_GAS;

case TransactionException::OutOfGasBase:
return EVMC_OUT_OF_GAS;

Check warning on line 98 in libhistoric/AlethExtVM.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethExtVM.cpp#L97-L98

Added lines #L97 - L98 were not covered by tests

case TransactionException::BadInstruction:
return EVMC_UNDEFINED_INSTRUCTION;

Expand All @@ -100,9 +106,12 @@
case TransactionException::StackUnderflow:
return EVMC_STACK_UNDERFLOW;

case TransactionException ::BadJumpDestination:
case TransactionException::BadJumpDestination:

Check warning on line 109 in libhistoric/AlethExtVM.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethExtVM.cpp#L109

Added line #L109 was not covered by tests
return EVMC_BAD_JUMP_DESTINATION;

case TransactionException::InvalidContractDeployer:
return EVMC_CONTRACT_VALIDATION_FAILURE;

Check warning on line 113 in libhistoric/AlethExtVM.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethExtVM.cpp#L112-L113

Added lines #L112 - L113 were not covered by tests

default:
return EVMC_FAILURE;
}
Expand Down
81 changes: 73 additions & 8 deletions libhistoric/AlethStandardTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
vector< uint8_t > returnData;
uint64_t logTopicsCount = 0;
switch ( _inst ) {
// record storage accesses
// record storage accesses
case Instruction::SLOAD:
// SLOAD - record storage access
// the stackSize() check prevents malicios code crashing the tracer
Expand All @@ -67,7 +67,7 @@
_vm->getStackElement( 1 );
}
break;
// NOW HANDLE CONTRACT FUNCTION CALL INSTRUCTIONS
// NOW HANDLE CONTRACT FUNCTION CALL INSTRUCTIONS
case Instruction::CALL:
case Instruction::CALLCODE:
case Instruction::DELEGATECALL:
Expand All @@ -78,7 +78,7 @@
m_accessedAccounts.insert( address );
}
break;
// NOW HANDLE SUICIDE
// NOW HANDLE SUICIDE
case Instruction::SUICIDE:
if ( _vm->stackSize() > 0 ) {
m_accessedAccounts.insert( asAddress( _vm->getStackElement( 0 ) ) );
Expand Down Expand Up @@ -118,18 +118,31 @@
// check if instruction depth changed. This means a function has been called or has returned

if ( currentDepth == m_lastOpRecord.m_depth + 1 ) {
// we are beginning to execute a new function
auto data = _ext.data.toVector();
recordFunctionIsCalled( _ext.caller, _ext.myAddress, _gasRemaining, data, _ext.value );
recordFunctionIsCalled(
_ext.caller, _ext.myAddress, _gasRemaining, getInputData( _ext ), _ext.value );

Check warning on line 122 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L121-L122

Added lines #L121 - L122 were not covered by tests
} else if ( currentDepth == m_lastOpRecord.m_depth - 1 ) {
auto status = _vm->getAndClearLastCallStatus();

recordFunctionReturned( status, _vm->getReturnData(),
getCurrentlyExecutingFunctionCall()->getFunctionGasLimit() - _gasRemaining );
} else {
// depth did not increase or decrease by one, therefore it should be the same
STATE_CHECK( currentDepth == m_lastOpRecord.m_depth )
}
}

vector< uint8_t > AlethStandardTrace::getInputData( const AlethExtVM& _ext ) const {
if ( m_lastOpRecord.m_op == Instruction::CREATE ||
m_lastOpRecord.m_op == Instruction::CREATE2 ) {

Check warning on line 136 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L134-L136

Added lines #L134 - L136 were not covered by tests
// we are in a constructor code, so input to the function is current
// code
return _ext.code;

Check warning on line 139 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L139

Added line #L139 was not covered by tests
} else {
// we are in a regular function so input is inputData field of _ext
return _ext.data.toVector();

Check warning on line 142 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L142

Added line #L142 was not covered by tests
}
}

const Address& AlethStandardTrace::getFrom() const {
STATE_CHECK( m_isFinalized )
return m_from;
Expand Down Expand Up @@ -266,6 +279,7 @@
STATE_CHECK( m_isFinalized )
return m_gasLimit;
}

void AlethStandardTrace::setOriginalFromBalance( const u256& _originalFromBalance ) {
STATE_CHECK( !m_isFinalized )
m_originalFromBalance = _originalFromBalance;
Expand Down Expand Up @@ -386,21 +400,49 @@
ExecutionResult& _er, HistoricState& _statePre, HistoricState& _statePost ) {
m_totalGasUsed = ( uint64_t ) _er.gasUsed;

auto statusCode = AlethExtVM::transactionExceptionToEvmcStatusCode( _er.excepted );
m_output = _er.output;
m_deployedContractAddress = _er.newAddress;
m_evmcStatusCode = AlethExtVM::transactionExceptionToEvmcStatusCode( _er.excepted );

Check warning on line 405 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L403-L405

Added lines #L403 - L405 were not covered by tests

STATE_CHECK( m_topFunctionCall == m_currentlyExecutingFunctionCall )

// if transaction is not just ETH transfer
// record return of the top function.
if ( m_topFunctionCall ) {
recordFunctionReturned( statusCode, _er.output, m_totalGasUsed );
recordFunctionReturned( m_evmcStatusCode, m_output, m_totalGasUsed );

Check warning on line 412 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L412

Added line #L412 was not covered by tests
}


recordMinerFeePayment( _statePost );

Check warning on line 416 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L416

Added line #L416 was not covered by tests


// we are done. Set the trace to finalized
STATE_CHECK( !m_isFinalized.exchange( true ) )
// now print trace
printTrace( _er, _statePre, _statePost );
}

void eth::AlethStandardTrace::recordMinerFeePayment( HistoricState& _statePost ) {
if ( !m_isCall ) { // geth does not record miner fee payments in call traces
auto fee = m_gasPrice * m_totalGasUsed;
auto fromPostBalance = _statePost.balance( m_from );
STATE_CHECK( fromPostBalance >= fee )
_statePost.setBalance( m_from, fromPostBalance - fee );
auto minerBalance = _statePost.balance( m_blockAuthor );
_statePost.setBalance( m_blockAuthor, minerBalance + fee );

Check warning on line 432 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L425-L432

Added lines #L425 - L432 were not covered by tests
}
}

Check warning on line 434 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L434

Added line #L434 was not covered by tests

const bytes& AlethStandardTrace::getOutput() const {
STATE_CHECK( m_isFinalized )
return m_output;

Check warning on line 438 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L436-L438

Added lines #L436 - L438 were not covered by tests
}

bool AlethStandardTrace::isFailed() const {
STATE_CHECK( m_isFinalized )
return m_evmcStatusCode != EVMC_SUCCESS;

Check warning on line 443 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L441-L443

Added lines #L441 - L443 were not covered by tests
}

void eth::AlethStandardTrace::printTrace( ExecutionResult& _er, const HistoricState& _statePre,
const HistoricState& _statePost ) { // now print the trace
m_jsonTrace = Json::Value( Json::objectValue );
Expand Down Expand Up @@ -496,10 +538,12 @@
STATE_CHECK( m_isFinalized )
return m_inputData;
}

const u256& AlethStandardTrace::getValue() const {
STATE_CHECK( m_isFinalized )
return m_value;
}

const Address& AlethStandardTrace::getTo() const {
STATE_CHECK( m_isFinalized )
return m_to;
Expand All @@ -509,6 +553,27 @@
STATE_CHECK( m_isFinalized )
return m_gasPrice;
}

evmc_status_code AlethStandardTrace::getEVMCStatusCode() const {
STATE_CHECK( m_isFinalized )
return m_evmcStatusCode;

Check warning on line 559 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L557-L559

Added lines #L557 - L559 were not covered by tests
}

const Address& AlethStandardTrace::getDeployedContractAddress() const {
return m_deployedContractAddress;

Check warning on line 563 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L562-L563

Added lines #L562 - L563 were not covered by tests
}

// return true if transaction is a simple Eth transfer
[[nodiscard]] bool AlethStandardTrace::isSimpleTransfer() {
return !m_topFunctionCall;

Check warning on line 568 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L567-L568

Added lines #L567 - L568 were not covered by tests
}

// return true if transaction is contract creation
[[nodiscard]] bool AlethStandardTrace::isContractCreation() {
return m_topFunctionCall && m_topFunctionCall->getType() == Instruction::CREATE;

Check warning on line 573 in libhistoric/AlethStandardTrace.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/AlethStandardTrace.cpp#L572-L573

Added lines #L572 - L573 were not covered by tests
}

} // namespace dev::eth


#endif
31 changes: 19 additions & 12 deletions libhistoric/AlethStandardTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AlethStandardTrace {
[[nodiscard]] const std::set< Address >& getAccessedAccounts() const;
[[nodiscard]] const h256& getTxHash() const;
[[nodiscard]] const std::shared_ptr< Json::Value >& getDefaultOpTrace() const;

[[nodiscard]] const Address& getDeployedContractAddress() const;
[[nodiscard]] const std::shared_ptr< FunctionCallRecord >& getCurrentlyExecutingFunctionCall()
const;
[[nodiscard]] const Address& getBlockAuthor() const;
Expand All @@ -95,9 +95,14 @@ class AlethStandardTrace {
[[nodiscard]] const u256& getValue() const;
[[nodiscard]] const bytes& getInputData() const;
[[nodiscard]] const Address& getTo() const;
[[nodiscard]] const u256& getGasPrice() const;
[[nodiscard]] const bytes& getOutput() const;
[[nodiscard]] bool isFailed() const;
[[nodiscard]] evmc_status_code getEVMCStatusCode() const;
[[nodiscard]] bool isSimpleTransfer();
[[nodiscard]] bool isContractCreation();

static string toGethCompatibleCompactHexPrefixed( const u256& _value );

[[nodiscard]] static string toGethCompatibleCompactHexPrefixed( const u256& _value );

private:
void setCurrentlyExecutingFunctionCall(
Expand Down Expand Up @@ -130,7 +135,6 @@ class AlethStandardTrace {
[[nodiscard]] static std::vector< std::uint8_t >
extractSmartContractMemoryByteArrayFromStackPointer( const LegacyVM* _vm );


// this is called when the function call depth of the current instruction is different from the
// previous instruction. This happens when a function is called or returned.
void processFunctionCallOrReturnIfHappened(
Expand All @@ -145,6 +149,13 @@ class AlethStandardTrace {

void recordMinerPayment( u256 _minerGasPayment );

void printTrace(
ExecutionResult& _er, const HistoricState& _statePre, const HistoricState& _statePost );

[[nodiscard]] vector< uint8_t > getInputData( const AlethExtVM& _ext ) const;

void recordMinerFeePayment( HistoricState& _statePost );

std::shared_ptr< FunctionCallRecord > m_topFunctionCall;
std::shared_ptr< FunctionCallRecord > m_currentlyExecutingFunctionCall;
std::vector< Instruction > m_lastInst;
Expand Down Expand Up @@ -176,18 +187,14 @@ class AlethStandardTrace {
u256 m_minerPayment;
u256 m_originalFromBalance;
bool m_isCall;

public:
const u256& getGasPrice() const;

private:
uint64_t m_totalGasUsed;
u256 m_value;
u256 m_gasLimit;
bytes m_inputData;
u256 m_gasPrice;

void printTrace(
ExecutionResult& _er, const HistoricState& _statePre, const HistoricState& _statePost );
bytes m_output;
evmc_status_code m_evmcStatusCode;
// this will include deployed contract address if the transaction was CREATE
Address m_deployedContractAddress;
};
} // namespace dev::eth
36 changes: 26 additions & 10 deletions libhistoric/CallTracePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,36 @@
namespace dev::eth {

// call tracer as implemented by geth
void CallTracePrinter::print(
Json::Value& _jsonTrace, const ExecutionResult&, const HistoricState&, const HistoricState& ) {
void CallTracePrinter::print( Json::Value& _jsonTrace, const ExecutionResult&, const HistoricState&,

Check warning on line 31 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L31

Added line #L31 was not covered by tests
const HistoricState& _statePost ) {
STATE_CHECK( _jsonTrace.isObject() )

auto topFunctionCallRecord = m_trace.getTopFunctionCall();
if ( !topFunctionCallRecord ) {
// no bytecodes were executed
// first print error description if the transaction failed
if ( m_trace.isFailed() ) {
_jsonTrace["error"] = getEvmErrorDescription( m_trace.getEVMCStatusCode() );

Check warning on line 37 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L36-L37

Added lines #L36 - L37 were not covered by tests
}

// now deal with the cases of simple ETH transfer vs contract interaction
if ( m_trace.isSimpleTransfer() ) {

Check warning on line 41 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L41

Added line #L41 was not covered by tests
// no bytecode was executed
printTransferTrace( _jsonTrace );
} else {
topFunctionCallRecord->printTrace( _jsonTrace, 0, m_trace.getOptions() );
printContractTransactionTrace( _jsonTrace, _statePost );

Check warning on line 45 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L45

Added line #L45 was not covered by tests
}
}
void CallTracePrinter::printContractTransactionTrace(

Check warning on line 48 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L47-L48

Added lines #L47 - L48 were not covered by tests
Json::Value& _jsonTrace, const HistoricState& _statePost ) {
auto topFunctionCall = m_trace.getTopFunctionCall();
STATE_CHECK( topFunctionCall );

Check warning on line 51 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L50-L51

Added lines #L50 - L51 were not covered by tests
// call trace on the top Solidity function call in the stack
// this will also recursively call printTrace on nested calls if exist
topFunctionCall->printTrace( _jsonTrace, _statePost, 0, m_trace.getOptions() );

Check warning on line 54 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L54

Added line #L54 was not covered by tests
// handle the case of a transaction that deploys a contract
// in this case geth prints transaction input data as input
// end prints to as newly created contract address
if ( m_trace.isContractCreation() ) {
_jsonTrace["input"] = toHexPrefixed( m_trace.getInputData() );
_jsonTrace["to"] = toHexPrefixed( m_trace.getDeployedContractAddress() );

Check warning on line 60 in libhistoric/CallTracePrinter.cpp

View check run for this annotation

Codecov / codecov/patch

libhistoric/CallTracePrinter.cpp#L58-L60

Added lines #L58 - L60 were not covered by tests
}
}

Expand All @@ -51,16 +71,12 @@
_jsonTrace["type"] = "CALL";
_jsonTrace["from"] = toHexPrefixed( m_trace.getFrom() );
_jsonTrace["to"] = toHexPrefixed( m_trace.getTo() );

_jsonTrace["gas"] =
AlethStandardTrace::toGethCompatibleCompactHexPrefixed( m_trace.getGasLimit() );
_jsonTrace["gasUsed"] =
AlethStandardTrace::toGethCompatibleCompactHexPrefixed( m_trace.getTotalGasUsed() );


_jsonTrace["value"] =
AlethStandardTrace::toGethCompatibleCompactHexPrefixed( m_trace.getValue() );

_jsonTrace["input"] = toHexPrefixed( m_trace.getInputData() );
}

Expand Down
2 changes: 2 additions & 0 deletions libhistoric/CallTracePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ class CallTracePrinter : public TracePrinter {

private:
void printTransferTrace( Json::Value& _jsonTrace );

void printContractTransactionTrace( Json::Value& _jsonTrace, const HistoricState& _statePost );
};
} // namespace dev::eth
Loading
Loading