crytic / slither

Static Analyzer for Solidity and Vyper
https://blog.trailofbits.com/2018/10/19/slither-a-solidity-static-analysis-framework/
GNU Affero General Public License v3.0
5.34k stars 970 forks source link

[Bug-Candidate]: Failure to parse shared errors on libraries #1393

Closed kevzettler closed 2 years ago

kevzettler commented 2 years ago

Describe the issue:

I have a library with an error class that was being used in a contract. Slither crashes on the line that access the error from the library.

Code example to reproduce the issue:

library TestLib {
 error SharedError();
}

contract TestContract{
   function doSomething(){
       revert TestLib.SharedError();
   }
}

Version:

kevzettler@kevs-mbp-3 contracts % slither --version 0.8.3

Relevant log output:

node:51462) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
'npx hardhat compile --force' running
Generating typings for: 18 artifacts in dir: ./build/typechain for target: ethers-v5
Successfully generated 54 typings!
Compiled 17 Solidity files successfully

(node:51466) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 744, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 87, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 72, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 113, in _process
    detector_results = slither.run_detectors()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 201, in run_detectors
    results = [d.detect() for d in self._detectors]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 201, in <listcomp>
    results = [d.detect() for d in self._detectors]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/abstract_detector.py", line 152, in detect
    for r in [output.data for output in self._detect()]:
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy_eth.py", line 93, in _detect
    super()._detect()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 303, in _detect
    self.detect_reentrancy(c)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 290, in detect_reentrancy
    self._explore(function.entry_point, [])
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  [Previous line repeated 4 more times]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 267, in _explore
    contains_call = fathers_context.analyze_node(node, self)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 159, in analyze_node
    if detector.can_callback(ir):
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 228, in can_callback
    return isinstance(ir, Call) and ir.can_reenter()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slithir/operations/library_call.py", line 27, in can_reenter
    return self.function.can_reenter(callstack)
AttributeError: 'NoneType' object has no attribute 'can_reenter'
None
Error in .
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 744, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 87, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 72, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/__main__.py", line 113, in _process
    detector_results = slither.run_detectors()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 201, in run_detectors
    results = [d.detect() for d in self._detectors]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slither.py", line 201, in <listcomp>
    results = [d.detect() for d in self._detectors]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/abstract_detector.py", line 152, in detect
    for r in [output.data for output in self._detect()]:
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy_eth.py", line 93, in _detect
    super()._detect()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 303, in _detect
    self.detect_reentrancy(c)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 290, in detect_reentrancy
    self._explore(function.entry_point, [])
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 282, in _explore
    self._explore(son, visited)
  [Previous line repeated 4 more times]
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 267, in _explore
    contains_call = fathers_context.analyze_node(node, self)
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 159, in analyze_node
    if detector.can_callback(ir):
  File "/opt/homebrew/lib/python3.10/site-packages/slither/detectors/reentrancy/reentrancy.py", line 228, in can_callback
    return isinstance(ir, Call) and ir.can_reenter()
  File "/opt/homebrew/lib/python3.10/site-packages/slither/slithir/operations/library_call.py", line 27, in can_reenter
    return self.function.can_reenter(callstack)
AttributeError: 'NoneType' object has no attribute 'can_reenter'
0xalpharush commented 2 years ago

I believe this is fixed on version 0.9.0 (worked fine for me). Could you upgrade and let me know if the issue persists please?

kevzettler commented 2 years ago

@0xalpharush confirmed this seems to be resolved with 0.9.0