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.34k stars 970 forks source link

[Bug]:`slither .` fails with the error: AttributeError: 'CryticCompile' object has no attribute 'asts' #1841

Closed Rishabh42 closed 7 months ago

Rishabh42 commented 1 year ago

Describe the issue:

slither . fails with the error: AttributeError: 'CryticCompile' object has no attribute 'asts'

Same error occurring in the following operating systems:

  1. mac OS Monterey version 12.5
  2. Python 3.8 virtual environment
  3. Ubuntu 23.04 LTS

Code example to reproduce the issue:

Running slither . after following the steps here: https://github.com/crytic/slither

Version:

0.9.3

Relevant log output:

>>> slither .
'npx hardhat clean' running (wd: /Users/rishabhthaney/nbai/smart-contract)
'npx hardhat clean --global' running (wd: /Users/rishabhthaney/nbai/smart-contract)
'npx hardhat compile --force' running
Downloading compiler 0.8.7
Downloading compiler 0.4.24
Compiled 46 Solidity files successfully

(node:59760) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:27:5: Warning: Use of the "var" keyword is deprecated.
    var _allowance = allowed[_from][msg.sender];
    ^------------^

@chainlink/contracts/src/v0.4/LinkToken.sol:15:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
  function LinkToken()
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/ERC677Token.sol:21:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(msg.sender, _to, _value, _data);
    ^--------------------------------------^

@chainlink/contracts/src/v0.4/vendor/BasicToken.sol:25:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(msg.sender, _to, _value);
    ^-------------------------------^

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:35:5: Warning: Invoking events without "emit" prefix is deprecated.
    Transfer(_from, _to, _value);
    ^--------------------------^

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:46:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, _value);
    ^------------------------------------^

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:69:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    ^-----------------------------------------------------------^

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:81:5: Warning: Invoking events without "emit" prefix is deprecated.
    Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
    ^-----------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC20Basic.sol:11:3: Warning: No visibility specified. Defaulting to "public". 
  function balanceOf(address who) constant returns (uint256);
  ^---------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC20Basic.sol:12:3: Warning: No visibility specified. Defaulting to "public". 
  function transfer(address to, uint256 value) returns (bool);
  ^----------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC20.sol:12:3: Warning: No visibility specified. Defaulting to "public". 
  function allowance(address owner, address spender) constant returns (uint256);
  ^----------------------------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC20.sol:13:3: Warning: No visibility specified. Defaulting to "public". 
  function transferFrom(address from, address to, uint256 value) returns (bool);
  ^----------------------------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC20.sol:14:3: Warning: No visibility specified. Defaulting to "public". 
  function approve(address spender, uint256 value) returns (bool);
  ^--------------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC677.sol:6:3: Warning: No visibility specified. Defaulting to "public". 
  function transferAndCall(address to, uint value, bytes data) returns (bool success);
  ^----------------------------------------------------------------------------------^

@chainlink/contracts/src/v0.4/interfaces/ERC677Receiver.sol:5:3: Warning: No visibility specified. Defaulting to "public". 
  function onTokenTransfer(address _sender, uint _value, bytes _data);
  ^------------------------------------------------------------------^

@chainlink/contracts/src/v0.4/vendor/BasicToken.sol:22:3: Warning: No visibility specified. Defaulting to "public". 
  function transfer(address _to, uint256 _value) returns (bool) {
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/BasicToken.sol:34:3: Warning: No visibility specified. Defaulting to "public". 
  function balanceOf(address _owner) constant returns (uint256 balance) {
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:26:3: Warning: No visibility specified. Defaulting to "public". 
  function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:44:3: Warning: No visibility specified. Defaulting to "public". 
  function approve(address _spender, uint256 _value) returns (bool) {
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:56:3: Warning: No visibility specified. Defaulting to "public". 
  function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:66:3: Warning: No visibility specified. Defaulting to "public". 
  function increaseApproval (address _spender, uint _addedValue) 
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/vendor/StandardToken.sol:73:3: Warning: No visibility specified. Defaulting to "public". 
  function decreaseApproval (address _spender, uint _subtractedValue) 
  ^ (Relevant source part starts here and spans across multiple lines).

@chainlink/contracts/src/v0.4/ERC677Token.sol:38:3: Warning: Function state mutability can be restricted to view
  function isContract(address _addr)
  ^ (Relevant source part starts here and spans across multiple lines).

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 712, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 82, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 65, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/usr/local/lib/python3.8/site-packages/slither/slither.py", line 81, in __init__
    for path, ast in crytic_compile.asts.items():
AttributeError: 'CryticCompile' object has no attribute 'asts'
ERROR:root:None
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 712, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 82, in process_all
    ) = process_single(compilation, args, detector_classes, printer_classes)
  File "/usr/local/lib/python3.8/site-packages/slither/__main__.py", line 65, in process_single
    slither = Slither(target, ast_format=ast, **vars(args))
  File "/usr/local/lib/python3.8/site-packages/slither/slither.py", line 81, in __init__
    for path, ast in crytic_compile.asts.items():
AttributeError: 'CryticCompile' object has no attribute 'asts'
0xalpharush commented 1 year ago

This looks related to https://github.com/crytic/crytic-compile/pull/420

Rishabh42 commented 1 year ago

Yup that's the one, thanks for confirming @0xalpharush Is there a more stable build of Slither, maybe an older version which I could use?

Slither was working fine previously when I had used it but that was a year ago

0xalpharush commented 1 year ago

This is a weird quirk of a very old compiler version and the latest version of slither contains many bug fixes and improvements so it would not make sense to use an older one. You can get around this issue until we make a release by applying the following patch to the ENS codebase. Thanks for reporting the issue! Hope this helps

diff --git a/contracts/utils/DummyOldResolver.sol b/contracts/utils/DummyOldResolver.sol
index ed38225..678b07b 100644
--- a/contracts/utils/DummyOldResolver.sol
+++ b/contracts/utils/DummyOldResolver.sol
@@ -1,5 +1,5 @@
 // SPDX-License-Identifier: MIT
-pragma solidity 0.4.11;
+pragma solidity ^0.4.11;

 contract DummyOldResolver {
     function test() public returns (bool) {
diff --git a/hardhat.config.ts b/hardhat.config.ts
index 4909de8..c6fd64c 100644
--- a/hardhat.config.ts
+++ b/hardhat.config.ts
@@ -82,7 +82,7 @@ const config: HardhatUserConfig = {
       },
       // for DummyOldResolver contract
       {
-        version: '0.4.11',
+        version: '0.4.12',
         settings: {
           optimizer: {
             enabled: true,
Rishabh42 commented 1 year ago

Thanks for the response @0xalpharush ! Could you please share the link of the 'ENS' code base? The 'ENS' that I know is this one: https://github.com/ensdomains/ens , but I don't think that's related to this issue

If you could please clarify this and I'll apply the patch at the right place and test it

Cheers