Skip to content

Commit 7ad7288

Browse files
authored
Only inject file-level instr. for first pragma in file (#865)
1 parent 351696e commit 7ad7288

File tree

5 files changed

+485
-39
lines changed

5 files changed

+485
-39
lines changed

lib/instrumenter.js

+3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ class Instrumenter {
8787

8888
// Handle contracts which only contain import statements
8989
contract.contractName = (root.length) ? root[0].name : null;
90+
91+
contract.finalParse = true;
9092
parse[ast.type](contract, ast);
93+
9194
// We have to iterate through these points in descending order
9295
const sortedPoints = Object.keys(contract.injectionPoints).sort((a, b) => b - a);
9396

lib/parse.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ parse.PragmaDirective = function(contract, expression){
245245
}
246246

247247
// From solc >=0.7.4, every file should have instrumentation methods
248-
// defined at the file level which file scoped fns can use...
249-
if (semver.lt("0.7.3", minVersion)){
248+
// defined at the file level which file scoped fns can use. (Make sure we only do this
249+
// once - flattened contracts have multiple pragma statements)
250+
if (semver.lt("0.7.3", minVersion) && contract.finalParse && !contract.fileLevelFinished){
250251
const start = expression.range[0];
251252
const end = contract.instrumented.slice(start).indexOf(';') + 1;
252253
const loc = start + end;
@@ -258,6 +259,7 @@ parse.PragmaDirective = function(contract, expression){
258259
};
259260

260261
contract.injectionPoints[loc] = [injectionObject];
262+
contract.fileLevelFinished = true;
261263
}
262264
}
263265

test/sources/solidity/contracts/statements/multi-contract-diamond.sol

-35
This file was deleted.

0 commit comments

Comments
 (0)