diff --git a/mythril/ethereum/util.py b/mythril/ethereum/util.py index 95987702..08d6927f 100644 --- a/mythril/ethereum/util.py +++ b/mythril/ethereum/util.py @@ -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"], diff --git a/tests/integration_tests/test_solc_settings.py b/tests/integration_tests/test_solc_settings.py index c08bad9c..f54644d9 100644 --- a/tests/integration_tests/test_solc_settings.py +++ b/tests/integration_tests/test_solc_settings.py @@ -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") diff --git a/tests/testdata/json_test_dir/dir_a/input_file.sol b/tests/testdata/json_test_dir/dir_a/input_file.sol index 57b409d6..f4b5d296 100644 --- a/tests/testdata/json_test_dir/dir_a/input_file.sol +++ b/tests/testdata/json_test_dir/dir_a/input_file.sol @@ -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; + } } diff --git a/tests/testdata/json_test_dir/test_file_disable.json b/tests/testdata/json_test_dir/test_file_disable.json new file mode 100644 index 00000000..323f7598 --- /dev/null +++ b/tests/testdata/json_test_dir/test_file_disable.json @@ -0,0 +1,4 @@ +{ + "remappings": [ "@openzeppelin/contracts/token/PRC20/=../" ] +} + \ No newline at end of file