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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mythril/ethereum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def parse_pragma(solidity_code):
gtr = Word(">")
eq = 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(
eq | (Combine(gtr + Optional(eq)) | Combine(lt + Optional(eq)))
)
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
("version_chaos.sol", None, True),
("version_2.sol", None, True),
("version_3.sol", None, True),
("version_patch.sol", None, False),
)


Expand Down
21 changes: 21 additions & 0 deletions tests/testdata/input_contracts/version_patch.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}