Skip to content

Commit

Permalink
#1751 case where no contract is called
Browse files Browse the repository at this point in the history
  • Loading branch information
kladkogex committed Jan 17, 2024
1 parent 64f4b5b commit 51d2ce6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
29 changes: 20 additions & 9 deletions libhistoric/PrestateTracePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ void PrestateTracePrinter::print( Json::Value& _jsonTrace, const ExecutionResult
if ( m_trace.getOptions().prestateDiffMode ) {
printDiff( _jsonTrace, _er, _statePre, _statePost );
} else {
printPre( _jsonTrace, _statePre );
printPre( _jsonTrace, _statePre, _statePost );
}
}
void PrestateTracePrinter::printPre( Json::Value& _jsonTrace, const HistoricState& _statePre ) {
void PrestateTracePrinter::printPre(
Json::Value& _jsonTrace, const HistoricState& _statePre, const HistoricState& _statePost ) {
for ( auto&& item : m_trace.getAccessedAccounts() ) {
printAllAccessedAccountPreValues( _jsonTrace, _statePre, item );
printAllAccessedAccountPreValues( _jsonTrace, _statePre, _statePost, item );
};

// geth always prints the balance of block miner balance
Expand Down Expand Up @@ -74,8 +75,8 @@ void PrestateTracePrinter::printDiff( Json::Value& _jsonTrace, const ExecutionRe


// this function returns original values (pre) to result
void PrestateTracePrinter::printAllAccessedAccountPreValues(
Json::Value& _jsonTrace, const HistoricState& _statePre, const Address& _address ) {
void PrestateTracePrinter::printAllAccessedAccountPreValues( Json::Value& _jsonTrace,
const HistoricState& _statePre, const HistoricState& _statePost, const Address& _address ) {
STATE_CHECK( _jsonTrace.isObject() )


Expand All @@ -86,12 +87,22 @@ void PrestateTracePrinter::printAllAccessedAccountPreValues(

auto balance = _statePre.balance( _address );

// take into account that for calls balance is modified in the state before execution
if ( m_trace.isCall() && _address == m_trace.getFrom() ) {
// take into account that for calls balance is modified in the state before execution
balance = m_trace.getOriginalFromBalance();
} else {
// geth does not print nonce for from address in debug_traceCall;
accountPreValues["nonce"] = ( uint64_t ) _statePre.getNonce( _address );
}


// geth does not print nonce for from address in debug_traceCall;
bool dontPrintNonce = m_trace.isCall() && _address == m_trace.getFrom();

if (!dontPrintNonce) {
auto preNonce = ( uint64_t ) _statePre.getNonce( _address );
auto postNonce = ( uint64_t ) _statePost.getNonce( _address );
// in calls nonce is always printed by geth
if (postNonce != preNonce || m_trace.isCall()) {
accountPreValues["nonce"] = preNonce;
}
}

accountPreValues["balance"] = AlethStandardTrace::toGethCompatibleCompactHexPrefixed( balance );
Expand Down
7 changes: 4 additions & 3 deletions libhistoric/PrestateTracePrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class PrestateTracePrinter : public TracePrinter {
void printDiff( Json::Value& _jsonTrace, const ExecutionResult&, const HistoricState& _statePre,
const HistoricState& _statePost );

void printAllAccessedAccountPreValues(
Json::Value& _jsonTrace, const HistoricState& _statePre, const Address& _address );
void printAllAccessedAccountPreValues( Json::Value& _jsonTrace, const HistoricState& _statePre,
const HistoricState& _statePost, const Address& _address );

void printAccountPreDiff( Json::Value& _preDiffTrace, const HistoricState& _statePre,
const HistoricState& _statePost, const Address& _address );
Expand All @@ -54,6 +54,7 @@ class PrestateTracePrinter : public TracePrinter {
uint64_t m_storageValuesReturnedPre = 0;
uint64_t m_storageValuesReturnedPost = 0;
uint64_t m_storageValuesReturnedAll = 0;
void printPre( Json::Value& _jsonTrace, const HistoricState& _statePre );
void printPre(
Json::Value& _jsonTrace, const HistoricState& _statePre, const HistoricState& _statePost );
};
} // namespace dev::eth
4 changes: 3 additions & 1 deletion test/historicstate/hardhat/scripts/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ async function verifyPrestateTransferTraceAgainstGethTrace(_fileName: string) {
}
}

console.log(`Found difference (lhs is expected value) ${index + 1} at path:`, difference.path);
console.log(`Difference ${index + 1}:`, difference);

foundDiffs = true;
});
}
Expand Down Expand Up @@ -637,7 +640,6 @@ async function main(): Promise<void> {
}

await verifyPrestateTransferTraceAgainstGethTrace(TEST_TRANSFER_PRESTATETRACER_FILE_NAME);

await verifyTransferTraceAgainstGethTrace(TEST_TRANSFER_DEFAULTTRACER_FILE_NAME);
await verifyTransferTraceAgainstGethTrace(TEST_TRANSFER_CALLTRACER_FILE_NAME);

Expand Down

0 comments on commit 51d2ce6

Please sign in to comment.