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

Fix parsing of compiler version and reformat file #1787

Merged
merged 2 commits into from
Jul 12, 2023

Conversation

abhinandanudupa
Copy link
Contributor

@abhinandanudupa abhinandanudupa commented Jul 9, 2023

Fixes a parsing error when the solidity source code specifies a version up to only the minor version number + reformatted the file with black:

pragma solidity ^0.8;

contract MyContract {
....

Error:

mythril.interfaces.cli [ERROR]: Traceback (most recent call last):
  File "~/mythril/mythril/interfaces/cli.py", line 966, in parse_args_and_execute
    address = load_code(disassembler, args)
  File "~/mythril/mythril/interfaces/cli.py", line 717, in load_code
    address, _ = disassembler.load_from_solidity(
  File "~/mythril/mythril/mythril/mythril_disassembler.py", line 252, in load_from_solidity
    solc_binary = self.solc_binary or util.extract_binary(file)
  File "~/mythril/mythril/ethereum/util.py", line 230, in extract_binary
    version = extract_version(file_data)
  File "~/mythril/mythril/ethereum/util.py", line 194, in extract_version
    pragma_dict = parse_pragma(version_line)
  File "~/mythril/mythril/ethereum/util.py", line 158, in parse_pragma
    result = pragma.parseString(solidity_code)
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 1955, in parseString
    raise exc
  File "/usr/lib/python3/dist-packages/pyparsing.py", line 3342, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected Re:('\\s*[0-9]+\\s*\\.\\s*[0-9]+\\s*\\.\\s*[0-9]+'), found '0'  (at char 17), (line:1, col:18)

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2023

CLA assistant check
All committers have signed the CLA.

@norhh
Copy link
Collaborator

norhh commented Jul 11, 2023

Thanks for the catch! Can you also add a simple testcase in tests/integration_tests/version_test.py? You'll have to add the file name with this test case and add this file to the input_contracts directory.

@abhinandanudupa
Copy link
Contributor Author

@norhh I have added the integration test

@norhh
Copy link
Collaborator

norhh commented Jul 11, 2023

Thanks for adding the test! Is the black formatting working for you? As I see the test failing. You can run black mythril/ethereum/util.py and see if it changes anything.

@abhinandanudupa
Copy link
Contributor Author

Is the black formatting working for you? As I see the test failing. You can run black mythril/ethereum/util.py and see if it changes anything.

Looks like the number of columns was set lower for VSCodium than the default number.

Copy link
Collaborator

@norhh norhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work! Thank you for the PR 🚀

@norhh norhh merged commit 39b79ca into Consensys:develop Jul 12, 2023
@abhinandanudupa abhinandanudupa deleted the parse-version branch July 12, 2023 11:00
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

Successfully merging this pull request may close these issues.

3 participants