Skip to content

call graph printer does not support top level functions #1437

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

Open
KyrylR opened this issue Oct 19, 2022 · 1 comment · May be fixed by #1763
Open

call graph printer does not support top level functions #1437

KyrylR opened this issue Oct 19, 2022 · 1 comment · May be fixed by #1763
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@KyrylR
Copy link

KyrylR commented Oct 19, 2022

Compiled with hardhat.

I faced an issue(log):

Traceback (most recent call last):
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 77, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 133, in _process
    printer_results = slither.run_printers()
  File "/home/internos/.local/lib/python3.10/site-packages/slither/slither.py", line 218, in run_printers
    return [p.output(self._crytic_compile.target).data for p in self._printers]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/slither.py", line 218, in <listcomp>
    return [p.output(self._crytic_compile.target).data for p in self._printers]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/printers/call/call_graph.py", line 244, in output
    ["strict digraph {"] + [_process_functions(all_functions_as_dict.values())] + ["}"]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/printers/call/call_graph.py", line 180, in _process_functions
    all_contracts.add(function.contract_declarer)
AttributeError: 'FunctionTopLevel' object has no attribute 'contract_declarer'
Error in .
Traceback (most recent call last):
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 77, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/home/internos/.local/lib/python3.10/site-packages/slither/__main__.py", line 133, in _process
    printer_results = slither.run_printers()
  File "/home/internos/.local/lib/python3.10/site-packages/slither/slither.py", line 218, in run_printers
    return [p.output(self._crytic_compile.target).data for p in self._printers]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/slither.py", line 218, in <listcomp>
    return [p.output(self._crytic_compile.target).data for p in self._printers]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/printers/call/call_graph.py", line 244, in output
    ["strict digraph {"] + [_process_functions(all_functions_as_dict.values())] + ["}"]
  File "/home/internos/.local/lib/python3.10/site-packages/slither/printers/call/call_graph.py", line 180, in _process_functions
    all_contracts.add(function.contract_declarer)
AttributeError: 'FunctionTopLevel' object has no attribute 'contract_declarer'

When I try execute following command: slither . --print call-graph

Does anyone have any idea what it could be?
Or where I need to dig to solve this problem?

@0xalpharush
Copy link
Contributor

This printer doesn't seem to support functions declared outside of contracts. Until it's fixed the only work around is to move the function into the contract:
Change

function toplevel(uint a, uint b) pure returns(uint) {
    return a + b;
} 

contract BaseContract{
    address a;
    function callgaph() external {
         toplevel(1, 2);
    }
}

to this



contract BaseContract{
    address a;
      function toplevel(uint a, uint b) internal returns(uint) {
          return a + b;
      } 
    function callgaph() external {
         toplevel(1, 2);
    }
}

@0xalpharush 0xalpharush added the bug Something isn't working label Oct 19, 2022
@0xalpharush 0xalpharush changed the title When I run slither . --print call-graph I get: AttributeError: 'FunctionTopLevel' object has no attribute 'contract_declarer' call graph printer does not support top level functions Oct 19, 2022
@montyly montyly added the 0.9.1 label Oct 26, 2022
@0xalpharush 0xalpharush removed the 0.9.1 label Dec 2, 2022
@0xalpharush 0xalpharush added the good first issue Good for newcomers label Dec 13, 2022
@technovision99 technovision99 self-assigned this Jan 31, 2023
@technovision99 technovision99 linked a pull request Mar 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants