Skip to content

Commit

Permalink
Check all PUSH opcodes for instr. hashes when viaIR is true (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Feb 29, 2024
1 parent 32029b4 commit 943a6fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
44 changes: 24 additions & 20 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions test/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 943a6fe

Please sign in to comment.