Skip to content

Commit 943a6fe

Browse files
authored
Check all PUSH opcodes for instr. hashes when viaIR is true (#871)
1 parent 32029b4 commit 943a6fe

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

lib/collector.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,7 @@ class DataCollector {
66
constructor(instrumentationData={}, viaIR){
77
this.instrumentationData = instrumentationData;
88

9-
this.validOpcodes = {
10-
"PUSH1": true,
11-
"DUP1": viaIR,
12-
"DUP2": viaIR,
13-
"DUP3": viaIR,
14-
"DUP4": viaIR,
15-
"DUP5": viaIR,
16-
"DUP6": viaIR,
17-
"DUP7": viaIR,
18-
"DUP8": viaIR,
19-
"DUP9": viaIR,
20-
"DUP10": viaIR,
21-
"DUP11": viaIR,
22-
"DUP12": viaIR,
23-
"DUP13": viaIR,
24-
"DUP14": viaIR,
25-
"DUP15": viaIR,
26-
"DUP16": viaIR,
27-
}
28-
9+
this.validOpcodes = this._getOpcodes(viaIR);
2910
this.lastHash = null;
3011
this.viaIR = viaIR;
3112
this.pcZeroCounter = 0;
@@ -98,6 +79,29 @@ class DataCollector {
9879
return hash;
9980
}
10081

82+
/**
83+
* Generates a list of all the opcodes to inspect for instrumentation hashes
84+
* When viaIR is true, it includes all DUPs and PUSHs, so things are a little slower.
85+
* @param {boolean} viaIR
86+
*/
87+
_getOpcodes(viaIR) {
88+
let opcodes = {
89+
"PUSH1": true
90+
};
91+
92+
for (let i = 2; i <= 32; i++) {
93+
const key = "PUSH" + i;
94+
opcodes[key] = viaIR;
95+
};
96+
97+
for (let i = 1; i <= 16; i++ ) {
98+
const key = "DUP" + i;
99+
opcodes[key] = viaIR;
100+
}
101+
102+
return opcodes;
103+
}
104+
101105
/**
102106
* Unit test helper
103107
* @param {Object} data Instrumenter.instrumentationData

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test:unit": "./scripts/unit.sh",
1414
"test:integration": "./scripts/integration.sh",
1515
"test:ci": "./scripts/ci.sh",
16-
"test:uint:viaIR": "VIA_IR=true ./scripts/unit.sh",
16+
"test:unit:viaIR": "VIA_IR=true ./scripts/unit.sh",
1717
"test:integration:viaIR": "VIA_IR=true ./scripts/integration.sh",
1818
"test:ci:viaIR": "VIA_IR=true ./scripts/ci.sh"
1919
},

test/util/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function getDiffABIs(sourceName, testFile="test.sol", original="Old", current="N
9292
// ============================
9393
function instrumentAndCompile(sourceName, api={ config: {} }) {
9494
api.config.viaIR = process.env.VIA_IR === "true";
95+
api.viaIR = process.env.VIA_IR === "true";
96+
9597
const contract = getCode(`${sourceName}.sol`)
9698
const instrumenter = new Instrumenter(api.config);
9799
const instrumented = instrumenter.instrument(contract, filePath);

0 commit comments

Comments
 (0)