Skip to content

Commit

Permalink
Only inject file-level instr. for first pragma in file (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Feb 17, 2024
1 parent 351696e commit 7ad7288
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 39 deletions.
3 changes: 3 additions & 0 deletions lib/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class Instrumenter {

// Handle contracts which only contain import statements
contract.contractName = (root.length) ? root[0].name : null;

contract.finalParse = true;
parse[ast.type](contract, ast);

// We have to iterate through these points in descending order
const sortedPoints = Object.keys(contract.injectionPoints).sort((a, b) => b - a);

Expand Down
6 changes: 4 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ parse.PragmaDirective = function(contract, expression){
}

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

contract.injectionPoints[loc] = [injectionObject];
contract.fileLevelFinished = true;
}
}

Expand Down

This file was deleted.

Loading

0 comments on commit 7ad7288

Please sign in to comment.