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.33k stars 967 forks source link

Failed to generate IR #2354

Closed AaronLee22 closed 7 months ago

AaronLee22 commented 8 months ago

--ignore-compile used, if something goes wrong, consider removing the ignore compile flag ERROR:ContractSolcParsing:Impossible to generate IR for LibSort._toInts (scripts/libraries/LibSort.sol#469-474): 'str' object has no attribute 'type' ERROR:SlitherSolcParsing: Failed to generate IR for LivenessGuard_TestInit._initializeSafeTools. Please open an issue https://github.com/crytic/slither/issues. LivenessGuard_TestInit._initializeSafeTools (test/safe-tools/SafeTestTools.sol#509-513): singleton = new GnosisSafe() proxyFactory = new GnosisSafeProxyFactory() handler = new CompatibilityFallbackHandler() Traceback (most recent call last): File "/opt/slither/bin/slither", line 8, in sys.exit(main()) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 735, in main main_impl(all_detector_classes=detectors, all_printer_classes=printers) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 841, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 107, in process_all ) = process_single(compilation, args, detector_classes, printer_classes) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 80, in process_single slither = Slither(target, ast_format=ast, **vars(args)) File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 146, in init self._init_parsing_and_analyses(kwargs.get("skip_analyze", False)) File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 166, in _init_parsing_and_analyses raise e File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 162, in _init_parsing_and_analyses parser.analyze_contracts() File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 539, in analyze_contracts self._convert_to_slithir() File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 765, in _convert_to_slithir raise e File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 750, in _convert_to_slithir func.generate_slithir_and_analyze() File "/opt/slither/lib/python3.9/site-packages/slither/core/declarations/function.py", line 1772, in generate_slithir_and_analyze node.slithir_generation() File "/opt/slither/lib/python3.9/site-packages/slither/core/cfg/node.py", line 716, in slithir_generation self._irs = convert_expression(expression, self) # type:ignore File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 118, in convert_expression result = apply_ir_heuristics(result, node, is_solidity) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 2033, in apply_ir_heuristics irs = propagate_type_and_convert_call(irs, node) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 529, in propagate_type_and_convert_call new_ins = propagate_types(ins, node) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 875, in propagate_types assert contract AssertionError

This error continues to occur despite having applied filter_path for both LibSort.sol and SafeTestTools.sol.

{ "detectors_to_exclude": "arbitrary-send-eth,incorrect-equality,naming-convention,solc-version", "exclude_dependencies": true, "exclude_informational": true, "exclude_low": true, "exclude_optimization": true, "fail_on": "none", "filter_paths": "(src/vendor|src/cannon/MIPS.sol|src/EAS/EAS.sol|test/safe-tools/SafeTestTools.sol|scripts/libraries/LibSort.sol)", "foundry_out_directory": "artifacts" }

0xalpharush commented 8 months ago

The filter-paths flag is applied after running the detectors and not during compilation, so it won't skip this script and avoid the error.

However, if you're using a recent version of slither, they way forge is invoked should be skipping the scripts directory at compilation time. What version of slither are you using and can you show the terminal output of the same command without --ignore-compile please?

AaronLee22 commented 8 months ago

It says solc-select-1.0.4. without the --ignore-compile it works as expected but some how my repository has a complex building mechanism and want to use it in mono repo environment.

- name: Run Slither
  uses: crytic/slither-action@v0.3.1
  with:
    target: packages/tokamak/contracts-bedrock
    slither-config: packages/tokamak/contracts-bedrock/slither.config.json
    fail-on: config
    slither-version: dev-triage-db
    slither-args: --triage-database packages/tokamak/contracts-bedrock/slither.db.json
    ignore-compile: true

The install dependencies and building contracts worked fine.

0xalpharush commented 8 months ago

If it works without --ignore-compile, could you explain what you're trying to accomplish by using --ignore-compile?There's an example of running a build command as a step in the github action here

elopez commented 8 months ago

if you want to use ignore-compile and build manually, you can add the --skip argument to your forge build invocation to achieve the same Slither does internally:

forge build --build-info --skip '*/test/**' '*/script/**'

That way test & script won't get built and Slither will then not process that code.

AaronLee22 commented 8 months ago

reason i want to use --ignore-compile. It is not suitable for a monorepo scenario where the dependency's pnpm-lock file exists at the top level of the repository, but the target directory I want to analyze is not located at the top level of the repository.

AaronLee22 commented 8 months ago

if you want to use ignore-compile and build manually, you can add the --skip argument to your forge build invocation to achieve the same Slither does internally:

forge build --build-info --skip '*/test/*' '/script/**'

That way test & script won't get built and Slither will then not process that code.

let me try this way too

AaronLee22 commented 8 months ago

If it works without --ignore-compile, could you explain what you're trying to accomplish by using --ignore-compile?There's an example of running a build command as a step in the github action here

This is exactly what I tried and the error above occurs

AaronLee22 commented 8 months ago

if you want to use ignore-compile and build manually, you can add the --skip argument to your forge build invocation to achieve the same Slither does internally:

forge build --build-info --skip '*/test/**' '*/script/**'

That way test & script won't get built and Slither will then not process that code.

I tried forge build --build-info --skip '*/test/*' '/script/**' as below

Have I done something wrong?

AaronLee22 commented 8 months ago

It says solc-select-1.0.4. without the --ignore-compile it works as expected but some how my repository has a complex building mechanism and want to use it in mono repo environment.

- name: Run Slither
  uses: crytic/slither-action@v0.3.1
  with:
    target: packages/tokamak/contracts-bedrock
    slither-config: packages/tokamak/contracts-bedrock/slither.config.json
    fail-on: config
    slither-version: dev-triage-db
    slither-args: --triage-database packages/tokamak/contracts-bedrock/slither.db.json
    ignore-compile: true

The install dependencies and building contracts worked fine.

slither version is 0.10.0

elopez commented 8 months ago

if you want to use ignore-compile and build manually, you can add the --skip argument to your forge build invocation to achieve the same Slither does internally: forge build --build-info --skip '*/test/**' '*/script/**' That way test & script won't get built and Slither will then not process that code.

I tried forge build --build-info --skip '/test/**' '/script/**' as below - name: Build the contracts run: | pnpm run build forge build --build-info --skip 'packages/tokamak/contracts-bedrock/scripts' 'packages/contracts-bedrock/test' still same error occurs as above.

Have I done something wrong?

please try again, removing pnpm run build and keeping the asterisks on the forge invocation. You're likely running forge from within packages/tokamak/contracts-bedrock so the expanded paths you tried with won't match, and any previous forge runs launched from pnpm may generate artifacts that trigger the issue.

AaronLee22 commented 8 months ago

if you want to use ignore-compile and build manually, you can add the --skip argument to your forge build invocation to achieve the same Slither does internally: forge build --build-info --skip '*/test/**' '*/script/**' That way test & script won't get built and Slither will then not process that code.

I tried forge build --build-info --skip '/test/**' '/script/**' as below - name: Build the contracts run: | pnpm run build forge build --build-info --skip 'packages/tokamak/contracts-bedrock/scripts' 'packages/contracts-bedrock/test' still same error occurs as above. Have I done something wrong?

please try again, removing pnpm run build and keeping the asterisks on the forge invocation. You're likely running forge from within packages/tokamak/contracts-bedrock so the expanded paths you tried with won't match, and any previous forge runs launched from pnpm may generate artifacts that trigger the issue.

I appreciate your help!

- name: Build the contracts
  run: |
    cd packages/tokamak/contracts-bedrock
    forge build --build-info --skip '/test/**' '/scripts/**'

I attempted to follow your instructions as provided, yet the error persists as indicated below. Could you please elucidate why this error arises specifically in the presence of the "--ignore-compile" option, whereas it does not manifest in its absence?

--ignore-compile used, if something goes wrong, consider removing the ignore compile flag ERROR:ContractSolcParsing:Impossible to generate IR for LibSort._toInts (scripts/libraries/LibSort.sol#469-474): 'str' object has no attribute 'type' ERROR:SlitherSolcParsing: Failed to generate IR for LivenessGuard_TestInit._initializeSafeTools. Please open an issue https://github.com/crytic/slither/issues. LivenessGuard_TestInit._initializeSafeTools (test/safe-tools/SafeTestTools.sol#509-513): singleton = new GnosisSafe() proxyFactory = new GnosisSafeProxyFactory() handler = new CompatibilityFallbackHandler() Traceback (most recent call last): File "/opt/slither/bin/slither", line 8, in sys.exit(main()) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 735, in main main_impl(all_detector_classes=detectors, all_printer_classes=printers) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 841, in main_impl ) = process_all(filename, args, detector_classes, printer_classes) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 107, in process_all ) = process_single(compilation, args, detector_classes, printer_classes) File "/opt/slither/lib/python3.9/site-packages/slither/main.py", line 80, in process_single slither = Slither(target, ast_format=ast, **vars(args)) File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 146, in init self._init_parsing_and_analyses(kwargs.get("skip_analyze", False)) File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 166, in _init_parsing_and_analyses raise e File "/opt/slither/lib/python3.9/site-packages/slither/slither.py", line 162, in _init_parsing_and_analyses parser.analyze_contracts() File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 539, in analyze_contracts self._convert_to_slithir() File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 765, in _convert_to_slithir raise e File "/opt/slither/lib/python3.9/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 750, in _convert_to_slithir func.generate_slithir_and_analyze() File "/opt/slither/lib/python3.9/site-packages/slither/core/declarations/function.py", line 1772, in generate_slithir_and_analyze node.slithir_generation() File "/opt/slither/lib/python3.9/site-packages/slither/core/cfg/node.py", line 716, in slithir_generation self._irs = convert_expression(expression, self) # type:ignore File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 118, in convert_expression result = apply_ir_heuristics(result, node, is_solidity) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 2033, in apply_ir_heuristics irs = propagate_type_and_convert_call(irs, node) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 529, in propagate_type_and_convert_call new_ins = propagate_types(ins, node) File "/opt/slither/lib/python3.9/site-packages/slither/slithir/convert.py", line 875, in propagate_types assert contract AssertionError

AaronLee22 commented 8 months ago

this is the log for Build the contracts

Run cd packages/tokamak/contracts-bedrock cd packages/tokamak/contracts-bedrock forge build --build-info --skip '/test/' '/scripts/' shell: /usr/bin/bash -e {0} installing solc version "0.8.19" Successfully installed solc 0.8.19 installing solc version "0.8.23" Successfully installed solc 0.8.23 installing solc version "0.8.15" Successfully installed solc 0.8.15 installing solc version "0.5.17" Successfully installed solc 0.5.17 Compiling 1 files with 0.5.17 Compiling 34 files with 0.8.19 Compiling 300 files with 0.8.15 Compiling 114 files with 0.8.23 Solc 0.5.17 finished in 47.42ms Solc 0.8.19 finished in 4.29s Solc 0.8.23 finished in 6.91s Solc 0.8.15 finished in 111.49s Compiler run successful!

elopez commented 8 months ago
- name: Build the contracts
  run: |
    cd packages/tokamak/contracts-bedrock
    forge build --build-info --skip '/test/**' '/scripts/**'

I attempted to follow your instructions as provided, yet the error persists as indicated below. Could you please elucidate why this error arises specifically in the presence of the "--ignore-compile" option, whereas it does not manifest in its absence?

Hi! It looks like you're still missing the asterisks at the beginning, please have another look at my message here: https://github.com/crytic/slither/issues/2354#issuecomment-1979937142

AaronLee22 commented 8 months ago
- name: Build the contracts
  run: |
    cd packages/tokamak/contracts-bedrock
    forge build --build-info --skip '/test/**' '/scripts/**'

I attempted to follow your instructions as provided, yet the error persists as indicated below. Could you please elucidate why this error arises specifically in the presence of the "--ignore-compile" option, whereas it does not manifest in its absence?

Hi! It looks like you're still missing the asterisks at the beginning, please have another look at my message here: #2354 (comment)

Wow it works now!! By the way can you tell me the reason why the [Failed to generate IR] error occurs? I don't really want to except any of the contracts.

Thanks again

elopez commented 8 months ago

I don't know what's causing the underlying issue with IR generation here. If your repository is public and you can share a link with us, that might help triage this bug further.

AaronLee22 commented 8 months ago

Here are the smart contract links that's having this issue.

https://github.com/tokamak-network/tokamak-titan-canyon/blob/main/packages/tokamak/contracts-bedrock/scripts/libraries/LibSort.sol

https://github.com/tokamak-network/tokamak-titan-canyon/blob/main/packages/tokamak/contracts-bedrock/test/safe-tools/SafeTestTools.sol

Thank you for helping me solve this issue!

0xalpharush commented 8 months ago

I am pretty sure that the assert contract failure is caused by the use of alias in the import

The need to support this is tracked in https://github.com/crytic/slither/issues/1452

aviggiano commented 7 months ago

I am pretty sure that the assert contract failure is caused by the use of alias in the import

The need to support this is tracked in #1452

Hello

I'm having the same issue and I don't have import aliases on src/, only on test/ and script/. Even after adding ingnore-compile and manually executing the command @elopez shared, it didn't work. Trying to use a previous slither version (0.9.6) doesn't work either.

Unfortunately, the repo is closed source, so I'll keep trying some alternatives until I find more information to share here.

aviggiano commented 7 months ago

Ok, after some trial and error, I think I understand what is causing the IR generation failure.

I am using an Errors library, like this:

library Errors {
    error NULL_AMOUNT();
    error NULL_ADDRESS();
}

Then, whenever I use revert Errors.XXX(), it causes a problem.

TMP_2534(None) = LIBRARY_CALL, dest:Errors, function:NULL_AMOUNT, arguments:[]
ERROR:SlitherSolcParsing:

Idk why, since this wasn't happening before. I'll try to create a MWE

0xalpharush commented 7 months ago

@aviggiano Would you open a new issue with the full stack trace and show the output of adding --disallow-partial please? To be clear, ignore-compile will prevent slither for running the build command and use whatever artifacts on disk, meaning they could be incomplete (bc of some filtering or partial compilation) or include scripts or tests which is where the bug may be present (which we skip by default)