diff --git a/mythril/ethereum/util.py b/mythril/ethereum/util.py index 090bdb4e..7b25246e 100644 --- a/mythril/ethereum/util.py +++ b/mythril/ethereum/util.py @@ -44,8 +44,11 @@ def get_solc_json(file, solc_binary="solc", solc_settings_json=None): :param solc_settings_json: :return: """ + if args.solc_args is None: + cmd = [solc_binary, "--standard-json", "--allow-paths", ".,/"] + else: + cmd = [solc_binary, "--standard-json"] + args.solc_args.split() - cmd = [solc_binary, "--standard-json", "--allow-paths", ".,/"] settings = {} if solc_settings_json: with open(solc_settings_json) as f: diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index ad2109d4..61369176 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -202,6 +202,11 @@ def get_utilities_parser() -> ArgumentParser: "--solc-json", help="Json for the optional 'settings' parameter of solc's standard-json input", ) + parser.add_argument( + "--solc-args", + help="""Provide solc args, example: --solc-args "--allow-paths --include-path /root_folder/node_modules --base-path /home/contracts" """, + type=str, + ) parser.add_argument( "--solv", help="specify solidity compiler version. If not present, will try to install it (Experimental)", @@ -921,11 +926,13 @@ def parse_args_and_execute(parser: ArgumentParser, args: Namespace) -> None: query_signature = args.__dict__.get("query_signature", None) solc_json = args.__dict__.get("solc_json", None) solv = args.__dict__.get("solv", None) + solc_args = args.__dict__.get("solc_args", None) disassembler = MythrilDisassembler( eth=config.eth, solc_version=solv, solc_settings_json=solc_json, enable_online_lookup=query_signature, + solc_args=solc_args, ) address = load_code(disassembler, args) diff --git a/mythril/mythril/mythril_disassembler.py b/mythril/mythril/mythril_disassembler.py index b0bb23cf..0ffc3bb2 100644 --- a/mythril/mythril/mythril_disassembler.py +++ b/mythril/mythril/mythril_disassembler.py @@ -17,8 +17,9 @@ from mythril.support.support_args import args from mythril.ethereum.evmcontract import EVMContract from mythril.ethereum.interface.rpc.exceptions import ConnectionError from mythril.solidity.soliditycontract import SolidityContract, get_contracts_from_file -from eth_utils import int_to_big_endian +from mythril.support.support_args import args +from eth_utils import int_to_big_endian log = logging.getLogger(__name__) @@ -37,7 +38,9 @@ class MythrilDisassembler: solc_version: str = None, solc_settings_json: str = None, enable_online_lookup: bool = False, + solc_args=None, ) -> None: + args.solc_args = solc_args self.solc_binary = self._init_solc_binary(solc_version) self.solc_settings_json = solc_settings_json self.eth = eth diff --git a/mythril/support/support_args.py b/mythril/support/support_args.py index 10f20288..aaeac933 100644 --- a/mythril/support/support_args.py +++ b/mythril/support/support_args.py @@ -19,6 +19,7 @@ class Args(object, metaclass=Singleton): self.transaction_sequences: List[List[str]] = None self.use_integer_module = True self.use_issue_annotations = False + self.solc_args = None args = Args() diff --git a/tests/integration_tests/test_solc_settings.py b/tests/integration_tests/test_solc_settings.py index f54644d9..0478290a 100644 --- a/tests/integration_tests/test_solc_settings.py +++ b/tests/integration_tests/test_solc_settings.py @@ -18,6 +18,17 @@ def test_positive_solc_settings(): assert "The analysis was completed successfully" in output +def test_positive_solc_args(): + base_path = str(TESTDATA) + file_dir = str(TESTDATA / "json_test_dir" / "dir_a") + json_file_path = str(TESTDATA / "json_test_dir" / "test_file.json") + file_path = file_dir + "/input_file_args.sol" + + command = f"""cd {file_dir} && python3 {MYTH} analyze {file_path} --solc-args "--allow-paths {base_path}" --solv 0.8.0""" + output = check_output(command, shell=True, stderr=STDOUT).decode("UTF-8") + 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") diff --git a/tests/testdata/json_test_dir/dir_a/input_file_args.sol b/tests/testdata/json_test_dir/dir_a/input_file_args.sol new file mode 100644 index 00000000..cdfe3e0f --- /dev/null +++ b/tests/testdata/json_test_dir/dir_a/input_file_args.sol @@ -0,0 +1,13 @@ +import "../PRC20.sol"; + +contract Nothing is PRC20{ + + + + function nothing(string memory g_0, bytes3 g_11) public view returns (bool){ + + return true; + + } +} +