Create ModifierStatements to allow IR conversion on modifier call

pull/293/head
Josselin 5 years ago
parent 43c6cf7a16
commit 22f8ed731d
  1. 4
      slither/core/cfg/node.py
  2. 21
      slither/core/declarations/function.py
  3. 8
      slither/printers/summary/slithir.py
  4. 25
      slither/solc_parsing/declarations/function.py

@ -62,6 +62,10 @@ class NodeType:
# Only modifier node
PLACEHOLDER = 0x40
# Node not related to the CFG
# Use for state variable declaration, or modifier calls
STANDALONE = 0x50
# @staticmethod
def str(t):

@ -15,10 +15,13 @@ from slither.core.expressions import (Identifier, IndexAccess, MemberAccess,
from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.state_variable import StateVariable
logger = logging.getLogger("Function")
ReacheableNode = namedtuple('ReacheableNode', ['node', 'ir'])
ModifierStatements = namedtuple('Modifier', ['modifier', 'node'])
class Function(ChildContract, ChildInheritance, SourceMapping):
"""
Function class
@ -324,6 +327,13 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
"""
list(Modifier): List of the modifiers
"""
return [c.modifier for c in self._modifiers]
@property
def modifiers_statements(self):
"""
list(ModifierCall): List of the modifiers call (include expression and irs)
"""
return list(self._modifiers)
@property
@ -335,7 +345,16 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
included.
"""
# This is a list of contracts internally, so we convert it to a list of constructor functions.
return [c.constructors_declared for c in self._explicit_base_constructor_calls if c.constructors_declared]
return [c.modifier.constructors_declared for c in self._explicit_base_constructor_calls if c.modifier.constructors_declared]
@property
def explicit_base_constructor_calls_statements(self):
"""
list(ModifierCall): List of the base constructors called explicitly by this presumed constructor definition.
"""
# This is a list of contracts internally, so we convert it to a list of constructor functions.
return [c for c in self._explicit_base_constructor_calls if c.modifier.constructors_declared]
# endregion

@ -34,6 +34,14 @@ class PrinterSlithIR(AbstractPrinter):
print('\t\tIRs:')
for ir in node.irs:
print('\t\t\t{}'.format(ir))
for modifier_statement in function.modifiers_statements:
print(f'\t\tModifier Call {modifier_statement.node.expression}')
for ir in modifier_statement.node.irs:
print('\t\t\t{}'.format(ir))
for modifier_statement in function.explicit_base_constructor_calls_statements:
print(f'\t\tConstructor Call {modifier_statement.node.expression}')
for ir in modifier_statement.node.irs:
print('\t\t\t{}'.format(ir))
for modifier in contract.modifiers:
print('\tModifier {}'.format(modifier.canonical_name))
for node in modifier.nodes:

@ -4,7 +4,7 @@ import logging
from slither.core.cfg.node import NodeType, link_nodes
from slither.core.declarations.contract import Contract
from slither.core.declarations.function import Function
from slither.core.declarations.function import Function, ModifierStatements
from slither.core.dominators.utils import (compute_dominance_frontier,
compute_dominators)
from slither.core.expressions import AssignmentOperation
@ -220,6 +220,12 @@ class FunctionSolc(Function):
for node in self.nodes:
node.analyze_expressions(self)
for modifier_statement in self.modifiers_statements:
modifier_statement.node.analyze_expressions(self)
for modifier_statement in self.explicit_base_constructor_calls_statements:
modifier_statement.node.analyze_expressions(self)
self._filter_ternary()
self._remove_alone_endif()
@ -897,9 +903,15 @@ class FunctionSolc(Function):
self._expression_modifiers.append(m)
for m in ExportValues(m).result():
if isinstance(m, Function):
self._modifiers.append(m)
node = self._new_node(NodeType.STANDALONE, modifier['src'])
node.add_unparsed_expression(modifier)
self._modifiers.append(ModifierStatements(modifier=m,
node=node))
elif isinstance(m, Contract):
self._explicit_base_constructor_calls.append(m)
node = self._new_node(NodeType.STANDALONE, modifier['src'])
node.add_unparsed_expression(modifier)
self._explicit_base_constructor_calls.append(ModifierStatements(modifier=m,
node=node))
# endregion
###################################################################################
@ -1122,6 +1134,13 @@ class FunctionSolc(Function):
def generate_slithir_and_analyze(self):
for node in self.nodes:
node.slithir_generation()
for modifier_statement in self.modifiers_statements:
modifier_statement.node.slithir_generation()
for modifier_statement in self.explicit_base_constructor_calls_statements:
modifier_statement.node.slithir_generation()
self._analyze_read_write()
self._analyze_calls()

Loading…
Cancel
Save