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

Error while running slither #1540

Closed
NoroMeb opened this issue Jan 2, 2023 · 15 comments
Closed

Error while running slither #1540

NoroMeb opened this issue Jan 2, 2023 · 15 comments

Comments

@NoroMeb
Copy link

NoroMeb commented Jan 2, 2023

Getting this error :

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 11: invalid start byte

while running slither . on the root of my brownie project .

have someone faced this error before and could handle it ?

ps : i have all dependencies installed successfully and brownie contracts compile with no probleme .

@0xalpharush
Copy link
Contributor

Can you post the full error message trace?

@NoroMeb
Copy link
Author

NoroMeb commented Jan 4, 2023

@0xalpharush

Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main_.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main_.py", line 86, in process_all
compilations = compile_all(target, **vars(args))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 637, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 117, in init
self._compile(**kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 548, in compile
self.platform.compile(self, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\brownie.py", line 67, in compile
stderr_bytes.decode(),
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 11: invalid start byte
Error in .
Traceback (most recent call last):
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main
.py", line 826, in main_impl
) = process_all(filename, args, detector_classes, printer_classes)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\slither_main
.py", line 86, in process_all
compilations = compile_all(target, **vars(args))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 637, in compile_all
compilations.append(CryticCompile(target, **kwargs))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 117, in init
self._compile(**kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\crytic_compile.py", line 548, in _compile
self._platform.compile(self, **kwargs)
File "C:\Users\Dell\AppData\Local\Programs\Python\Python310\lib\site-packages\crytic_compile\platform\brownie.py", line 67, in compile
stderr_bytes.decode(),
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 11: invalid start byte

@0xalpharush
Copy link
Contributor

@elopez Do you have an idea what could cause this?

@elopez
Copy link
Member

elopez commented Jan 5, 2023

maybe there's something non-utf8 in brownie's stderr? 🤔 I think Windows used some other encoding for the terminal output.

@NoroMeb would you mind opening a terminal, navigating to your project folder with cd and then running the following command and attaching the generated stderr.bin and stdout.bin files in this issue? They will contain a copy of whatever you see when you run brownie compile but in the exact binary representation that slither & crytic-compile receive:

python3 -c "import subprocess, shutil; stdout, stderr = subprocess.Popen(['brownie', 'compile'], executable=shutil.which('brownie'), stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(); open('stdout.bin', 'wb').write(stdout); open('stderr.bin', 'wb').write(stderr)"

@NoroMeb
Copy link
Author

NoroMeb commented Jan 6, 2023

@elopez i tried but I have an error that github don't support binary files, what can i do ?

@elopez
Copy link
Member

elopez commented Jan 6, 2023

I think you can create a zip file with them and upload that @NoroMeb

@NoroMeb
Copy link
Author

NoroMeb commented Jan 6, 2023

stderr.zip @elopez

@elopez
Copy link
Member

elopez commented Jan 6, 2023

Thanks @NoroMeb!

@0xalpharush:

$ file *
stderr.bin: Non-ISO extended-ASCII text, with CRLF line terminators
stdout.bin: ASCII text, with CRLF line terminators

stdout is usual ASCII output:

Brownie v1.19.0 - Python development framework for Ethereum

Project has been compiled. Build artifacts saved at (...)

But stderr has this message (encoded in a DOS codepage, like https://en.wikipedia.org/wiki/Code_page_850) :

Information : impossible de trouver des fichiers pour le(s) modèle(s) spécifié(s).

Maybe we could sprinkle all the "debug" decode calls with ignore or backslashreplace:

% python3
Python 3.10.9 (main, Dec 15 2022, 17:11:09) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = open('stderr.bin', 'rb').read()
>>> print(x.decode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 11: invalid start byte
>>> print(x.decode(errors="ignore"))
Information: impossible de trouver des fichiers pour le(s) mod?le(s) spcifi(s).

>>> print(x.decode(errors="backslashreplace"))
Information\xff: impossible de trouver des fichiers pour le(s) mod?le(s) sp\x82cifi\x82(s).

@0xalpharush
Copy link
Contributor

0xalpharush commented Jan 9, 2023 via email

@NoroMeb
Copy link
Author

NoroMeb commented Jan 9, 2023

@0xalpharush @elopez what can i do to make it work for me ?

elopez added a commit to crytic/crytic-compile that referenced this issue Jan 9, 2023
Sometimes tools produce output not in UTF-8, and failing because
the tool error could not be processed does not provide a good UX.
This sprinkles backslashreplace on bytes.decode() for things that
are meant to be logged or printed as part of an error or warning
message.

Fixes: crytic/slither#1540
@elopez
Copy link
Member

elopez commented Jan 9, 2023

I don't understand French much, but maybe the error message "Information : impossible de trouver des fichiers pour le(s) modèle(s) spécifié(s)." gives you a better idea of what the underlying problem is.

I opened a PR with a fix to not fail completely if the error message has unexpected text encoding, this should also alleviate the problem: crytic/crytic-compile#351 If you want to try it out, you should be able to install the patched versions of Slither and crytic-compile as follows:

pip3 uninstall crytic-compile slither-analyzer
pip3 install https://github.com/crytic/slither/archive/refs/heads/dev.zip
pip3 uninstall crytic-compile
pip3 install https://github.com/crytic/crytic-compile/archive/refs/heads/dev-fix-error-decode.zip

@NoroMeb
Copy link
Author

NoroMeb commented Jan 10, 2023

@elopez
getting this error :

ERROR: HTTP error 404 while getting https://github.com/crytic/crytic-compile/archive/refs/heads/dev-fix-error-decode.zip
ERROR: Could not install requirement https://github.com/crytic/crytic-compile/archive/refs/heads/dev-fix-error-decode.zip because of HTTP error 404 Client Error: Not Found for url: https://codeload.github.com/crytic/crytic-compile/zip/refs/heads/dev-fix-error-decode for URL https://github.com/crytic/crytic-compile/archive/refs/heads/dev-fix-error-decode.zip

@elopez
Copy link
Member

elopez commented Jan 10, 2023

The PR got merged earlier today and the branch got deleted, so you got that error. You should be ok with just installing dev now:

pip3 uninstall crytic-compile slither-analyzer
pip3 install https://github.com/crytic/slither/archive/refs/heads/dev.zip

@NoroMeb
Copy link
Author

NoroMeb commented Jan 10, 2023

Does it act like main branche ?

@elopez
Copy link
Member

elopez commented Jan 10, 2023

yep, dev is the main development branch we use.

@NoroMeb NoroMeb closed this as completed Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants