Skip to content

Commit

Permalink
Print all entry points not reaching whenNotPaused. Fix - 1114 (#1128)
Browse files Browse the repository at this point in the history
New printer pausable:  print what functions use whenNotPaused. 

Fix #1114

Co-authored-by: Josselin <[email protected]>
  • Loading branch information
feliam and montyly authored Apr 15, 2022
1 parent 597ac46 commit e3b75c0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions slither/printers/all_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .summary.constructor_calls import ConstructorPrinter
from .guidance.echidna import Echidna
from .summary.evm import PrinterEVM
from .summary.when_not_paused import PrinterWhenNotPaused
61 changes: 61 additions & 0 deletions slither/printers/summary/when_not_paused.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Module printing summary of the contract
"""

from slither.core.declarations import Function
from slither.core.declarations.function import SolidityFunction
from slither.printers.abstract_printer import AbstractPrinter
from slither.utils import output
from slither.utils.myprettytable import MyPrettyTable


def _use_modifier(function: Function, modifier_name: str = "whenNotPaused") -> bool:
if function.is_constructor or function.view or function.pure:
return False

for internal_call in function.all_internal_calls():
if isinstance(internal_call, SolidityFunction):
continue
if any(modifier.name == modifier_name for modifier in function.modifiers):
return True
return False


class PrinterWhenNotPaused(AbstractPrinter):

ARGUMENT = "pausable"
HELP = "Print functions that do not use whenNotPaused"

WIKI = "https://github.com/trailofbits/slither/wiki/Printer-documentation#when-not-paused"

def output(self, _filename: str) -> output.Output:
"""
_filename is not used
Args:
_filename(string)
"""

modifier_name: str = "whenNotPaused"

txt = ""
txt += "Constructor and pure/view functions are not displayed\n"
all_tables = []
for contract in self.slither.contracts:

txt += f"\n{contract.name}:\n"
table = MyPrettyTable(["Name", "Use whenNotPaused"])

for function in contract.functions_entry_points:
status = "X" if _use_modifier(function, modifier_name) else ""
table.add_row([function.solidity_signature, status])

txt += str(table) + "\n"
all_tables.append((contract.name, table))

self.info(txt)

res = self.generate_output(txt)
for name, table in all_tables:
res.add_pretty_table(table, name)

return res

0 comments on commit e3b75c0

Please sign in to comment.