Support solc-args (#1698)

pull/1700/head
Nikhil Parasaram 2 years ago committed by GitHub
parent 19f6a8b120
commit 185f2d6cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      mythril/ethereum/util.py
  2. 7
      mythril/interfaces/cli.py
  3. 5
      mythril/mythril/mythril_disassembler.py
  4. 1
      mythril/support/support_args.py
  5. 11
      tests/integration_tests/test_solc_settings.py
  6. 13
      tests/testdata/json_test_dir/dir_a/input_file_args.sol

@ -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:

@ -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)

@ -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

@ -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()

@ -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")

@ -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;
}
}
Loading…
Cancel
Save