Handle edge case when parsing (#1826)

* Change configuration

* Downgrade solcx

* Handle edge case when parsing
pull/1828/head
Nikhil Parasaram 11 months ago committed by GitHub
parent 460e9da50c
commit 2bf6a35327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mythril/ethereum/util.py
  2. 1
      tests/util_tests.py

@ -156,7 +156,7 @@ def parse_pragma(solidity_code):
max_version = Optional(inequality + version) max_version = Optional(inequality + version)
pragma = Word("pragma") + Word("solidity") + min_version + Optional(max_version) pragma = Word("pragma") + Word("solidity") + min_version + Optional(max_version)
result = pragma.parseString(solidity_code) result = pragma.parseString(solidity_code)
min_inequality = result[2] if result[2] in [">", "<", ">=", "<="] else "" min_inequality = result[2] if result[2] in [">", "<", ">=", "<=", "="] else ""
min_carrot = result[2] if result[2] == "^" else "" min_carrot = result[2] if result[2] == "^" else ""
min_version = result[3] if min_carrot != "" or min_inequality != "" else result[2] min_version = result[3] if min_carrot != "" or min_inequality != "" else result[2]
return { return {

@ -5,6 +5,7 @@ from mythril.ethereum.util import extract_version
test_data = ( test_data = (
("pragma solidity 0.5.0\n", ["0.5.0"]), ("pragma solidity 0.5.0\n", ["0.5.0"]),
("pragma solidity =0.5.0\n", ["0.5.0"]),
("pragma solidity ^0.4.26\n", ["0.4.26"]), ("pragma solidity ^0.4.26\n", ["0.4.26"]),
("pragma solidity ^0.6.3;\n", [f"0.6.{x}" for x in range(3, 13)]), ("pragma solidity ^0.6.3;\n", [f"0.6.{x}" for x in range(3, 13)]),
("pragma solidity ^0.6.3 ;\n", [f"0.6.{x}" for x in range(3, 13)]), ("pragma solidity ^0.6.3 ;\n", [f"0.6.{x}" for x in range(3, 13)]),

Loading…
Cancel
Save