crytic / crytic/slither

[Bug]: Vyper `for` loop over an iterable inside a struct fails

Open
#2,194 1 comment 0 reactions 0 assignees View on GitHub
bug vyper
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

### Describe the issue:

Slither crashes when analysing a Vyper program that contains a `for` loop iterating over an array inside a struct.

Likely caused by: https://github.com/crytic/slither/blob/e3dcf1ecd3e9de60da046de471c5663ab637993a/slither/vyper_parsing/declarations/function.py#L331
As it seems that Slither is assuming that if the iterable is an `Attribute`, it must be something like `self.[smth]` (a state variable) but the `Attribute` AST node is also used for struct accessing.

### Code example to reproduce the issue:

```Vyper
struct A:
a: uint256[3]

@external
def foo():
x: A = A({a:[1,2,3]})
temp:uint256 = 0
for i in x.a:
temp += i
```

### Version:

`0.10.0`

### Relevant log output:

```shell
Traceback (most recent call last):
File "/home/csdocker/.local/bin/slither", line 8, in
sys.exit(main())
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/__main__.py", line 727, in main
main_impl(all_detector_classes=detectors, all_printer_classes=printers)
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/__main__.py", line 833, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/__main__.py", line 107, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/__main__.py", line 80, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/slither.py", line 144, in __init__
self._init_parsing_and_analyses(kwargs.get("skip_analyze", False))
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/slither.py", line 164, in _init_parsing_and_analyses
raise e
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/slither.py", line 160, in _init_parsing_and_analyses
parser.analyze_contracts()
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/vyper_parsing/vyper_compilation_unit.py", line 61, in analyze_contracts
contract_parser.analyze()
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/vyper_parsing/declarations/contract.py", line 521, in analyze
function.analyze_content()
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/vyper_parsing/declarations/function.py", line 186, in analyze_content
self._parse_cfg(body)
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/vyper_parsing/declarations/function.py", line 523, in _parse_cfg
curr_node = parse_statement(curr_node, expr)
File "/home/csdocker/.local/pipx/venvs/slither-analyzer/lib/python3.10/site-packages/slither/vyper_parsing/declarations/function.py", line 333, in parse_statement
loop_iterator = list(
IndexError: list index out of range
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.