Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable offset may uninitialized #1782

Open
kabeor opened this issue Jun 26, 2023 · 3 comments
Open

Variable offset may uninitialized #1782

kabeor opened this issue Jun 26, 2023 · 3 comments

Comments

@kabeor
Copy link

kabeor commented Jun 26, 2023

https://github.com/ConsenSys/mythril/blob/develop/mythril/solidity/soliditycontract.py#L368C18-L368C18

    def _get_solc_mappings(self, srcmap, constructor=False):
        """

        :param srcmap:
        :param constructor:
        """
        mappings = self.constructor_mappings if constructor else self.mappings
        prev_item = ""
        for item in srcmap:
            if item == "":
                item = prev_item
            mapping = item.split(":")

            if len(mapping) > 0 and len(mapping[0]) > 0:
                offset = int(mapping[0])

            if len(mapping) > 1 and len(mapping[1]) > 0:
                length = int(mapping[1])

            if len(mapping) > 2 and len(mapping[2]) > 0:
                idx = int(mapping[2])

            if self._is_autogenerated_code(offset, length, idx):
                lineno = None
            else:
                lineno = (
                    self.solc_indices[idx]
                    .data.encode("utf-8")[0:offset]
                    .count("\n".encode("utf-8"))
                    + 1
                )
            prev_item = item
            mappings.append(SourceMapping(idx, offset, length, lineno, item))

L376(if self._is_autogenerated_code(offset, length, idx):) will cause UnboundLocalError: local variable 'offset' referenced before assignment if L367(if len(mapping) > 0 and len(mapping[0]) > 0:) is False.

@kabeor
Copy link
Author

kabeor commented Jun 26, 2023

Branch: develop

myth analyze xxx.sol --solc-json config.json

config.json is:

{
    "remappings": [ "@openzeppelin/=lib/openzeppelin-contracts/", "@layerzero/=lib/LayerZero/"],
     "optimizer": {
       "enabled": true
     }
}

But works after removing

     "optimizer": {
       "enabled": true
     }

@norhh
Copy link
Collaborator

norhh commented Jun 26, 2023

Hi @kabeor , That was intended as previous solc-mapping adhered to such convention starting with non-zero offset and only using "" when a previous offset exists, although I should have used a custom Exception in such scenario.
It could be a change in mapping from the recent solidity version. Can you point out the version of solidity where this bug pops up?

@kabeor
Copy link
Author

kabeor commented Jun 26, 2023

@norhh Sure, it's 0.8.20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants