Additional fixes

pull/823/head
Josselin 4 years ago
parent 71e33c608e
commit 84f76055a1
  1. 6
      slither/core/compilation_unit.py
  2. 20
      slither/printers/guidance/echidna.py
  3. 8
      slither/printers/summary/evm.py
  4. 16
      slither/slithir/convert.py
  5. 10
      slither/tools/flattening/flattening.py
  6. 2
      slither/tools/upgradeability/checks/abstract_checks.py

@ -2,7 +2,7 @@ import math
from collections import defaultdict
from typing import Optional, Dict, List, Set, Union, TYPE_CHECKING, Tuple
from crytic_compile import CompilationUnit
from crytic_compile import CompilationUnit, CryticCompile
from crytic_compile.compiler.compiler import CompilerVersion
from slither.core.context.context import Context
@ -81,6 +81,10 @@ class SlitherCompilationUnit(Context):
def crytic_compile_compilation_unit(self) -> CompilationUnit:
return self._crytic_compile_compilation_unit
@property
def crytic_compile(self) -> CryticCompile:
return self._crytic_compile_compilation_unit.crytic_compile
# endregion
###################################################################################
###################################################################################

@ -79,14 +79,8 @@ def _is_constant(f: Function) -> bool: # pylint: disable=too-many-branches
:return:
"""
if f.view or f.pure:
if (
f.contract.compilation_unit.crytic_compile
and f.contract.compilation_unit.crytic_compile.compiler_version
):
if not f.contract.compilation_unit.crytic_compile.compiler_version.version.startswith(
"0.4"
):
return True
if not f.contract.compilation_unit.solc_version.startswith("0.4"):
return True
if f.payable:
return False
if not f.is_implemented:
@ -108,14 +102,8 @@ def _is_constant(f: Function) -> bool: # pylint: disable=too-many-branches
if isinstance(ir, HighLevelCall):
if isinstance(ir.function, Variable) or ir.function.view or ir.function.pure:
# External call to constant functions are ensured to be constant only for solidity >= 0.5
if (
f.contract.compilation_unit.crytic_compile
and f.contract.compilation_unit.crytic_compile.compiler_version
):
if f.contract.compilation_unit.crytic_compile.compiler_version.version.startswith(
"0.4"
):
return False
if f.contract.compilation_unit.solc_version.startswith("0.4"):
return False
else:
return False
if isinstance(ir, InternalCall):

@ -38,8 +38,12 @@ def _extract_evm_info(slither):
contract.source_mapping["filename_absolute"],
)
contract_bytecode_init = slither.crytic_compile.bytecode_init(contract.name)
contract_srcmap_init = slither.crytic_compile.srcmap_init(contract.name)
contract_bytecode_init = (
contract.compilation_unit.crytic_compile_compilation_unit.bytecode_init(contract.name)
)
contract_srcmap_init = (
contract.compilation_unit.crytic_compile_compilation_unit.srcmap_init(contract.name)
)
cfg_init = CFG(contract_bytecode_init)
evm_info["cfg_init", contract.name] = cfg_init

@ -387,26 +387,14 @@ def _convert_type_contract(ir, compilation_unit: "SlitherCompilationUnit"):
contract = ir.variable_left.type.type
if ir.variable_right == "creationCode":
if compilation_unit.crytic_compile:
bytecode = compilation_unit.crytic_compile.bytecode_init(contract.name)
else:
logger.info(
"The codebase uses type(x).creationCode, but crytic-compile was not used. As a result, the bytecode cannot be found"
)
bytecode = "MISSING_BYTECODE"
bytecode = compilation_unit.crytic_compile_compilation_unit.bytecode_init(contract.name)
assignment = Assignment(ir.lvalue, Constant(str(bytecode)), ElementaryType("bytes"))
assignment.set_expression(ir.expression)
assignment.set_node(ir.node)
assignment.lvalue.set_type(ElementaryType("bytes"))
return assignment
if ir.variable_right == "runtimeCode":
if compilation_unit.crytic_compile:
bytecode = compilation_unit.crytic_compile.bytecode_runtime(contract.name)
else:
logger.info(
"The codebase uses type(x).runtimeCode, but crytic-compile was not used. As a result, the bytecode cannot be found"
)
bytecode = "MISSING_BYTECODE"
bytecode = compilation_unit.crytic_compile_compilation_unit.bytecode_runtime(contract.name)
assignment = Assignment(ir.lvalue, Constant(str(bytecode)), ElementaryType("bytes"))
assignment.set_expression(ir.expression)
assignment.set_node(ir.node)

@ -7,6 +7,7 @@ from typing import List, Set, Dict, Optional
from slither.core.declarations import SolidityFunction, EnumContract, StructureContract
from slither.core.declarations.contract import Contract
from slither.core.slither_core import SlitherCore
from slither.core.solidity_types import MappingType, ArrayType
from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.exceptions import SlitherException
@ -43,7 +44,7 @@ class Flattening:
# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-locals,too-few-public-methods
def __init__(
self,
slither,
slither: SlitherCore,
external_to_public=False,
remove_assert=False,
private_to_internal=False,
@ -51,7 +52,7 @@ class Flattening:
pragma_solidity: Optional[str] = None,
):
self._source_codes: Dict[Contract, str] = {}
self._slither = slither
self._slither: SlitherCore = slither
self._external_to_public = external_to_public
self._remove_assert = remove_assert
self._use_abi_encoder_v2 = False
@ -188,8 +189,9 @@ class Flattening:
ret = ""
if self._pragma_solidity:
ret += f"pragma solidity {self._pragma_solidity};\n"
elif self._slither.solc_version:
ret += f"pragma solidity {self._slither.solc_version};\n"
else:
# TODO support multiple compiler version
ret += f"pragma solidity {self._slither.crytic_compile.compilation_units[0].compiler_version.version};\n"
if self._use_abi_encoder_v2:
ret += "pragma experimental ABIEncoderV2;\n"

@ -139,7 +139,7 @@ class AbstractCheck(metaclass=abc.ABCMeta):
def generate_result(self, info, additional_fields=None):
output = Output(
info, additional_fields, markdown_root=self.contract.compilation_unit.markdown_root
info, additional_fields, markdown_root=self.contract.compilation_unit.core.markdown_root
)
output.data["check"] = self.ARGUMENT

Loading…
Cancel
Save