Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Only filter duplicate instrumentation hashes within transaction
  • Loading branch information
cgewecke committed Feb 25, 2024
commit 34d6ff1e7600b5acf45157a51be1803bd503bb60
10 changes: 8 additions & 2 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DataCollector {

this.lastHash = null;
this.viaIR = viaIR;
this.pcZeroCounter = 0;
this.lastPcZeroCount = 0;
}

/**
Expand All @@ -36,11 +38,13 @@ class DataCollector {
* @param {Object} info vm step info
*/
step(info){
if (info.pc === 0) this.pcZeroCounter++;

try {
if (this.validOpcodes[info.opcode.name] && info.stack.length > 0){
const idx = info.stack.length - 1;
let hash = '0x' + info.stack[idx].toString(16);
this._registerHash(hash)
this._registerHash(hash);
}
} catch (err) { /*Ignore*/ };
}
Expand All @@ -66,8 +70,10 @@ class DataCollector {

if(this.instrumentationData[hash]){
// abi.encode (used to circumvent viaIR) sometimes puts the hash on the stack twice
if (this.lastHash !== hash) {
// We should only skip duplicate hashes *within* a transaction (see issue #863)
if (this.lastHash !== hash || this.lastPcZeroCount !== this.pcZeroCounter) {
this.lastHash = hash;
this.lastPcZeroCount = this.pcZeroCounter;
this.instrumentationData[hash].hits++
}
return;
Expand Down