-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from trailofbits/dev-external-function
Fix external-function detector to avoid false-positives
- Loading branch information
Showing
9 changed files
with
216 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This tests against false-positives. This test should output no recommendations from the external-function detector. | ||
|
||
|
||
contract ContractWithBaseFunctionCalled { | ||
function getsCalledByBase() public; | ||
function callsOverrideMe() external { | ||
getsCalledByBase(); | ||
} | ||
} | ||
|
||
|
||
contract DerivingContractWithBaseCalled is ContractWithBaseFunctionCalled { | ||
function getsCalledByBase() public { | ||
// This should not be recommended to be marked external because it is called by the base class. | ||
} | ||
} | ||
|
||
|
||
// All the contracts below should not recommend changing to external since inherited contracts have dynamic calls. | ||
contract ContractWithDynamicCall { | ||
function() returns(uint) ptr; | ||
|
||
function test1() public returns(uint){ | ||
return 1; | ||
} | ||
|
||
function test2() public returns(uint){ | ||
return 2; | ||
} | ||
|
||
function setTest1() external{ | ||
ptr = test1; | ||
} | ||
|
||
function setTest2() external{ | ||
ptr = test2; | ||
} | ||
|
||
function exec() external returns(uint){ | ||
return ptr(); | ||
} | ||
} | ||
|
||
contract DerivesFromDynamicCall is ContractWithDynamicCall{ | ||
function getsCalledDynamically() public returns (uint){ | ||
// This should not be recommended because it is called dynamically. | ||
return 3; | ||
} | ||
function setTest3() public { | ||
// This should not be recommended because we inherit from a contract that calls dynamically, and we cannot be | ||
// sure it did not somehow call this function. | ||
|
||
ptr = getsCalledDynamically; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/external_function_test_2.sol → tests/external_function_import.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters