How to use the mythril.laser.ethereum.util.get_concrete_int function in mythril

To help you get started, we’ve selected a few mythril examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ConsenSys / mythril / mythril / laser / ethereum / taint_analysis.py View on Github external
def mutate_sstore(record: TaintRecord, op0: Expression) -> None:
        """

        :param record:
        :param op0:
        :return:
        """
        _, value_taint = record.stack.pop(), record.stack.pop()
        try:
            index = helper.get_concrete_int(op0)
        except TypeError:
            log.debug("Can't mstore taint track symbolically")
            return

        record.storage[index] = value_taint
github ConsenSys / mythril / mythril / laser / ethereum / instructions.py View on Github external
def _calldata_copy_helper(global_state, mstate, mstart, dstart, size):
        environment = global_state.environment

        try:
            mstart = util.get_concrete_int(mstart)
        except TypeError:
            log.debug("Unsupported symbolic memory offset in CALLDATACOPY")
            return [global_state]

        try:
            dstart = util.get_concrete_int(dstart)  # type: Union[int, BitVec]
        except TypeError:
            log.debug("Unsupported symbolic calldata offset in CALLDATACOPY")
            dstart = simplify(dstart)

        try:
            size = util.get_concrete_int(size)  # type: Union[int, BitVec]
        except TypeError:
            log.debug("Unsupported symbolic size in CALLDATACOPY")
            size = 320  # The excess size will get overwritten

        size = cast(int, size)
        if size > 0:
            try:
                mstate.mem_extend(mstart, size)
            except TypeError as e:
                log.debug("Memory allocation error: {}".format(e))
github ConsenSys / mythril / mythril / laser / ethereum / taint_analysis.py View on Github external
def mutate_mload(record: TaintRecord, op0: Expression) -> None:
        """

        :param record:
        :param op0:
        :return:
        """
        _ = record.stack.pop()
        try:
            index = helper.get_concrete_int(op0)
        except TypeError:
            log.debug("Can't MLOAD taint track symbolically")
            record.stack.append(False)
            return

        record.stack.append(record.memory_tainted(index))
github ConsenSys / mythril / mythril / laser / ethereum / call.py View on Github external
symbol_factory.BitVecVal(memory_size, 256)
            if isinstance(memory_size, int)
            else memory_size
        ),
    )

    uses_entire_calldata = simplify(
        memory_size == global_state.environment.calldata.calldatasize
    )

    if is_true(uses_entire_calldata):
        return global_state.environment.calldata

    try:
        calldata_from_mem = state.memory[
            util.get_concrete_int(memory_start) : util.get_concrete_int(
                memory_start + memory_size
            )
        ]
        return ConcreteCalldata(transaction_id, calldata_from_mem)
    except TypeError:
        log.debug(
            "Unsupported symbolic memory offset %s size %s", memory_start, memory_size
        )
        return SymbolicCalldata(transaction_id)
github ConsenSys / mythril / mythril / laser / ethereum / instructions.py View on Github external
def revert_(self, global_state: GlobalState) -> None:
        """

        :param global_state:
        """
        state = global_state.mstate
        offset, length = state.stack.pop(), state.stack.pop()
        return_data = [global_state.new_bitvec("return_data", 8)]
        try:
            return_data = state.memory[
                util.get_concrete_int(offset) : util.get_concrete_int(offset + length)
            ]
        except TypeError:
            log.debug("Return with symbolic length or offset. Not supported")
        global_state.current_transaction.end(
            global_state, return_data=return_data, revert=True
        )
github ConsenSys / mythril / mythril / analysis / modules / integer.py View on Github external
def _handle_return(state: GlobalState) -> None:
        """
        Adds all the annotations into the state which correspond to the
        locations in the memory returned by RETURN opcode.
        :param state: The Global State
        """

        stack = state.mstate.stack
        try:
            offset, length = get_concrete_int(stack[-1]), get_concrete_int(stack[-2])
        except TypeError:
            return

        state_annotation = _get_overflowunderflow_state_annotation(state)

        for element in state.mstate.memory[offset : offset + length]:

            if not isinstance(element, Expression):
                continue

            for annotation in element.annotations:
                if isinstance(annotation, OverUnderflowAnnotation):
                    state_annotation.overflowing_state_annotations.add(annotation)
github ConsenSys / mythril / mythril / laser / ethereum / instructions.py View on Github external
except TypeError:
            # except both attribute error and Exception
            global_state.mstate.mem_extend(concrete_memory_offset, 1)
            global_state.mstate.memory[
                concrete_memory_offset
            ] = global_state.new_bitvec(
                "code({})".format(
                    global_state.environment.active_account.contract_name
                ),
                8,
            )
            return [global_state]

        try:
            concrete_code_offset = helper.get_concrete_int(code_offset)
        except TypeError:
            log.debug("Unsupported symbolic code offset in {}".format(op))
            global_state.mstate.mem_extend(concrete_memory_offset, concrete_size)
            for i in range(concrete_size):
                global_state.mstate.memory[
                    concrete_memory_offset + i
                ] = global_state.new_bitvec(
                    "code({})".format(
                        global_state.environment.active_account.contract_name
                    ),
                    8,
                )
            return [global_state]

        if code[0:2] == "0x":
            code = code[2:]
github ConsenSys / mythril / mythril / laser / ethereum / instructions.py View on Github external
def signextend_(self, global_state: GlobalState) -> List[GlobalState]:
        """

        :param global_state:
        :return:
        """
        mstate = global_state.mstate
        s0, s1 = mstate.stack.pop(), mstate.stack.pop()

        try:
            s0 = util.get_concrete_int(s0)
            s1 = util.get_concrete_int(s1)
        except TypeError:
            log.debug("Unsupported symbolic argument for SIGNEXTEND")
            mstate.stack.append(
                global_state.new_bitvec(
                    "SIGNEXTEND({},{})".format(hash(s0), hash(s1)), 256
                )
            )
            return [global_state]

        if s0 <= 31:
            testbit = s0 * 8 + 7
            if s1 & (1 << testbit):
                mstate.stack.append(s1 | (TT256 - (1 << testbit)))
            else:
                mstate.stack.append(s1 & ((1 << testbit) - 1))
        else:
github ConsenSys / mythril / mythril / laser / ethereum / instructions.py View on Github external
)

        try:
            concrete_memory_offset = helper.get_concrete_int(memory_offset)
        except TypeError:
            log.debug("Unsupported symbolic memory offset in RETURNDATACOPY")
            return [global_state]

        try:
            concrete_return_offset = helper.get_concrete_int(return_offset)
        except TypeError:
            log.debug("Unsupported symbolic return offset in RETURNDATACOPY")
            return [global_state]

        try:
            concrete_size = helper.get_concrete_int(size)
        except TypeError:
            log.debug("Unsupported symbolic max_length offset in RETURNDATACOPY")
            return [global_state]

        if global_state.last_return_data is None:
            return [global_state]

        global_state.mstate.mem_extend(concrete_memory_offset, concrete_size)
        for i in range(concrete_size):
            global_state.mstate.memory[concrete_memory_offset + i] = (
                global_state.last_return_data[concrete_return_offset + i]
                if i < len(global_state.last_return_data)
                else 0
            )

        return [global_state]