Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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