crytic / crytic-compile

Abstraction layer for smart contract build systems
GNU Affero General Public License v3.0
155 stars 84 forks source link

[Bug]: KeyError: 1006 when checking brownie project #272

Open palango opened 2 years ago

palango commented 2 years ago

What happened?

When running slither on a brownie based project I see the following error output:

Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x10292e730>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x10292ec40>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x10292e970>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x102935d90>
Traceback (most recent call last):
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 743, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 84, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 67, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/slither.py", line 120, in __init__
    parser.parse_contracts()
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 424, in parse_contracts
    self._analyze_first_part(contracts_to_be_analyzed, libraries)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 485, in _analyze_first_part
    self._parse_struct_var_modifiers_functions(contract)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 555, in _parse_struct_var_modifiers_functions
    contract.parse_functions()
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/contract.py", line 351, in parse_functions
    self._parse_function(function)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/contract.py", line 337, in _parse_function
    func.set_offset(function_data["src"], self._contract.compilation_unit)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/core/source_mapping/source_mapping.py", line 101, in _convert_source_mapping
    (lines, starting_column, ending_column) = self._compute_line(
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 291, in get_line_from_offset
    return lines_delimiters[offset]
KeyError: 1006
None
Error in .
Traceback (most recent call last):
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 743, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 84, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 67, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/slither.py", line 120, in __init__
    parser.parse_contracts()
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 424, in parse_contracts
    self._analyze_first_part(contracts_to_be_analyzed, libraries)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 485, in _analyze_first_part
    self._parse_struct_var_modifiers_functions(contract)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 555, in _parse_struct_var_modifiers_functions
    contract.parse_functions()
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/contract.py", line 351, in parse_functions
    self._parse_function(function)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/solc_parsing/declarations/contract.py", line 337, in _parse_function
    func.set_offset(function_data["src"], self._contract.compilation_unit)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/slither/core/source_mapping/source_mapping.py", line 101, in _convert_source_mapping
    (lines, starting_column, ending_column) = self._compute_line(
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/raisync-NwuNULVI-py3.9/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 291, in get_line_from_offset
    return lines_delimiters[offset]
KeyError: 1006

Can you share code with us to reproduce this bug?

unfortunately not right now

Version

0.8.2

Relevant log output

No response

0xalpharush commented 2 years ago

Based off the error log, this may be an error with crytic-compile or compilation. Can you try crytic-compile . and report back? Prior to doing that, make sure it compiles with brownie compile please.

palango commented 2 years ago

@0xalpharush That works fine:

➜  contracts git:(brownie-update) ✗ crytic-compile .
INFO:CryticCompile:Brownie v1.18.1 - Python development framework for Ethereum

Project has been compiled. Build artifacts saved at /Users/paul/Projects/contracts/build/contracts

➜  contracts git:(brownie-update) ✗ brownie compile
Brownie v1.18.1 - Python development framework for Ethereum

Project has been compiled. Build artifacts saved at /Users/paul/Projects/contracts/build/contracts
elopez commented 2 years ago

Could you please confirm which version of crytic-compile you have installed? You can check it by running crytic-compile --version

If it's not the latest (0.2.2) can you please upgrade it (pip3 install --upgrade crytic-compile) and let us know if that fixes the issue?

palango commented 2 years ago

@elopez It's already installed:


$  contracts ✗ crytic-compile --version
0.2.2
$  contracts ✗ pip3 install --upgrade crytic-compile
Requirement already satisfied: crytic-compile in /Users/paul/Library/Caches/pypoetry/virtualenvs/test/lib/python3.9/site-packages (0.2.2)
Requirement already satisfied: pysha3>=1.0.2 in /Users/paul/Library/Caches/pypoetry/virtualenvs/test/lib/python3.9/site-packages (from crytic-compile) (1.0.2)
guarilha commented 2 years ago

Having the same issues here.

➜ slither .                            
Brownie v1.17.2 - Python development framework for Ethereum

Project has been compiled. Build artifacts saved at /home/vader/Code/labs/furia/px-nft/build/contracts

Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x7f2902fb2040>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x7f29028f4f10>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x7f2902536ac0>
Missing inheritance <slither.solc_parsing.declarations.contract.ContractSolc object at 0x7f2901fee790>
Traceback (most recent call last):

[ . . . ]

  File "/home/---/.local/lib/python3.8/site-packages/crytic_compile/crytic_compile.py", line 291, in get_line_from_offset
    return lines_delimiters[offset]
KeyError: 3118

Evidences:

➜ crytic-compile --version
0.2.2

➜ crytic-compile .
INFO:CryticCompile:Brownie v1.17.2 - Python development framework for Ethereum

Project has been compiled.

➜ brownie compile
Brownie v1.17.2 - Python development framework for Ethereum

Project has been compiled. 

It did ran once and I was able to view some warnings and address a couple of them. When I tried running again, I received this error.

0xalpharush commented 2 years ago

Can you provide an example of a codebase that causes this error? (Duplicate of https://github.com/crytic/slither/issues/1066)

palango commented 2 years ago

Can you provide an example of a codebase that causes this error? (Duplicate of crytic/slither#1066)

Not currently, but next week I'll be able to share to code.

palango commented 2 years ago

@0xalpharush Here's the way to reproduce the following problem:

Error in .
Traceback (most recent call last):
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 743, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 84, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/__main__.py", line 67, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/slither.py", line 97, in __init__
    parser.parse_top_level_from_loaded_json(ast, path)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 182, in parse_top_level_from_loaded_json
    contract.set_offset(top_level_data["src"], self._compilation_unit)
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/slither/core/source_mapping/source_mapping.py", line 101, in _convert_source_mapping
    (lines, starting_column, ending_column) = self._compute_line(
  File "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/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 "/Users/paul/Library/Caches/pypoetry/virtualenvs/beamer-1vah2Hfk-py3.9/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 291, in get_line_from_offset
    return lines_delimiters[offset]
KeyError: 2783
git clone https://github.com/beamer-bridge/beamer.git
cd beamer
poetry add -D slither-analyzer
poetry install
poetry shell
slither .
Selcuk05 commented 2 years ago

Any updates on this?

Selcuk05 commented 2 years ago

Any updates on this?

I fixed the problem by removing the build folder created by brownie