Repository: crytic/slither

Issue:
Human-summary printer: show number of lines of assemly code
The human summary printer should show if a contract uses inline assembly, and if so, shows the number of lines of assembly code


Discussion:

Resolving patch:
diff --git a/slither/printers/summary/human_summary.py b/slither/printers/summary/human_summary.py
--- a/slither/printers/summary/human_summary.py
+++ b/slither/printers/summary/human_summary.py
@@ -8,6 +8,8 @@
 from slither.utils.code_complexity import compute_cyclomatic_complexity
 from slither.utils.colors import green, red, yellow
 from slither.utils.standard_libraries import is_standard_library
+from slither.core.cfg.node import NodeType
+
 
 class PrinterHumanSummary(AbstractPrinter):
     ARGUMENT = 'human-summary'
@@ -29,14 +31,13 @@ def _get_summary_erc20(contract):
             else:
                 mint_limited = True
         else:
-            mint_limited = None # no minting
+            mint_limited = None  # no minting
 
-        race_condition_mitigated = 'increaseApproval' in functions_name or\
+        race_condition_mitigated = 'increaseApproval' in functions_name or \
                                    'safeIncreaseAllowance' in functions_name
 
         return pause, mint_limited, race_condition_mitigated
 
-
     def get_summary_erc20(self, contract):
         txt = ''
 
@@ -93,8 +94,6 @@ def _get_detectors_result(self):
         issues_high = [c for c in issues_high if c]
         issues_high = [item for sublist in issues_high for item in sublist]
 
-
-
         return (len(issues_optimization),
                 len(issues_informational),
                 len(issues_low),
@@ -159,6 +158,17 @@ def _lines_number(self):
                 total_lines += lines
         return total_lines, total_dep_lines
 
+    def _get_number_of_assembly_lines(self):
+        total_asm_lines = 0
+        for contract in self.contracts:
+            for function in contract.functions_declared:
+                for node in function.nodes:
+                    if node.type == NodeType.ASSEMBLY:
+                        inline_asm = node.inline_asm
+                        if inline_asm:
+                            total_asm_lines += len(inline_asm.splitlines())
+        return total_asm_lines
+
     def _compilation_type(self):
         if self.slither.crytic_compile is None:
             return 'Compilation non standard\n'
@@ -202,17 +212,20 @@ def output(self, _filename):
             },
             'number_lines': 0,
             'number_lines_in_dependencies': 0,
+            'number_lines_assembly': 0,
             'standard_libraries': [],
             'ercs': [],
         }
 
-
         lines_number = self._lines_number()
         if lines_number:
             total_lines, total_dep_lines = lines_number
             txt += f'Number of lines: {total_lines} (+ {total_dep_lines} in dependencies)\n'
             results['number_lines'] = total_lines
             results['number_lines__dependencies'] = total_dep_lines
+            total_asm_lines = self._get_number_of_assembly_lines()
+            txt += f"Number of assembly lines: {total_asm_lines}\n"
+            results['number_lines_assembly'] = total_asm_lines
 
         number_contracts, number_contracts_deps = self._number_contracts()
         txt += f'Number of contracts: {number_contracts} (+ {number_contracts_deps} in dependencies) \n\n'
@@ -272,4 +285,3 @@ def output(self, _filename):
         json = self.generate_output(txt, additional_fields=results)
 
         return json
-


Test patch: