From 9413e1ea9461e68127510e182a32ac0e8dafbf3d Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 18 Apr 2024 10:28:30 +0200 Subject: [PATCH] Fix #2430 EVM printer now correctly detects missing bytecode in contract and don't try to analyze them. --- slither/printers/summary/evm.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/slither/printers/summary/evm.py b/slither/printers/summary/evm.py index 0e5ce58d7..aad71bdff 100644 --- a/slither/printers/summary/evm.py +++ b/slither/printers/summary/evm.py @@ -1,6 +1,8 @@ """ Module printing evm mapping of the contract """ +import logging + from slither.printers.abstract_printer import AbstractPrinter from slither.analyses.evm import ( generate_source_to_evm_ins_mapping, @@ -9,6 +11,9 @@ from slither.analyses.evm import ( from slither.utils.colors import blue, green, magenta, red +logger: logging.Logger = logging.getLogger("EVMPrinter") + + def _extract_evm_info(slither): """ Extract evm information for all derived contracts using evm_cfg_builder @@ -24,6 +29,16 @@ def _extract_evm_info(slither): contract_bytecode_runtime = contract.file_scope.bytecode_runtime( contract.compilation_unit.crytic_compile_compilation_unit, contract.name ) + + if not contract_bytecode_runtime: + logger.info( + "Contract %s (abstract: %r) has no bytecode runtime, skipping. ", + contract.name, + contract.is_abstract, + ) + evm_info["empty", contract.name] = True + continue + contract_srcmap_runtime = contract.file_scope.srcmap_runtime( contract.compilation_unit.crytic_compile_compilation_unit, contract.name ) @@ -80,6 +95,10 @@ class PrinterEVM(AbstractPrinter): for contract in self.slither.contracts_derived: txt += blue(f"Contract {contract.name}\n") + if evm_info.get(("empty", contract.name), False): + txt += "\tempty contract\n" + continue + contract_file = self.slither.source_code[ contract.source_mapping.filename.absolute ].encode("utf-8")