Merge branch 'master' into dev

pull/68/head
Josselin 6 years ago
commit 6e229913d8
  1. 15
      README.md
  2. 3
      slither/detectors/functions/external_function.py
  3. 12
      slither/detectors/variables/uninitialized_state_variables.py
  4. 2
      slither/printers/call/call_graph.py
  5. 2
      slither/printers/functions/authorization.py
  6. 2
      slither/printers/inheritance/inheritance.py
  7. 2
      slither/printers/inheritance/inheritance_graph.py
  8. 2
      slither/printers/summary/contract.py
  9. 2
      slither/printers/summary/function.py
  10. 12
      slither/printers/summary/slithir.py
  11. 6
      slither/slithir/convert.py
  12. 3
      slither/utils/command_line.py

@ -71,13 +71,14 @@ To run a printer, use `--printers` and a comma-separated list of printers.
Num | Printer | Description
--- | --- | ---
1 | `call-graph` | the call graph
2 | `contract-summary` | a summary of the contract
3 | `function-summary` | the summary of the functions
4 | `inheritance` | the inheritance relation between contracts
5 | `inheritance-graph` | the inheritance graph
6 | `slithir` | the slithIR
7 | `vars-and-auth` | state variables written and the authorization of the functions
1 | `call-graph` | Export the call-graph of the contracts to a dot file
2 | `contract-summary` | Print a summary of the contracts
3 | `function-summary` | Print a summary of the functions
4 | `inheritance` | Print the inheritance relations between contracts
5 | `inheritance-graph` | Export the inheritance graph of each contract to a dot file
6 | `slithir` | Print the slithIR representation of the functions
7 | `vars-and-auth` | Print the state variables written and the authorization of the functions
## How to install

@ -54,7 +54,8 @@ class ExternalFunction(AbstractDetector):
public_function_calls.extend(func_list)
for func in [f for f in contract.functions if f.visibility == 'public' and\
not f in public_function_calls]:
not f in public_function_calls and\
not f.is_constructor]:
func_name = func.name
txt = "Public function in {} Contract: {}, Function: {} should be declared external"
info = txt.format(self.filename,

@ -45,10 +45,20 @@ class UninitializedStateVarsDetection(AbstractDetector):
return ret
@staticmethod
def read_variables(contract):
ret = []
for f in contract.all_functions_called + contract.modifiers:
ret += f.state_variables_read
return ret
def detect_uninitialized(self, contract):
written_variables = self.written_variables(contract)
read_variables = self.read_variables(contract)
return [(variable, contract.get_functions_reading_from_variable(variable))
for variable in contract.state_variables if variable not in written_variables]
for variable in contract.state_variables if variable not in written_variables and\
not variable.expression and\
variable in read_variables]
def detect(self):
""" Detect uninitialized state variables

@ -40,7 +40,7 @@ def _node(node, label=None):
class PrinterCallGraph(AbstractPrinter):
ARGUMENT = 'call-graph'
HELP = 'the call graph'
HELP = 'Export the call-graph of the contracts to a dot file'
def __init__(self, slither, logger):
super(PrinterCallGraph, self).__init__(slither, logger)

@ -9,7 +9,7 @@ from slither.core.declarations.function import Function
class PrinterWrittenVariablesAndAuthorization(AbstractPrinter):
ARGUMENT = 'vars-and-auth'
HELP = 'the state variables written and the authorization of the functions'
HELP = 'Print the state variables written and the authorization of the functions'
@staticmethod
def get_msg_sender_checks(function):

@ -10,7 +10,7 @@ from slither.utils.colors import blue, green
class PrinterInheritance(AbstractPrinter):
ARGUMENT = 'inheritance'
HELP = 'the inheritance relation between contracts'
HELP = 'Print the inheritance relations between contracts'
def _get_child_contracts(self, base):
# Generate function to get all child contracts of a base contract

@ -12,7 +12,7 @@ from slither.printers.abstract_printer import AbstractPrinter
class PrinterInheritanceGraph(AbstractPrinter):
ARGUMENT = 'inheritance-graph'
HELP = 'the inheritance graph'
HELP = 'Export the inheritance graph of each contract to a dot file'
def __init__(self, slither, logger):
super(PrinterInheritanceGraph, self).__init__(slither, logger)

@ -8,7 +8,7 @@ from slither.utils.colors import blue, green, magenta
class ContractSummary(AbstractPrinter):
ARGUMENT = 'contract-summary'
HELP = 'a summary of the contract'
HELP = 'Print a summary of the contracts'
def output(self, _filename):
"""

@ -8,7 +8,7 @@ from slither.printers.abstract_printer import AbstractPrinter
class FunctionSummary(AbstractPrinter):
ARGUMENT = 'function-summary'
HELP = 'the summary of the functions'
HELP = 'Print a summary of the functions'
@staticmethod
def _convert(l):

@ -8,7 +8,7 @@ from slither.utils.colors import blue, green, magenta
class PrinterSlithIR(AbstractPrinter):
ARGUMENT = 'slithir'
HELP = 'the slithIR'
HELP = 'Print the slithIR representation of the functions'
def output(self, _filename):
"""
@ -29,4 +29,14 @@ class PrinterSlithIR(AbstractPrinter):
print('\t\tIRs:')
for ir in node.irs:
print('\t\t\t{}'.format(ir))
for modifier in contract.modifiers:
if modifier.contract == contract:
print('\tModifier {}'.format(modifier.full_name))
for node in modifier.nodes:
print(node)
if node.expression:
print('\t\tExpression: {}'.format(node.expression))
print('\t\tIRs:')
for ir in node.irs:
print('\t\t\t{}'.format(ir))
self.info(txt)

@ -636,6 +636,12 @@ def convert_expression(expression, node):
if isinstance(expression, Identifier) and node.type == NodeType.RETURN:
result = [Return(expression.value)]
return result
if isinstance(expression, Literal) and node.type in [NodeType.IF, NodeType.IFLOOP]:
result = [Condition(Constant(expression.value))]
return result
if isinstance(expression, Identifier) and node.type in [NodeType.IF, NodeType.IFLOOP]:
result = [Condition(expression.value)]
return result
visitor = ExpressionToSlithIR(expression)
result = visitor.result()

@ -43,6 +43,9 @@ def output_detectors(detector_classes):
detectors_list = []
for detector in detector_classes:
argument = detector.ARGUMENT
# dont show the backdoor example
if argument == 'backdoor':
continue
help_info = detector.HELP
impact = detector.IMPACT
confidence = classification_txt[detector.CONFIDENCE]

Loading…
Cancel
Save