From 6839e92d8fcdb9bf57a5ac73892e6c333397643c Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 27 Feb 2024 07:13:24 -0800 Subject: [PATCH] Improve organization of edge case code in collector (#869) --- lib/collector.js | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/lib/collector.js b/lib/collector.js index 320d2f3..e382cc1 100644 --- a/lib/collector.js +++ b/lib/collector.js @@ -49,18 +49,6 @@ class DataCollector { } catch (err) { /*Ignore*/ }; } - // Temporarily disabled because some relevant traces aren't available - /** - * Converts pushData value to string and registers in instrumentation map. - * @param {HardhatEVMTraceInstruction} instruction - */ - /*trackHardhatEVMInstruction(instruction){ - if (instruction && instruction.pushData){ - let hash = `0x` + instruction.pushData.toString('hex'); - this._registerHash(hash) - } - }*/ - /** * Normalizes has string and marks hit. * @param {String} hash bytes32 hash @@ -78,20 +66,6 @@ class DataCollector { } return; } - - // Detect and recover from viaIR mangled hashes by left-padding single `0` - if(this.viaIR && hash.length === 18) { - hash = hash.slice(2); - hash = '0' + hash; - hash = hash.slice(0,16); - hash = '0x' + hash; - if(this.instrumentationData[hash]){ - if (this.lastHash !== hash) { - this.lastHash = hash; - this.instrumentationData[hash].hits++ - } - } - } } /** @@ -107,6 +81,15 @@ class DataCollector { // but it doesn't preserve leading zeroes when it does this if (this.viaIR && hash.length >= 18) { hash = hash.slice(0,18); + + // Detect and recover from viaIR mangled hashes by left-padding single `0` + if(!this.instrumentationData[hash]) { + hash = hash.slice(2); + hash = '0' + hash; + hash = hash.slice(0,16); + hash = '0x' + hash; + } + } else if (hash.length < 18 && hash.length > 11){ hash = hash.slice(2); while(hash.length < 16) hash = '0' + hash; @@ -124,4 +107,4 @@ class DataCollector { } } -module.exports = DataCollector; \ No newline at end of file +module.exports = DataCollector;