|
|
|
@ -1,7 +1,8 @@ |
|
|
|
|
const web3Utils = require("web3-utils"); |
|
|
|
|
|
|
|
|
|
class Injector { |
|
|
|
|
constructor(){ |
|
|
|
|
constructor(viaIR){ |
|
|
|
|
this.viaIR = viaIR; |
|
|
|
|
this.hashCounter = 0; |
|
|
|
|
this.modifierCounter = 0; |
|
|
|
|
this.modifiers = {}; |
|
|
|
@ -23,7 +24,9 @@ class Injector { |
|
|
|
|
case 'modifier': |
|
|
|
|
return ` ${this._getModifierIdentifier(id)} `; |
|
|
|
|
default: |
|
|
|
|
return `${this._getDefaultMethodIdentifier(id)}(${hash}); /* ${type} */ \n`; |
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `${this._getAbiEncodeStatementHash(hash)} /* ${type} */ \n` |
|
|
|
|
: `${this._getDefaultMethodIdentifier(id)}(${hash}); /* ${type} */ \n`; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -51,6 +54,16 @@ class Injector { |
|
|
|
|
return `c_mod${web3Utils.keccak256(id).slice(2,10)}` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Way to get hash on the stack with viaIR (which seems to ignore abi.encode builtin)
|
|
|
|
|
// Tested with v0.8.17, v0.8.24
|
|
|
|
|
_getAbiEncodeStatementHash(hash){ |
|
|
|
|
return `abi.encode(${hash}); ` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_getAbiEncodeStatementVar(hash){ |
|
|
|
|
return `abi.encode(c__${hash}); ` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_getInjectionComponents(contract, injectionPoint, id, type){ |
|
|
|
|
const { start, end } = this._split(contract, injectionPoint); |
|
|
|
|
const hash = this._getHash(id) |
|
|
|
@ -73,7 +86,10 @@ class Injector { |
|
|
|
|
_getDefaultMethodDefinition(id){ |
|
|
|
|
const hash = web3Utils.keccak256(id).slice(2,10); |
|
|
|
|
const method = this._getDefaultMethodIdentifier(id); |
|
|
|
|
return `\nfunction ${method}(bytes8 c__${hash}) internal pure {}\n`; |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `` |
|
|
|
|
: `\nfunction ${method}(bytes8 c__${hash}) internal pure {}\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -85,7 +101,11 @@ class Injector { |
|
|
|
|
_getFileScopedHashMethodDefinition(id, contract){ |
|
|
|
|
const hash = web3Utils.keccak256(id).slice(2,10); |
|
|
|
|
const method = this._getDefaultMethodIdentifier(id); |
|
|
|
|
return `\nfunction ${method}(bytes8 c__${hash}) pure {}\n`; |
|
|
|
|
const abi = this._getAbiEncodeStatementVar(hash); |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `\nfunction ${method}(bytes8 c__${hash}) pure { ${abi} }\n` |
|
|
|
|
: `\nfunction ${method}(bytes8 c__${hash}) pure {}\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -97,7 +117,11 @@ class Injector { |
|
|
|
|
_getTrueMethodDefinition(id){ |
|
|
|
|
const hash = web3Utils.keccak256(id).slice(2,10); |
|
|
|
|
const method = this._getTrueMethodIdentifier(id); |
|
|
|
|
return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return true; }\n`; |
|
|
|
|
const abi = this._getAbiEncodeStatementVar(hash); |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ ${abi} return true; }\n` |
|
|
|
|
: `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return true; }\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -110,7 +134,11 @@ class Injector { |
|
|
|
|
_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`; |
|
|
|
|
const abi = this._getAbiEncodeStatementVar(hash); |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `function ${method}(bytes8 c__${hash}) pure returns (bool){ ${abi} return true; }\n` |
|
|
|
|
: `function ${method}(bytes8 c__${hash}) pure returns (bool){ return true; }\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -122,7 +150,11 @@ class Injector { |
|
|
|
|
_getFalseMethodDefinition(id){ |
|
|
|
|
const hash = web3Utils.keccak256(id).slice(2,10); |
|
|
|
|
const method = this._getFalseMethodIdentifier(id); |
|
|
|
|
return `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return false; }\n`; |
|
|
|
|
const abi = this._getAbiEncodeStatementVar(hash); |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ ${abi} return false; }\n` |
|
|
|
|
: `function ${method}(bytes8 c__${hash}) internal pure returns (bool){ return false; }\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -135,7 +167,11 @@ class Injector { |
|
|
|
|
_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`; |
|
|
|
|
const abi = this._getAbiEncodeStatementVar(hash); |
|
|
|
|
|
|
|
|
|
return (this.viaIR) |
|
|
|
|
? `function ${method}(bytes8 c__${hash}) pure returns (bool){ ${abi} return false; }\n` |
|
|
|
|
: `function ${method}(bytes8 c__${hash}) pure returns (bool){ return false; }\n`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_getModifierDefinitions(contractId, instrumentation){ |
|
|
|
|