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

[Bug]: cache-array-length throws "StateVariable object has no attribute view" #2017

Closed
rndquu opened this issue Jul 1, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@rndquu
Copy link

rndquu commented Jul 1, 2023

Describe the issue:

We have this github workflow file that runs slither in a CI runner

Recently, since the release of slither 0.9.5, this workflow started to fail with the following error:

  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 137, in _is_loop_referencing_array_length
    if isinstance(op, HighLevelCall) and not op.function.view and not op.function.pure:
AttributeError: 'StateVariable' object has no attribute 'view'

The latest slither release (0.9.5) introduced a new cache-array-length detector

If I exclude the cache-array-length from slither config then the workflow works fine again

What am I doing wrong?

Code example to reproduce the issue:

Check this PR

There are 2 commits:

Version:

0.9.5

Relevant log output:

Run yarn workspace @ubiquity/contracts run test:slither
  yarn workspace @ubiquity/contracts run test:slither
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.10.1[2](https://github.com/rndquu/ubiquity-dollar/actions/runs/5431180883/jobs/9877385161#step:7:2)/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/[3](https://github.com/rndquu/ubiquity-dollar/actions/runs/5431180883/jobs/9877385161#step:7:3).10.12/x6[4](https://github.com/rndquu/ubiquity-dollar/actions/runs/5431180883/jobs/9877385161#step:7:4)/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.12/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.12/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.12/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.12/x64/lib
    MSYS: winsymlinks:nativestrict
'forge clean' running (wd: /home/runner/work/ubiquity-dollar/ubiquity-dollar/packages/contracts)
'forge build --build-info' running (wd: /home/runner/work/ubiquity-dollar/ubiquity-dollar/packages/contracts)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 102, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 82, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 132, in _process
    detector_resultss = slither.run_detectors()
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/slither.py", line 226, in run_detectors
    results = [d.detect() for d in self._detectors]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/slither.py", line 226, in <listcomp>
    results = [d.detect() for d in self._detectors]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/abstract_detector.py", line 187, in detect
    for r in [output.data for output in self._detect()]:
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 209, in _detect
    non_optimal_array_len_usages = CacheArrayLength._get_non_optimal_array_len_usages(
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 201, in _get_non_optimal_array_len_usages
    CacheArrayLength._get_non_optimal_array_len_usages_for_function(f)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 188, in _get_non_optimal_array_len_usages_for_function
    CacheArrayLength._handle_loops(f.nodes, non_optimal_array_len_usages)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 177, in _handle_loops
    if not CacheArrayLength._is_loop_referencing_array_length(
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  [Previous line repeated 1 more time]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 137, in _is_loop_referencing_array_length
    if isinstance(op, HighLevelCall) and not op.function.view and not op.function.pure:
AttributeError: 'StateVariable' object has no attribute 'view'
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 102, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 82, in process_single
    return _process(slither, detector_classes, printer_classes)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/__main__.py", line 132, in _process
    detector_resultss = slither.run_detectors()
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/slither.py", line 226, in run_detectors
    results = [d.detect() for d in self._detectors]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/slither.py", line 226, in <listcomp>
    results = [d.detect() for d in self._detectors]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/abstract_detector.py", line 187, in detect
    for r in [output.data for output in self._detect()]:
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 209, in _detect
    non_optimal_array_len_usages = CacheArrayLength._get_non_optimal_array_len_usages(
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 201, in _get_non_optimal_array_len_usages
    CacheArrayLength._get_non_optimal_array_len_usages_for_function(f)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 188, in _get_non_optimal_array_len_usages_for_function
    CacheArrayLength._handle_loops(f.nodes, non_optimal_array_len_usages)
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 177, in _handle_loops
    if not CacheArrayLength._is_loop_referencing_array_length(
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 142, in _is_loop_referencing_array_length
    if CacheArrayLength._is_loop_referencing_array_length(son, visited, array, depth):
  [Previous line repeated 1 more time]
  File "/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/slither/detectors/operations/cache_array_length.py", line 137, in _is_loop_referencing_array_length
    if isinstance(op, HighLevelCall) and not op.function.view and not op.function.pure:
AttributeError: 'StateVariable' object has no attribute 'view'

Error: Process completed with exit code 2[5](https://github.com/rndquu/ubiquity-dollar/actions/runs/5431180883/jobs/9877385161#step:7:5)5.
@rndquu rndquu added the bug-candidate Bugs reports that are not yet confirmed label Jul 1, 2023
@0xalpharush 0xalpharush changed the title [Bug-Candidate]: cache-array-length throws "StateVariable object has no attribute view" [Bug]: cache-array-length throws "StateVariable object has no attribute view" Jul 1, 2023
@0xalpharush 0xalpharush added bug Something isn't working and removed bug-candidate Bugs reports that are not yet confirmed labels Jul 1, 2023
@0xalpharush
Copy link
Contributor

Released https://github.com/crytic/slither/releases/tag/0.9.6 to fix this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants