Check all PUSH opcodes for instr. hashes when viaIR is true (#871)

pull/873/head
cgewecke 9 months ago committed by GitHub
parent 32029b4fb6
commit 943a6fe56a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 44
      lib/collector.js
  2. 2
      package.json
  3. 2
      test/util/util.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

@ -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"
},

@ -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);

Loading…
Cancel
Save