Merge pull request #810 from crytic/dev-fix-types-propagation

Fix signed integer type propagation
pull/815/head
Feist Josselin 4 years ago committed by GitHub
commit b0075a41ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      slither/printers/summary/slithir.py
  2. 20
      slither/slithir/convert.py

@ -39,7 +39,7 @@ class PrinterSlithIR(AbstractPrinter):
continue continue
txt += "Contract {}\n".format(contract.name) txt += "Contract {}\n".format(contract.name)
for function in contract.functions: for function in contract.functions:
txt = f'\tFunction {function.canonical_name} {"" if function.is_shadowed else "(*)"}\n' txt += f'\tFunction {function.canonical_name} {"" if function.is_shadowed else "(*)"}\n'
txt += _print_function(function) txt += _print_function(function)
for modifier in contract.modifiers: for modifier in contract.modifiers:
txt += "\tModifier {}\n".format(modifier.canonical_name) txt += "\tModifier {}\n".format(modifier.canonical_name)

@ -1475,15 +1475,15 @@ def convert_constant_types(irs):
if isinstance(ir.rvalue, TupleVariable): if isinstance(ir.rvalue, TupleVariable):
# TODO: fix missing Unpack conversion # TODO: fix missing Unpack conversion
continue continue
if ir.rvalue.type.type != "int256": if ir.rvalue.type.type not in ElementaryTypeInt:
ir.rvalue.set_type(ElementaryType("int256")) ir.rvalue.set_type(ElementaryType(ir.lvalue.type.type))
was_changed = True was_changed = True
if isinstance(ir, Binary): if isinstance(ir, Binary):
if isinstance(ir.lvalue.type, ElementaryType): if isinstance(ir.lvalue.type, ElementaryType):
if ir.lvalue.type.type in ElementaryTypeInt: if ir.lvalue.type.type in ElementaryTypeInt:
for r in ir.read: for r in ir.read:
if r.type.type != "int256": if r.type.type not in ElementaryTypeInt:
r.set_type(ElementaryType("int256")) r.set_type(ElementaryType(ir.lvalue.type.type))
was_changed = True was_changed = True
if isinstance(ir, (HighLevelCall, InternalCall)): if isinstance(ir, (HighLevelCall, InternalCall)):
func = ir.function func = ir.function
@ -1498,8 +1498,8 @@ def convert_constant_types(irs):
t = types[idx] t = types[idx]
if isinstance(t, ElementaryType): if isinstance(t, ElementaryType):
if t.type in ElementaryTypeInt: if t.type in ElementaryTypeInt:
if arg.type.type != "int256": if arg.type.type not in ElementaryTypeInt:
arg.set_type(ElementaryType("int256")) arg.set_type(ElementaryType(t.type))
was_changed = True was_changed = True
if isinstance(ir, NewStructure): if isinstance(ir, NewStructure):
st = ir.structure st = ir.structure
@ -1507,16 +1507,16 @@ def convert_constant_types(irs):
e = st.elems_ordered[idx] e = st.elems_ordered[idx]
if isinstance(e.type, ElementaryType): if isinstance(e.type, ElementaryType):
if e.type.type in ElementaryTypeInt: if e.type.type in ElementaryTypeInt:
if arg.type.type != "int256": if arg.type.type not in ElementaryTypeInt:
arg.set_type(ElementaryType("int256")) arg.set_type(ElementaryType(e.type.type))
was_changed = True was_changed = True
if isinstance(ir, InitArray): if isinstance(ir, InitArray):
if isinstance(ir.lvalue.type, ArrayType): if isinstance(ir.lvalue.type, ArrayType):
if isinstance(ir.lvalue.type.type, ElementaryType): if isinstance(ir.lvalue.type.type, ElementaryType):
if ir.lvalue.type.type.type in ElementaryTypeInt: if ir.lvalue.type.type.type in ElementaryTypeInt:
for r in ir.read: for r in ir.read:
if r.type.type != "int256": if r.type.type not in ElementaryTypeInt:
r.set_type(ElementaryType("int256")) r.set_type(ElementaryType(ir.lvalue.type.type.type))
was_changed = True was_changed = True

Loading…
Cancel
Save