Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag functions with empty body as unimplemented #1886

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ def analyze_content(self) -> None:
body = self._functionNotParsed.get("body", None)

if body and body[self.get_key()] == "Block":
self._function.is_implemented = True
if (
len(body["statements"]) > 0
or len(self._functionNotParsed["modifiers"]) > 0
or self._function.function_type
in [FunctionType.FALLBACK, FunctionType.RECEIVE, FunctionType.CONSTRUCTOR]
):
self._function.is_implemented = True
self._parse_cfg(body)

for modifier in self._functionNotParsed["modifiers"]:
smonicas marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -293,13 +299,19 @@ def analyze_content(self) -> None:
self._function.is_implemented = False
for child in children[2:]:
if child[self.get_key()] == "Block":
self._function.is_implemented = True
if len(child["children"]) > 0 or self._function.function_type in [
FunctionType.FALLBACK,
FunctionType.RECEIVE,
FunctionType.CONSTRUCTOR,
]:
self._function.is_implemented = True
self._parse_cfg(child)

# Parse modifier after parsing all the block
# In the case a local variable is used in the modifier
for child in children[2:]:
if child[self.get_key()] == "ModifierInvocation":
self._function.is_implemented = True
self._parse_modifier(child)

for local_var_parser in self._local_variables_parser:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DerivedContract.__gap (tests/e2e/detectors/test_data/shadowing-state/0.7.5/public_gap_variable.sol#8) shadows:
DerivedContract.__gap (tests/e2e/detectors/test_data/shadowing-state/0.7.5/public_gap_variable.sol#10) shadows:
- BaseContract.__gap (tests/e2e/detectors/test_data/shadowing-state/0.7.5/public_gap_variable.sol#3)

8 changes: 4 additions & 4 deletions tests/e2e/detectors/test_data/dead-code/0.8.0/dead-code.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
contract Test{
function unused() internal{

uint i = 1;
}
}


contract Test2{

function unused_but_shadowed() internal virtual{

uint i = 1;
}
}

contract Test3 is Test2{
function unused_but_shadowed() internal override{

uint i = 1;
}

function f() public{
Expand All @@ -24,7 +24,7 @@ contract Test3 is Test2{

contract Test4 is Test2{
function unused_but_shadowed() internal override{

uint i = 1;
}
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ contract A{

contract B is A{
function B(uint y) A(y * 3) public{

uint i = 1;
}
}

contract C is B{
function C(uint y) A(y * 2) public{

uint i = 1;
}
}

contract D is B(1), C(1) {
function D() B(3) C(2) public {

uint i = 1;
}
}

contract E is B(1), C, D() {
function E() B(1) C(2) D() public {

uint i = 1;
}
}


contract F is B {
function F() A(1) public {

uint i = 1;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ contract A{

contract B is A{
constructor(uint y) A(y * 3) public{

uint i = 1;
}
}

contract C is B{
constructor(uint y) A(y * 2) public{

uint i = 1;
}
}

contract D is B(1), C(1) {
constructor() B(3) C(2) public {

uint i = 1;
}
}

contract E is B(1), C, D() {
constructor() B(1) C(2) D() public {

uint i = 1;
}
}


contract F is B {
constructor() A(1) public {

uint i = 1;
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
pragma solidity ^0.7.5;
contract BaseContract{
uint256[50] private __gap;
function f() external {}
function f() external {
uint i = 1;
}
}

contract DerivedContract is BaseContract{
uint256[50] public __gap;
function g() external {}
function g() external {
uint j = 2;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ contract UpgradeableNoDestruct is Initializable{
contract Fixed2 is Initializable {
address owner;

constructor() public initializer {}
constructor() public initializer {
uint i = 1;
}

function initialize() external initializer {
require(owner == address(0));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ contract UpgradeableNoDestruct is Initializable{
contract Fixed2 is Initializable {
address payable owner;

constructor() public initializer {}
constructor() public initializer {
uint i = 1;
}

function initialize() external initializer {
require(owner == address(0));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ contract UpgradeableNoDestruct is Initializable{
contract Fixed2 is Initializable {
address payable owner;

constructor() public initializer {}
constructor() public initializer {
uint i = 1;
}

function initialize() external initializer {
require(owner == address(0));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ contract UpgradeableNoDestruct is Initializable{
contract Fixed2 is Initializable {
address payable owner;

constructor() initializer {}
constructor() initializer {
uint i = 1;
}

function initialize() external initializer {
require(owner == address(0));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ contract UpgradeableNoDestruct is Initializable{
contract Fixed2 is Initializable {
address payable owner;

constructor() initializer {}
constructor() initializer {
uint i = 1;
}

function initialize() external initializer {
require(owner == address(0));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract C{
contract D is C{

constructor() public C(){

uint i = 1;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract C{
contract D is C{

constructor() public C(){

uint i = 1;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract C{
contract D is C{

constructor() public C(){

uint i = 1;
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract C{
contract D is C{

constructor() public C(){

uint i = 1;
}

}
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/e2e/solc_parsing/test_data/contract-0.4.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract A {
// inheritance, no constructor
contract B is A {
function B(uint a) {

uint i = 1;
}
}

Expand All @@ -19,7 +19,7 @@ contract C is B(4) {
// inheritance, init in constructor
contract D is B {
function D() B(2) {

uint i = 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/solc_parsing/test_data/contract-0.4.22.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract A {
// inheritance, no constructor
contract B is A {
constructor(uint a) public {

uint i = 1;
}
}

Expand All @@ -19,7 +19,7 @@ contract C is B(4) {
// inheritance, init in constructor
contract D is B {
constructor() B(2) public {

uint i = 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/solc_parsing/test_data/contract-0.6.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract A {
// inheritance, no constructor
contract B is A {
constructor(uint a) public {

uint i = 1;
}
}

Expand All @@ -19,7 +19,7 @@ contract C is B(4) {
// inheritance, init in constructor
contract D is B {
constructor() B(2) public {

uint i = 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Test": {
"test()": "digraph{\n0[label=\"Node Type: ENTRY_POINT 0\n\"];\n0->1;\n1[label=\"Node Type: EXPRESSION 1\n\"];\n}\n"
}
}
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.4.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.4.16.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.4.22.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.4.23.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.5.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.6.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/solc_parsing/test_data/function-0.7.0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ abstract contract C3 {
modifier modifierNoArgs() { _; }
modifier modifierWithArgs(uint a) { _; }

function f() public modifierNoArgs modifierWithArgs(block.timestamp) {}
function f() public modifierNoArgs modifierWithArgs(block.timestamp) {
uint i = 1;
}
}

contract C4 {
Expand Down
Loading