From 31fd66acf52749d4543200c84b8a388c9ea75c59 Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Mon, 13 May 2019 10:58:14 +0200 Subject: [PATCH 1/2] ignore external calls to precompile contracts --- mythril/analysis/modules/external_calls.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mythril/analysis/modules/external_calls.py b/mythril/analysis/modules/external_calls.py index 554cbb93..10f1eaa4 100644 --- a/mythril/analysis/modules/external_calls.py +++ b/mythril/analysis/modules/external_calls.py @@ -5,7 +5,7 @@ from mythril.analysis import solver from mythril.analysis.swc_data import REENTRANCY from mythril.analysis.modules.base import DetectionModule from mythril.analysis.report import Issue -from mythril.laser.smt import UGT, symbol_factory +from mythril.laser.smt import UGT, symbol_factory, Or, BitVec from mythril.laser.ethereum.state.global_state import GlobalState from mythril.exceptions import UnsatError from copy import copy @@ -71,6 +71,8 @@ def _analyze_state(state): ) except UnsatError: + if _is_precompile_call(state): + return [] log.debug( "[EXTERNAL_CALLS] Callee address cannot be modified. Reporting informational issue." @@ -104,6 +106,22 @@ def _analyze_state(state): return [issue] +def _is_precompile_call(global_state: GlobalState): + to = global_state.mstate.stack[-2] # type: BitVec + try: + constraints = copy(global_state.mstate.constraints) + constraints += [ + Or( + to < symbol_factory.BitVecVal(1, 256), + to > symbol_factory.BitVecVal(16, 256), + ) + ] + solver.get_model(constraints) + return False + except UnsatError: + return True + + class ExternalCalls(DetectionModule): """This module searches for low level calls (e.g. call.value()) that forward all gas to the callee.""" From 6887fbdc06e1953c487a5bdafe0ae80f999c3840 Mon Sep 17 00:00:00 2001 From: Joran Honig Date: Tue, 14 May 2019 10:41:52 +0200 Subject: [PATCH 2/2] move constraint creation out of try context --- mythril/analysis/modules/external_calls.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mythril/analysis/modules/external_calls.py b/mythril/analysis/modules/external_calls.py index 10f1eaa4..e24470a6 100644 --- a/mythril/analysis/modules/external_calls.py +++ b/mythril/analysis/modules/external_calls.py @@ -108,14 +108,15 @@ def _analyze_state(state): def _is_precompile_call(global_state: GlobalState): to = global_state.mstate.stack[-2] # type: BitVec + constraints = copy(global_state.mstate.constraints) + constraints += [ + Or( + to < symbol_factory.BitVecVal(1, 256), + to > symbol_factory.BitVecVal(16, 256), + ) + ] + try: - constraints = copy(global_state.mstate.constraints) - constraints += [ - Or( - to < symbol_factory.BitVecVal(1, 256), - to > symbol_factory.BitVecVal(16, 256), - ) - ] solver.get_model(constraints) return False except UnsatError: