-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print all entry points not reaching whenNotPaused. Fix - 1114 (#1128)
New printer pausable: print what functions use whenNotPaused. Fix #1114 Co-authored-by: Josselin <[email protected]>
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |