<commit_before>from z3 import *
from mythril.analysis.ops import *
from mythril.analysis.report import Issue
import re
import logging


'''
MODULE DESCRIPTION:

Check for call.value()() to an untrusted address
'''

def execute(statespace):

    issues = []

    for call in statespace.calls:

        if (call.type == "CALL"):

            logging.debug("[CALL_TO_DYNAMIC_WITH_GAS] Call to: " + str(call.to) + ", value " + str(call.value) + ", gas = " + str(call.gas))

            if (call.to.type == VarType.SYMBOLIC and (call.gas.type == VarType.CONCRETE and call.gas.val > 2300) or (call.gas.type == VarType.SYMBOLIC and "2300" not in str(call.gas))):

                issue = Issue("CALL with gas to dynamic address", "Warning")

                target = str(call.to)
                is_valid = False

                if ("calldata" in target or "caller" in target):

                    issue.description = \
                        "The function " + call.node.function_name + " contains a call.value() to "

                    if ("calldata" in target):
                        issue.description += "an address provided as a function argument. "
                    else:
                        issue.description += "the address of the transaction sender. "

                    is_valid = True
                else:
                    m = re.search(r'storage_([a-z0-9_&^]+)', str(call.to))

                    if (m):
                        index = m.group(1)

                        try:

                            for s in statespace.sstors[index]:

                                if s.tainted:

                                    issue.description += \
                                        "The target address of the call is found at storage position " + str(index) + \
                                        "This storage position can be written to by calling the function '" + s.node.function_name + "'.\n" \
                                        "Make sure that the contract address cannot be set by untrusted users. "

                                    is_valid = True
                                    break

                        except KeyError:
                            logging.debug("[CALL_TO_DYNAMIC_WITH_GAS] No storage writes to index " + str(index))
                            continue<commit_msg>Update call_to_dynamic_with_gas.py<commit_after>from z3 import *
from mythril.analysis.ops import *
from mythril.analysis.report import Issue
import re
import logging


'''
MODULE DESCRIPTION:

Check for call.value()() to an untrusted address
'''

def execute(statespace):

    issues = []

    for call in statespace.calls:

        if (call.type == "CALL"):

            logging.debug("[CALL_TO_DYNAMIC_WITH_GAS] Call to: " + str(call.to) + ", value " + str(call.value) + ", gas = " + str(call.gas))

            if (call.to.type == VarType.SYMBOLIC and (call.gas.type == VarType.CONCRETE and call.gas.val > 2300) or (call.gas.type == VarType.SYMBOLIC and "2300" not in str(call.gas))):

                issue = Issue("CALL with gas to dynamic address", "Warning")
                issue.description = "The function " + call.node.function_name + " contains a call.value() to "

                target = str(call.to)
                is_valid = False

                if ("calldata" in target or "caller" in target):

                    if ("calldata" in target):
                        issue.description += "an address provided as a function argument. "
                    else:
                        issue.description += "the address of the transaction sender. "

                    is_valid = True
                else:
                    m = re.search(r'storage_([a-z0-9_&^]+)', str(call.to))

                    if (m):
                        index = m.group(1)

                        try:

                            for s in statespace.sstors[index]:

                                if s.tainted:

                                    issue.description += \
                                        "an address found at storage position " + str(index) + ".\n" + \
                                        "This storage position can be written to by calling the function '" + s.node.function_name + "'.\n" \
                                        "Verify that the contract address cannot be set by untrusted users.\n"

                                    is_valid = True
                                    break

                        except KeyError:
                            logging.debug("[CALL_TO_DYNAMIC_WITH_GAS] No storage writes to index " + str(index))
                            continue
{'fraction_non_alphanumeric': 0.09642168416541676, 'fraction_numerical': 0.005142489822155561, 'mean_word_length': 1.3086053412462908, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654876', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1139, 'n_words': 345}