From 63ad6770e678c0a0037a92b2e3a4fd20940c64ed Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 25 Apr 2022 20:16:06 -0700 Subject: [PATCH] Fix true/false scoped method definition function visibilities --- lib/injector.js | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/injector.js b/lib/injector.js index e914b2a..e1bd0b0 100644 --- a/lib/injector.js +++ b/lib/injector.js @@ -85,7 +85,7 @@ class Injector { _getFileScopedHashMethodDefinition(id, contract){ const hash = web3Utils.keccak256(id).slice(2,10); const method = this._getDefaultMethodIdentifier(id); - return `\nfunction ${method}(bytes8 c__${hash}) public pure {}\n`; + return `\nfunction ${method}(bytes8 c__${hash}) pure {}\n`; } /** @@ -100,6 +100,19 @@ class Injector { return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return true; }\n`; } + /** + * Generates a solidity statement injection defining a method + * *which returns boolean true* to pass instrumentation hash to. + * Declared once per file. (Has no visibility modifier) + * @param {String} fileName + * @return {String} ex: bytes32[1] memory _sc_82e0891 + */ + _getFileScopeTrueMethodDefinition(id){ + const hash = web3Utils.keccak256(id).slice(2,10); + const method = this._getTrueMethodIdentifier(id); + return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return true; }\n`; + } + /** * Generates a solidity statement injection defining a method * *which returns boolean false* to pass instrumentation hash to. @@ -112,6 +125,19 @@ class Injector { return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return false; }\n`; } + /** + * Generates a solidity statement injection defining a method + * *which returns boolean false* to pass instrumentation hash to. + * Declared once per file. (Has no visibility modifier) + * @param {String} fileName + * @return {String} ex: bytes32[1] memory _sc_82e0891 + */ + _getFileScopedFalseMethodDefinition(id){ + const hash = web3Utils.keccak256(id).slice(2,10); + const method = this._getFalseMethodIdentifier(id); + return `function ${method}(bytes8 c__${hash}) pure returns (bool){ return false; }\n`; + } + _getModifierDefinitions(contractId, instrumentation){ let injection = ''; @@ -312,11 +338,23 @@ class Injector { ? this._getFileScopedHashMethodDefinition(id) : this._getDefaultMethodDefinition(id); + const trueMethodDefinition = (injection.isFileScoped) + ? this._getFileScopeTrueMethodDefinition(id) + : this._getTrueMethodDefinition(id); + + const falseMethodDefinition = (injection.isFileScoped) + ? this._getFileScopedFalseMethodDefinition(id) + : this._getFalseMethodDefinition(id); + + const modifierDefinition = (injection.isFileScoped) + ? "" + : this._getModifierDefinitions(id, instrumentation); + contract.instrumented = `${start}` + `${methodDefinition}` + - `${this._getTrueMethodDefinition(id)}` + - `${this._getFalseMethodDefinition(id)}` + - `${this._getModifierDefinitions(id, instrumentation)}` + + `${trueMethodDefinition}` + + `${falseMethodDefinition}` + + `${modifierDefinition}` + `${end}`; }