Fix parsing of compiler version and reformat file (#1787)

* Fix parsing of compiler version (patch version)

* Add test to check version-patch fix
pull/1789/head
Abhinandan Udupa 1 year ago committed by GitHub
parent 2a37d2801a
commit 39b79cae8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mythril/ethereum/util.py
  2. 1
      tests/integration_tests/version_test.py
  3. 21
      tests/testdata/input_contracts/version_patch.sol

@ -148,7 +148,7 @@ def parse_pragma(solidity_code):
gtr = Word(">") gtr = Word(">")
eq = Word("=") eq = Word("=")
carrot = Word("^") carrot = Word("^")
version = Regex(r"\s*[0-9]+\s*\.\s*[0-9]+\s*\.\s*[0-9]+") version = Regex(r"\s*[0-9]+\s*\.\s*[0-9]+\s*(\.\s*[0-9]+)?")
inequality = Optional( inequality = Optional(
eq | (Combine(gtr + Optional(eq)) | Combine(lt + Optional(eq))) eq | (Combine(gtr + Optional(eq)) | Combine(lt + Optional(eq)))
) )

@ -14,6 +14,7 @@ test_data = (
("version_chaos.sol", None, True), ("version_chaos.sol", None, True),
("version_2.sol", None, True), ("version_2.sol", None, True),
("version_3.sol", None, True), ("version_3.sol", None, True),
("version_patch.sol", None, False),
) )

@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8; // Patch version - X.y[.z] is missing
contract EtherWallet {
address payable public owner;
constructor() {
owner = payable(msg.sender);
}
receive() external payable {}
function withdraw(uint256 _amount) external {
require(msg.sender == owner, "caller is not owner");
payable(msg.sender).transfer(_amount);
}
function getBalance() external view returns (uint256) {
return address(this).balance;
}
}
Loading…
Cancel
Save