convert raw_call to LowLevelCall

pull/2099/head
alpharush 1 year ago
parent 85e63c6ba5
commit 55ab580a75
  1. 7
      slither/slithir/convert.py
  2. 16
      slither/vyper_parsing/expressions/expression_parsing.py

@ -1131,6 +1131,7 @@ def can_be_low_level(ir: HighLevelCall) -> bool:
"delegatecall",
"callcode",
"staticcall",
"raw_call",
]
@ -1159,13 +1160,14 @@ def convert_to_low_level(
ir.set_node(prev_ir.node)
ir.lvalue.set_type(ElementaryType("bool"))
return ir
if ir.function_name in ["call", "delegatecall", "callcode", "staticcall"]:
if ir.function_name in ["call", "delegatecall", "callcode", "staticcall", "raw_call"]:
new_ir = LowLevelCall(
ir.destination, ir.function_name, ir.nbr_arguments, ir.lvalue, ir.type_call
)
new_ir.call_gas = ir.call_gas
new_ir.call_value = ir.call_value
new_ir.arguments = ir.arguments
# TODO fix this for Vyper
if ir.node.compilation_unit.solc_version >= "0.5":
new_ir.lvalue.set_type([ElementaryType("bool"), ElementaryType("bytes")])
else:
@ -1916,7 +1918,8 @@ def apply_ir_heuristics(irs: List[Operation], node: "Node") -> List[Operation]:
irs = propagate_type_and_convert_call(irs, node)
irs = remove_unused(irs)
find_references_origin(irs)
convert_constant_types(irs)
# TODO refine only for Solidity
# convert_constant_types(irs)
convert_delete(irs)
_find_source_mapping_references(irs)

@ -311,10 +311,10 @@ def parse_expression(expression: Dict, caller_context) -> "Expression":
if isinstance(expression, Call):
called = parse_expression(expression.func, caller_context)
if isinstance(called, Identifier) and isinstance(called.value, SolidityFunction):
if called.value.name == "empty()":
type_to = parse_type(expression.args[0], caller_context)
# TODO figure out how to represent this type argument
parsed_expr = CallExpression(called, [], str(type_to))
parsed_expr.set_offset(expression.src, caller_context.compilation_unit)
return parsed_expr
@ -355,7 +355,19 @@ def parse_expression(expression: Dict, caller_context) -> "Expression":
),
)
return parsed_expr
elif called.value.name == "raw_call()":
args = [parse_expression(a, caller_context) for a in expression.args]
# This is treated specially in order to force `extract_tmp_call` to treat this as a `HighLevelCall` which will be converted
# to a `LowLevelCall` by `convert_to_low_level`. This is an artifact of the late conversion of Solidity...
call = CallExpression(MemberAccess("raw_call", "tuple(bool,bytes32)", args[0]), args[1:], "tuple(bool,bytes32)")
call.set_offset(expression.src, caller_context.compilation_unit)
call.call_value = next(iter(parse_expression(x.value, caller_context) for x in expression.keywords if x.arg == "value"), None)
call.call_gas = next(iter(parse_expression(x.value, caller_context) for x in expression.keywords if x.arg == "gas"), None)
# TODO handle `max_outsize` keyword
return call
if expression.args and isinstance(expression.args[0], VyDict):
arguments = []
for val in expression.args[0].values:

Loading…
Cancel
Save