diff --git a/lib/collector.js b/lib/collector.js index e382cc1..c56dd0d 100644 --- a/lib/collector.js +++ b/lib/collector.js @@ -6,26 +6,7 @@ class DataCollector { constructor(instrumentationData={}, viaIR){ this.instrumentationData = instrumentationData; - this.validOpcodes = { - "PUSH1": true, - "DUP1": viaIR, - "DUP2": viaIR, - "DUP3": viaIR, - "DUP4": viaIR, - "DUP5": viaIR, - "DUP6": viaIR, - "DUP7": viaIR, - "DUP8": viaIR, - "DUP9": viaIR, - "DUP10": viaIR, - "DUP11": viaIR, - "DUP12": viaIR, - "DUP13": viaIR, - "DUP14": viaIR, - "DUP15": viaIR, - "DUP16": viaIR, - } - + this.validOpcodes = this._getOpcodes(viaIR); this.lastHash = null; this.viaIR = viaIR; this.pcZeroCounter = 0; @@ -98,6 +79,29 @@ class DataCollector { return hash; } + /** + * Generates a list of all the opcodes to inspect for instrumentation hashes + * When viaIR is true, it includes all DUPs and PUSHs, so things are a little slower. + * @param {boolean} viaIR + */ + _getOpcodes(viaIR) { + let opcodes = { + "PUSH1": true + }; + + for (let i = 2; i <= 32; i++) { + const key = "PUSH" + i; + opcodes[key] = viaIR; + }; + + for (let i = 1; i <= 16; i++ ) { + const key = "DUP" + i; + opcodes[key] = viaIR; + } + + return opcodes; + } + /** * Unit test helper * @param {Object} data Instrumenter.instrumentationData diff --git a/package.json b/package.json index 47b060b..79e3422 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test:unit": "./scripts/unit.sh", "test:integration": "./scripts/integration.sh", "test:ci": "./scripts/ci.sh", - "test:uint:viaIR": "VIA_IR=true ./scripts/unit.sh", + "test:unit:viaIR": "VIA_IR=true ./scripts/unit.sh", "test:integration:viaIR": "VIA_IR=true ./scripts/integration.sh", "test:ci:viaIR": "VIA_IR=true ./scripts/ci.sh" }, diff --git a/test/util/util.js b/test/util/util.js index 05f44e1..f51e7aa 100644 --- a/test/util/util.js +++ b/test/util/util.js @@ -92,6 +92,8 @@ function getDiffABIs(sourceName, testFile="test.sol", original="Old", current="N // ============================ function instrumentAndCompile(sourceName, api={ config: {} }) { api.config.viaIR = process.env.VIA_IR === "true"; + api.viaIR = process.env.VIA_IR === "true"; + const contract = getCode(`${sourceName}.sol`) const instrumenter = new Instrumenter(api.config); const instrumented = instrumenter.instrument(contract, filePath);