Skip to content

Commit

Permalink
Fixes optimizer issue (Consensys#1597)
Browse files Browse the repository at this point in the history
* Init config dir

* Fix solc optimizer
  • Loading branch information
norhh authored Mar 5, 2022
1 parent 8f1b8cd commit c88a5ed
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mythril/ethereum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def get_solc_json(file, solc_binary="solc", solc_settings_json=None):
if solc_settings_json:
with open(solc_settings_json) as f:
settings = json.load(f)
if "optimizer" not in settings:
settings.update({"optimizer": {"enabled": False}})

settings.update(
{
"optimizer": {"enabled": False},
"outputSelection": {
"*": {
"": ["ast"],
Expand Down
10 changes: 10 additions & 0 deletions tests/integration_tests/test_solc_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def test_positive_solc_settings():
assert "The analysis was completed successfully" in output


def test_neg_optimizer_solc_settings():
file_dir = str(TESTDATA / "json_test_dir" / "dir_a")
json_file_path = str(TESTDATA / "json_test_dir" / "test_file_disable.json")
file_path = file_dir + "/input_file.sol"

command = f"cd {file_dir} && python3 {MYTH} analyze {file_path} --solc-json {json_file_path} --solv 0.8.0"
output = check_output(command, shell=True, stderr=STDOUT).decode("UTF-8")
assert "Stack too deep when compiling inline assembly" in output


def test_negative_solc_settings():
file_path = str(TESTDATA / "json_test_dir" / "dir_a" / "input_file.sol")

Expand Down
55 changes: 54 additions & 1 deletion tests/testdata/json_test_dir/dir_a/input_file.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
import "@openzeppelin/contracts/token/PRC20/PRC20.sol";

contract Nothing is PRC20{
function nothing() public pure{
string x_0 = "";

bytes3 x_1 = "A";

bytes5 x_2 = "E";

bytes5 x_3 = "";

bytes3 x_4 = "I";

bytes3 x_5 = "U";

bytes3 x_6 = "O";

bytes3 x_7 = "0";

bytes3 x_8 = "U";

bytes3 x_9 = "U";
function stringCompare(string memory a, string memory b) internal pure returns (bool) {
if(bytes(a).length != bytes(b).length) {
return false;
} else {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}

function nothing(string memory g_0, bytes3 g_1, bytes5 g_2, bytes5 g_3, bytes3 g_4, bytes3 g_5, bytes3 g_6, bytes3 g_7, bytes3 g_8, bytes3 g_9, bytes3 g_10, bytes3 g_11) public view returns (bool){
if (!stringCompare(g_0, x_0)) return false;

if (g_1 != x_1) return false;

if (g_2 != x_2) return false;

if (g_3 != x_3) return false;

if (g_4 != x_4) return false;

if (g_5 != x_5) return false;

if (g_6 != x_6) return false;

if (g_7 != x_7) return false;

if (g_8 != x_8) return false;

if (g_9 != x_9) return false;

if (g_10 != x_9) return false;

if (g_11 != x_9) return false;

return true;

}
}

4 changes: 4 additions & 0 deletions tests/testdata/json_test_dir/test_file_disable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"remappings": [ "@openzeppelin/contracts/token/PRC20/=../" ]
}

0 comments on commit c88a5ed

Please sign in to comment.