slither
slither copied to clipboard
[Bug-Candidate]:
Describe the issue:
ENV : HARDHAT
Traceback (most recent call last): File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/main.py", line 741, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/main.py", line 83, in process_all ) = process_single(compilation, args, detector_classes, printer_classes) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/main.py", line 66, in process_single slither = Slither(target, ast_format=ast, **vars(args)) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/slither.py", line 81, in init parser.parse_top_level_from_loaded_json(ast, path) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 171, in parse_top_level_from_loaded_json contract.set_offset(top_level_data["src"], self._compilation_unit) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/core/source_mapping/source_mapping.py", line 124, in set_offset self._source_mapping = self._convert_source_mapping(offset, compilation_unit) File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/core/source_mapping/source_mapping.py", line 101, in _convert_source_mapping (lines, starting_column, ending_column) = self._compute_line( File "/home/nba-179-41a/.local/lib/python3.8/site-packages/slither/core/source_mapping/source_mapping.py", line 43, in _compute_line end_line, ending_column = compilation_unit.core.crytic_compile.get_line_from_offset( File "/home/nba-179-41a/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 291, in get_line_from_offset return lines_delimiters[offset] KeyError: 1305
Code example to reproduce the issue:
slither .
Version:
0.8.1
Relevant log output:
No response
Hi @KirylMoisa, thanks for the report. Can you still reproduce this issue after cleaning the artifacts with hardhat clean and removing crytic-export if present, and then having them rebuilt? See https://github.com/crytic/slither/issues/1066#issuecomment-1073694872 for more details
After removing crytic-export and hardhat clean
Traceback (most recent call last): File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 744, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 87, in process_all ) = process_single(compilation, args, detector_classes, printer_classes) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 70, in process_single slither = Slither(target, ast_format=ast, **vars(args)) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/slither.py", line 95, in init parser.parse_top_level_from_loaded_json(ast, path) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 238, in parse_top_level_from_loaded_json _handle_import_aliases(symbol_aliases, import_directive, scope) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 50, in _handle_import_aliases and "name" in symbol_alias["foreign"] TypeError: argument of type 'int' is not iterable None Error in . Traceback (most recent call last): File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 744, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 87, in process_all ) = process_single(compilation, args, detector_classes, printer_classes) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/main.py", line 70, in process_single slither = Slither(target, ast_format=ast, **vars(args)) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/slither.py", line 95, in init parser.parse_top_level_from_loaded_json(ast, path) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 238, in parse_top_level_from_loaded_json _handle_import_aliases(symbol_aliases, import_directive, scope) File "/home/nba-179-41a/PycharmProjects/crypto-luckyblock-smart-contracts/.venv/lib/python3.8/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 50, in _handle_import_aliases and "name" in symbol_alias["foreign"] TypeError: argument of type 'int' is not iterable
Would you be able to share a reproducible example?
I believe I'm having the same issue. Running crytic-compile . succeeds, but slither . fails. Using a foundry repo, tried forge clean + reinstalling deps but still seeing the problem.
Versions:
$ crytic-compile --version
0.2.4
$ slither --version
0.9.1
To reproduce:
- Clone https://github.com/ScopeLift/flexible-voting
- Switch to
scopelintbranch - Install deps with
forge install - Run
slither .to get the below stack trace:
From logging the files, it looks like the source of this is:
Filename(absolute='/Users/mds/Documents/projects/flexible-voting/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol', used='lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol', relative='lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol', short='lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol')
Stack trace:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 75, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/usr/local/lib/python3.10/site-packages/slither/slither.py", line 125, in __init__
parser.parse_contracts()
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 482, in parse_contracts
self._analyze_first_part(contracts_to_be_analyzed, libraries)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 527, in _analyze_first_part
self._parse_struct_var_modifiers_functions(lib)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 614, in _parse_struct_var_modifiers_functions
contract.parse_functions()
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/declarations/contract.py", line 380, in parse_functions
self._parse_function(function)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/declarations/contract.py", line 366, in _parse_function
func.set_offset(function_data["src"], self._contract.compilation_unit)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 184, in set_offset
self.source_mapping = _convert_source_mapping(offset, compilation_unit)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 150, in _convert_source_mapping
(lines, starting_column, ending_column) = _compute_line(compilation_unit, filename, s, l)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 108, in _compute_line
start_line, starting_column = compilation_unit.core.crytic_compile.get_line_from_offset(
File "/usr/local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 292, in get_line_from_offset
return lines_delimiters[offset]
KeyError: 2476
Error in .
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 97, in process_all
) = process_single(compilation, args, detector_classes, printer_classes)
File "/usr/local/lib/python3.10/site-packages/slither/__main__.py", line 75, in process_single
slither = Slither(target, ast_format=ast, **vars(args))
File "/usr/local/lib/python3.10/site-packages/slither/slither.py", line 125, in __init__
parser.parse_contracts()
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 482, in parse_contracts
self._analyze_first_part(contracts_to_be_analyzed, libraries)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 527, in _analyze_first_part
self._parse_struct_var_modifiers_functions(lib)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 614, in _parse_struct_var_modifiers_functions
contract.parse_functions()
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/declarations/contract.py", line 380, in parse_functions
self._parse_function(function)
File "/usr/local/lib/python3.10/site-packages/slither/solc_parsing/declarations/contract.py", line 366, in _parse_function
func.set_offset(function_data["src"], self._contract.compilation_unit)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 184, in set_offset
self.source_mapping = _convert_source_mapping(offset, compilation_unit)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 150, in _convert_source_mapping
(lines, starting_column, ending_column) = _compute_line(compilation_unit, filename, s, l)
File "/usr/local/lib/python3.10/site-packages/slither/core/source_mapping/source_mapping.py", line 108, in _compute_line
start_line, starting_column = compilation_unit.core.crytic_compile.get_line_from_offset(
File "/usr/local/lib/python3.10/site-packages/crytic_compile/crytic_compile.py", line 292, in get_line_from_offset
return lines_delimiters[offset]
KeyError: 2476
At first glance, it looks like maybe there's some sort of conflict in the compilation artifacts between the IERC165's defined in aave-v3 and forge-std as the function that's being parsed here is executeMintUnbacked in Aave. Or something about the import aliases in Aave aren't handled properly in slither... Will dig into this more later
Maybe related to https://github.com/crytic/crytic-compile/issues/285 h/t @plotchy
@mds1 The top level key "id" of ~/flexible-voting/out/BridgeLogic.sol/BridgeLogic.json and ~/flexible-voting/out/IERC165.sol/IERC165.json are the same so it causes issues when slither resolves the source mapping here:
https://github.com/crytic/slither/blob/a41f86739d9d2aad7596b9a0ac0ab2ce644fc2f3/slither/core/source_mapping/source_mapping.py#L133-L150
The use of a dictionary here assumes that a source unit is unique in a source mapping e.g. the function executeMintUnbacked has the mapping, 2476:1532:38. Currently, this could refer to either BridgeLogic or IERC165 (they both have a source unit id of 38 in this example). When the source mapping resolves to IERC165 it causes a KeyError, looking for an offset that is in another source file.
I haven't really dealt with anything related to compilation artifacts so I'd defer to @montyly. However, my expectation is that Foundry should produce unique source units. If not, we may have to handle this edge case in crytic-compile... @mds1 what do you think?
Ah yes, I see they have the same id. I think this is related to what @montyly and @mattsse were discussing here: https://github.com/foundry-rs/foundry/issues/3450
Similarly I'm not too familiar with compilation artifacts, so ultimately I'll defer to what @montyly and @mattsse agree on, but it does seem worthy of restructuring the forge build outputs to improve compatibility with tools like slither. Perhaps a forge artifact <contract> can be added to print the path to a given contract so its easier for users to find which compilation unit contains a given artifact
Hey all, this should be fixed by https://github.com/crytic/crytic-compile/pull/348. Take the latest slither release a spin and if you run into any problems, please open a new issue.