def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description="Demo", usage="slither-demo filename", formatter_class=argparse.RawDescriptionHelpFormatter, ) parser.add_argument( "filename", help="The filename of the contract or truffle directory to analyze.") parser.add_argument("--contract", help="The targeted contract.") parser.add_argument( "--scenario", help= f"Test a specific scenario. Use --list-scenarios to see the available scenarios. Default Transferable", default="Transferable", ) parser.add_argument( "--list-scenarios", help="List available scenarios", action=ListScenarios, nargs=0, default=False, ) parser.add_argument( "--list-properties", help="List available properties", action=ListProperties, nargs=0, default=False, ) parser.add_argument("--address-owner", help=f"Owner address. Default {OWNER_ADDRESS}", default=None) parser.add_argument("--address-user", help=f"Owner address. Default {USER_ADDRESS}", default=None) parser.add_argument("--address-attacker", help=f"Attacker address. Default {ATTACKER_ADDRESS}", default=None) # Add default arguments from crytic-compile cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description='slither-kspec-coverage', usage='slither-kspec-coverage contract.sol kspec.md') parser.add_argument( 'contract', help='The filename of the contract or truffle directory to analyze.') parser.add_argument( 'kspec', help= 'The filename of the Klab spec markdown for the analyzed contract(s)') parser.add_argument('--version', help='displays the current version', version='0.1.0', action='version') parser.add_argument( '--json', help= 'Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=False) cryticparser.init(parser) if len(sys.argv) < 2: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser( description= "Experimental smart contract mutator. Based on https://arxiv.org/abs/2006.11597", usage="slither-mutate target", ) parser.add_argument( "codebase", help="Codebase to analyze (.sol file, truffle directory, ...)") parser.add_argument( "--list-mutators", help="List available detectors", action=ListMutators, nargs=0, default=False, ) # Initiate all the crytic config cli options cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser( description= 'Slither Upgradeability Checks. For usage information see https://github.com/crytic/slither/wiki/Upgradeability-Checks.', usage="slither-check-upgradeability contract.sol ContractName") parser.add_argument('contract.sol', help='Codebase to analyze') parser.add_argument('ContractName', help='Contract name (logic contract)') parser.add_argument('--proxy-name', help='Proxy name') parser.add_argument('--proxy-filename', help='Proxy filename (if different)') parser.add_argument('--new-contract-name', help='New contract name (if changed)') parser.add_argument('--new-contract-filename', help='New implementation filename (if different)') parser.add_argument( '--json', help= 'Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=False) cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description='Contracts flattening', usage='slither-flat filename') parser.add_argument( 'filename', help='The filename of the contract or project to analyze.') parser.add_argument('--convert-external', help='Convert external to public.', action='store_true') parser.add_argument('--convert-private', help='Convert private variables to internal.', action='store_true') parser.add_argument('--remove-assert', help='Remove call to assert().', action='store_true') parser.add_argument( '--contract', help= 'Flatten a specific contract (default: all most derived contracts).', default=None) # Add default arguments from crytic-compile cryticparser.init(parser) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser( description= "Code similarity detection tool. For usage, see https://github.com/crytic/slither/wiki/Code-Similarity-detector" ) parser.add_argument("mode", help="|".join(modes)) parser.add_argument("model", help="model.bin") parser.add_argument("--filename", action="store", dest="filename", help="contract.sol") parser.add_argument("--fname", action="store", dest="fname", help="Target function") parser.add_argument("--ext", action="store", dest="ext", help="Extension to filter contracts") parser.add_argument( "--nsamples", action="store", type=int, dest="nsamples", help="Number of contract samples used for training", ) parser.add_argument( "--ntop", action="store", type=int, dest="ntop", default=10, help="Number of more similar contracts to show for testing", ) parser.add_argument("--input", action="store", dest="input", help="File or directory used as input") parser.add_argument("--version", help="displays the current version", version="0.0", action="version") cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() return args
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( description="evm-cfg-builder", usage="evm-cfg-builder contract.evm [flag]") parser.add_argument("filename", help="contract.evm") parser.add_argument( "--export-dot", help="Export the functions to .dot files in the directory", action="store", dest="dot_directory", default="crytic-export/evm", ) parser.add_argument( "--disable-optimizations", help="Disable the CFG recovery optimizations", action="store_true", dest="disable_optimizations", default=False, ) parser.add_argument( "--disable-cfg", help="Disable the CFG recovery", action="store_true", dest="disable_cfg", default=False, ) parser.add_argument( "--export-abi", help="Export the contract's ABI", action="store", dest="export_abi", default=None, ) parser.add_argument( "--version", help="displays the current version", version=require("evm-cfg-builder")[0].version, action="version", ) parser.add_argument( "--perf", help=argparse.SUPPRESS, action="store_true", default=False, ) cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() return args
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description="Check the ERC 20 conformance", usage="slither-check-erc project contractName", ) parser.add_argument("project", help="The codebase to be tested.") parser.add_argument( "contract_name", help="The name of the contract. Specify the first case contract that follow the standard. Derived contracts will be checked.", ) parser.add_argument( "--erc", help=f"ERC to be tested, available {','.join(ERCS.keys())} (default ERC20)", action="store", default="erc20", ) parser.add_argument( "--json", help='Export the results as a JSON file ("--json -" to export to stdout)', action="store", default=False, ) # Add default arguments from crytic-compile cryticparser.init(parser) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description="fortress-kspec-coverage", usage="fortress-kspec-coverage contract.sol kspec.md", ) parser.add_argument( "contract", help="The filename of the contract or truffle directory to analyze." ) parser.add_argument( "kspec", help="The filename of the Klab spec markdown for the analyzed contract(s)", ) parser.add_argument( "--version", help="displays the current version", version="0.1.0", action="version", ) parser.add_argument( "--json", help='Export the results as a JSON file ("--json -" to export to stdout)', action="store", default=False, ) cryticparser.init(parser) if len(sys.argv) < 2: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser( description= 'Slither Upgradeability Checks. For usage information see https://github.com/crytic/slither/wiki/Upgradeability-Checks.', usage="slither-check-upgradeability contract.sol ContractName") parser.add_argument('contract.sol', help='Codebase to analyze') parser.add_argument('ContractName', help='Contract name (logic contract)') parser.add_argument('--proxy-name', help='Proxy name') parser.add_argument('--proxy-filename', help='Proxy filename (if different)') parser.add_argument('--new-contract-name', help='New contract name (if changed)') parser.add_argument('--new-contract-filename', help='New implementation filename (if different)') parser.add_argument( '--json', help= 'Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=False) parser.add_argument('--list-detectors', help='List available detectors', action=ListDetectors, nargs=0, default=False) parser.add_argument('--markdown-root', help='URL for markdown generation', action='store', default="") parser.add_argument('--wiki-detectors', help=argparse.SUPPRESS, action=OutputWiki, default=False) parser.add_argument('--list-detectors-json', help=argparse.SUPPRESS, action=ListDetectorsJson, nargs=0, default=False) parser.add_argument('--markdown', help=argparse.SUPPRESS, action=OutputMarkdown, default=False) cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser( description= 'Code similarity detection tool. For usage, see https://github.com/crytic/slither/wiki/Code-Similarity-detector' ) parser.add_argument('mode', help="|".join(modes)) parser.add_argument('model', help='model.bin') parser.add_argument('--filename', action='store', dest='filename', help='contract.sol') parser.add_argument('--fname', action='store', dest='fname', help='Target function') parser.add_argument('--ext', action='store', dest='ext', help='Extension to filter contracts') parser.add_argument('--nsamples', action='store', type=int, dest='nsamples', help='Number of contract samples used for training') parser.add_argument( '--ntop', action='store', type=int, dest='ntop', default=10, help='Number of more similar contracts to show for testing') parser.add_argument('--input', action='store', dest='input', help='File or directory used as input') parser.add_argument('--version', help='displays the current version', version="0.0", action='version') cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() return args
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description='Demo', usage='slither-demo filename') parser.add_argument('filename', help='The filename of the contract or truffle directory to analyze.') # Add default arguments from crytic-compile cryticparser.init(parser) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description="Demo", usage="fortress-demo filename") parser.add_argument( "filename", help="The filename of the contract or truffle directory to analyze." ) # Add default arguments from crytic-compile cryticparser.init(parser) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description='PossiblePaths', usage='possible_paths.py filename [contract.function targets]') parser.add_argument('filename', help='The filename of the contract or truffle directory to analyze.') parser.add_argument('targets', nargs='+') cryticparser.init(parser) return parser.parse_args()
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description='slither_format', usage='slither_format filename') parser.add_argument('filename', help='The filename of the contract or truffle directory to analyze.') parser.add_argument('--verbose-test', '-v', help='verbose mode output for testing',action='store_true',default=False) parser.add_argument('--verbose-json', '-j', help='verbose json output',action='store_true',default=False) parser.add_argument('--version', help='displays the current version', version='0.1.0', action='version') parser.add_argument('--config-file', help='Provide a config file (default: slither.config.json)', action='store', dest='config_file', default='slither.config.json') group_detector = parser.add_argument_group('Detectors') group_detector.add_argument('--detect', help='Comma-separated list of detectors, defaults to all, ' 'available detectors: {}'.format( ', '.join(d for d in available_detectors)), action='store', dest='detectors_to_run', default='all') group_detector.add_argument('--exclude', help='Comma-separated list of detectors to exclude,' 'available detectors: {}'.format( ', '.join(d for d in available_detectors)), action='store', dest='detectors_to_exclude', default='all') cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser(description='evm-cfg-builder', usage="evm-cfg-builder contract.evm [flag]") parser.add_argument('filename', help='contract.evm') parser.add_argument('--export-dot', help='Export the functions to .dot files in the directory', action='store', dest='dot_directory', default='crytic-export/evm') parser.add_argument('--disable-optimizations', help='Disable the CFG recovery optimizations', action='store_true', dest='disable_optimizations', default=False) parser.add_argument('--disable-cfg', help='Disable the CFG recovery', action='store_true', dest='disable_cfg', default=False) parser.add_argument('--export-abi', help="Export the contract's ABI", action='store', dest='export_abi', default=None) parser.add_argument('--version', help='displays the current version', version=require('evm-cfg-builder')[0].version, action='version') parser.add_argument( "--perf", help=argparse.SUPPRESS, action="store_true", default=False, ) cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() return args
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description="PossiblePaths", usage="possible_paths.py filename [contract.function targets]" ) parser.add_argument( "filename", help="The filename of the contract or truffle directory to analyze." ) parser.add_argument("targets", nargs="+") cryticparser.init(parser) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser(description='Slither Upgradeability Checks. For usage information see https://github.com/crytic/slither/wiki/Upgradeability-Checks.', usage="slither-check-upgradeability proxy.sol ProxyName implem.sol ContractName") parser.add_argument('proxy.sol', help='Proxy filename') parser.add_argument('ProxyName', help='Contract name') parser.add_argument('implem.sol', help='Implementation filename') parser.add_argument('ContractName', help='Contract name') parser.add_argument('--new-version', help='New implementation filename') parser.add_argument('--new-contract-name', help='New contract name (if changed)') cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(detector_classes, printer_classes): parser = argparse.ArgumentParser( description= 'Slither. For usage information, see https://github.com/crytic/slither/wiki/Usage', usage="slither.py contract.sol [flag]") parser.add_argument('filename', help='contract.sol') cryticparser.init(parser) parser.add_argument('--version', help='displays the current version', version=require('slither-analyzer')[0].version, action='version') group_detector = parser.add_argument_group('Detectors') group_printer = parser.add_argument_group('Printers') group_misc = parser.add_argument_group('Additional option') group_detector.add_argument( '--detect', help='Comma-separated list of detectors, defaults to all, ' 'available detectors: {}'.format(', '.join(d.ARGUMENT for d in detector_classes)), action='store', dest='detectors_to_run', default=defaults_flag_in_config['detectors_to_run']) group_printer.add_argument( '--print', help='Comma-separated list fo contract information printers, ' 'available printers: {}'.format(', '.join(d.ARGUMENT for d in printer_classes)), action='store', dest='printers_to_run', default=defaults_flag_in_config['printers_to_run']) group_detector.add_argument('--list-detectors', help='List available detectors', action=ListDetectors, nargs=0, default=False) group_printer.add_argument('--list-printers', help='List available printers', action=ListPrinters, nargs=0, default=False) group_detector.add_argument( '--exclude', help='Comma-separated list of detectors that should be excluded', action='store', dest='detectors_to_exclude', default=defaults_flag_in_config['detectors_to_exclude']) group_detector.add_argument( '--exclude-informational', help='Exclude informational impact analyses', action='store_true', default=defaults_flag_in_config['exclude_informational']) group_detector.add_argument('--exclude-low', help='Exclude low impact analyses', action='store_true', default=defaults_flag_in_config['exclude_low']) group_detector.add_argument( '--exclude-medium', help='Exclude medium impact analyses', action='store_true', default=defaults_flag_in_config['exclude_medium']) group_detector.add_argument( '--exclude-high', help='Exclude high impact analyses', action='store_true', default=defaults_flag_in_config['exclude_high']) group_misc.add_argument( '--json', help= 'Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=defaults_flag_in_config['json']) group_misc.add_argument('--disable-color', help='Disable output colorization', action='store_true', default=defaults_flag_in_config['disable_color']) group_misc.add_argument( '--filter-paths', help='Comma-separated list of paths for which results will be excluded', action='store', dest='filter_paths', default=defaults_flag_in_config['filter_paths']) group_misc.add_argument( '--triage-mode', help='Run triage mode (save results in slither.db.json)', action='store_true', dest='triage_mode', default=False) group_misc.add_argument( '--config-file', help='Provide a config file (default: slither.config.json)', action='store', dest='config_file', default='slither.config.json') group_misc.add_argument('--solc-ast', help='Provide the contract as a json AST', action='store_true', default=False) # debugger command parser.add_argument('--debug', help=argparse.SUPPRESS, action="store_true", default=False) parser.add_argument('--markdown', help=argparse.SUPPRESS, action=OutputMarkdown, default=False) group_misc.add_argument('--checklist', help=argparse.SUPPRESS, action='store_true', default=False) parser.add_argument('--wiki-detectors', help=argparse.SUPPRESS, action=OutputWiki, default=False) parser.add_argument('--list-detectors-json', help=argparse.SUPPRESS, action=ListDetectorsJson, nargs=0, default=False) parser.add_argument('--legacy-ast', help=argparse.SUPPRESS, action='store_true', default=defaults_flag_in_config['legacy_ast']) parser.add_argument('--ignore-return-value', help=argparse.SUPPRESS, action='store_true', default=defaults_flag_in_config['ignore_return_value']) # if the json is splitted in different files parser.add_argument('--splitted', help=argparse.SUPPRESS, action='store_true', default=False) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() if os.path.isfile(args.config_file): try: with open(args.config_file) as f: config = json.load(f) for key, elem in config.items(): if key not in defaults_flag_in_config: logger.info( yellow('{} has an unknown key: {} : {}'.format( args.config_file, key, elem))) continue if getattr(args, key) == defaults_flag_in_config[key]: setattr(args, key, elem) except json.decoder.JSONDecodeError as e: logger.error( red('Impossible to read {}, please check the file {}'.format( args.config_file, e))) return args
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser( description= "Contracts flattening. See https://github.com/crytic/slither/wiki/Contract-Flattening", usage="slither-flat filename", ) parser.add_argument( "filename", help="The filename of the contract or project to analyze.") parser.add_argument("--contract", help="Flatten one contract.", default=None) parser.add_argument( "--strategy", help=f"Flatenning strategy: {STRATEGIES_NAMES} (default: MostDerived).", default=Strategy.MostDerived.name, ) group_export = parser.add_argument_group("Export options") group_export.add_argument( "--dir", help=f"Export directory (default: {DEFAULT_EXPORT_PATH}).", default=None) group_export.add_argument( "--json", help= 'Export the results as a JSON file ("--json -" to export to stdout)', action="store", default=None, ) parser.add_argument( "--zip", help="Export all the files to a zip file", action="store", default=None, ) parser.add_argument( "--zip-type", help= f"Zip compression type. One of {','.join(ZIP_TYPES_ACCEPTED.keys())}. Default lzma", action="store", default=None, ) group_patching = parser.add_argument_group("Patching options") group_patching.add_argument("--convert-external", help="Convert external to public.", action="store_true") group_patching.add_argument("--convert-private", help="Convert private variables to internal.", action="store_true") group_patching.add_argument("--remove-assert", help="Remove call to assert().", action="store_true") # Add default arguments from crytic-compile cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args(detector_classes, printer_classes): parser = argparse.ArgumentParser( description='Slither. For usage information, see https://github.com/crytic/slither/wiki/Usage', usage="slither.py contract.sol [flag]") parser.add_argument('filename', help='contract.sol') cryticparser.init(parser) parser.add_argument('--version', help='displays the current version', version=require('slither-analyzer')[0].version, action='version') group_detector = parser.add_argument_group('Detectors') group_printer = parser.add_argument_group('Printers') group_misc = parser.add_argument_group('Additional options') group_detector.add_argument('--detect', help='Comma-separated list of detectors, defaults to all, ' 'available detectors: {}'.format( ', '.join(d.ARGUMENT for d in detector_classes)), action='store', dest='detectors_to_run', default=defaults_flag_in_config['detectors_to_run']) group_printer.add_argument('--print', help='Comma-separated list fo contract information printers, ' 'available printers: {}'.format( ', '.join(d.ARGUMENT for d in printer_classes)), action='store', dest='printers_to_run', default=defaults_flag_in_config['printers_to_run']) group_detector.add_argument('--list-detectors', help='List available detectors', action=ListDetectors, nargs=0, default=False) group_printer.add_argument('--list-printers', help='List available printers', action=ListPrinters, nargs=0, default=False) group_detector.add_argument('--exclude', help='Comma-separated list of detectors that should be excluded', action='store', dest='detectors_to_exclude', default=defaults_flag_in_config['detectors_to_exclude']) group_detector.add_argument('--exclude-dependencies', help='Exclude results that are only related to dependencies', action='store_true', default=defaults_flag_in_config['exclude_dependencies']) group_detector.add_argument('--exclude-optimization', help='Exclude optimization analyses', action='store_true', default=defaults_flag_in_config['exclude_optimization']) group_detector.add_argument('--exclude-informational', help='Exclude informational impact analyses', action='store_true', default=defaults_flag_in_config['exclude_informational']) group_detector.add_argument('--exclude-low', help='Exclude low impact analyses', action='store_true', default=defaults_flag_in_config['exclude_low']) group_detector.add_argument('--exclude-medium', help='Exclude medium impact analyses', action='store_true', default=defaults_flag_in_config['exclude_medium']) group_detector.add_argument('--exclude-high', help='Exclude high impact analyses', action='store_true', default=defaults_flag_in_config['exclude_high']) group_misc.add_argument('--json', help='Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=defaults_flag_in_config['json']) group_misc.add_argument('--json-types', help=f'Comma-separated list of result types to output to JSON, defaults to ' + \ f'{",".join(output_type for output_type in DEFAULT_JSON_OUTPUT_TYPES)}. ' + \ f'Available types: {",".join(output_type for output_type in JSON_OUTPUT_TYPES)}', action='store', default=defaults_flag_in_config['json-types']) group_misc.add_argument('--zip', help='Export the results as a zipped JSON file', action='store', default=defaults_flag_in_config['zip']) group_misc.add_argument('--zip-type', help=f'Zip compression type. One of {",".join(ZIP_TYPES_ACCEPTED.keys())}. Default lzma', action='store', default=defaults_flag_in_config['zip_type']) group_misc.add_argument('--markdown-root', help='URL for markdown generation', action='store', default="") group_misc.add_argument('--disable-color', help='Disable output colorization', action='store_true', default=defaults_flag_in_config['disable_color']) group_misc.add_argument('--filter-paths', help='Comma-separated list of paths for which results will be excluded', action='store', dest='filter_paths', default=defaults_flag_in_config['filter_paths']) group_misc.add_argument('--triage-mode', help='Run triage mode (save results in slither.db.json)', action='store_true', dest='triage_mode', default=False) group_misc.add_argument('--config-file', help='Provide a config file (default: slither.config.json)', action='store', dest='config_file', default='slither.config.json') group_misc.add_argument('--solc-ast', help='Provide the contract as a json AST', action='store_true', default=False) group_misc.add_argument('--generate-patches', help='Generate patches (json output only)', action='store_true', default=False) # debugger command parser.add_argument('--debug', help=argparse.SUPPRESS, action="store_true", default=False) parser.add_argument('--markdown', help=argparse.SUPPRESS, action=OutputMarkdown, default=False) group_misc.add_argument('--checklist', help=argparse.SUPPRESS, action='store_true', default=False) parser.add_argument('--wiki-detectors', help=argparse.SUPPRESS, action=OutputWiki, default=False) parser.add_argument('--list-detectors-json', help=argparse.SUPPRESS, action=ListDetectorsJson, nargs=0, default=False) parser.add_argument('--legacy-ast', help=argparse.SUPPRESS, action='store_true', default=defaults_flag_in_config['legacy_ast']) parser.add_argument('--ignore-return-value', help=argparse.SUPPRESS, action='store_true', default=defaults_flag_in_config['ignore_return_value']) # if the json is splitted in different files parser.add_argument('--splitted', help=argparse.SUPPRESS, action='store_true', default=False) # Disable the throw/catch on partial analyses parser.add_argument('--disallow-partial', help=argparse.SUPPRESS, action="store_true", default=False) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() read_config_file(args) args.filter_paths = parse_filter_paths(args) # Verify our json-type output is valid args.json_types = set(args.json_types.split(',')) for json_type in args.json_types: if json_type not in JSON_OUTPUT_TYPES: raise Exception(f"Error: \"{json_type}\" is not a valid JSON result output type.") return args
def parse_arguments() -> argparse.Namespace: def positive(value): ivalue = int(value) if ivalue <= 0: raise argparse.ArgumentTypeError("Argument must be positive") return ivalue parser = argparse.ArgumentParser( description="Symbolic execution tool", prog="manticore", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) # Add crytic compile arguments # See https://github.com/crytic/crytic-compile/wiki/Configuration cryticparser.init(parser) parser.add_argument("--context", type=str, default=None, help=argparse.SUPPRESS) parser.add_argument( "--coverage", type=str, default="visited.txt", help="Where to write the coverage data" ) parser.add_argument("--names", type=str, default=None, help=argparse.SUPPRESS) parser.add_argument( "--no-colors", action="store_true", help="Disable ANSI color escape sequences in output" ) parser.add_argument("--offset", type=int, default=16, help=argparse.SUPPRESS) # FIXME (theo) Add some documentation on the different search policy options parser.add_argument( "--policy", type=str, default="random", help=( "Search policy. random|adhoc|uncovered|dicount" "|icount|syscount|depth. (use + (max) or - (min)" " to specify order. e.g. +random)" ), ) parser.add_argument( "argv", type=str, nargs="*", default=[], help="Path to program, and arguments ('+' in arguments indicates symbolic byte).", ) parser.add_argument( "-v", action="count", default=1, help="Specify verbosity level from -v to -vvvv" ) parser.add_argument( "--workspace", type=str, default=None, help=("A folder name for temporaries and results." "(default mcore_?????)"), ) current_version = pkg_resources.get_distribution("manticore").version parser.add_argument( "--version", action="version", version=f"Manticore {current_version}", help="Show program version information", ) parser.add_argument( "--config", type=str, help="Manticore config file (.yml) to use. (default config file pattern is: ./[.]m[anti]core.yml)", ) bin_flags = parser.add_argument_group("Binary flags") bin_flags.add_argument("--entrysymbol", type=str, default=None, help="Symbol as entry point") bin_flags.add_argument("--assertions", type=str, default=None, help=argparse.SUPPRESS) bin_flags.add_argument("--buffer", type=str, help=argparse.SUPPRESS) bin_flags.add_argument( "--data", type=str, default="", help="Initial concrete concrete_data for the input symbolic buffer", ) bin_flags.add_argument( "--file", type=str, default=[], action="append", dest="files", help="Specify symbolic input file, '+' marks symbolic bytes", ) bin_flags.add_argument( "--env", type=str, nargs=1, default=[], action="append", help='Add an environment variable. Use "+" for symbolic bytes. (VARNAME=++++)', ) bin_flags.add_argument( "--pure-symbolic", action="store_true", help="Treat all writable memory as symbolic" ) eth_flags = parser.add_argument_group("Ethereum flags") eth_flags.add_argument( "--verbose-trace", action="store_true", help="Dump an extra verbose trace for each state" ) eth_flags.add_argument( "--txlimit", type=positive, help="Maximum number of symbolic transactions to run (positive integer)", ) eth_flags.add_argument( "--txnocoverage", action="store_true", help="Do not use coverage as stopping criteria" ) eth_flags.add_argument( "--txnoether", action="store_true", help="Do not attempt to send ether to contract" ) eth_flags.add_argument( "--txaccount", type=str, default="attacker", help='Account used as caller in the symbolic transactions, either "attacker" or ' '"owner" or "combo1" (uses both)', ) eth_flags.add_argument( "--txpreconstrain", action="store_true", help="Constrain human transactions to avoid exceptions in the contract function dispatcher", ) eth_flags.add_argument( "--contract", type=str, help="Contract name to analyze in case of multiple contracts" ) eth_detectors = parser.add_argument_group("Ethereum detectors") eth_detectors.add_argument( "--list-detectors", help="List available detectors", action=ListEthereumDetectors, nargs=0, default=False, ) eth_detectors.add_argument( "--exclude", help="Comma-separated list of detectors that should be excluded", action="store", dest="detectors_to_exclude", default="", ) eth_detectors.add_argument( "--exclude-all", help="Excludes all detectors", action="store_true", default=False ) eth_flags.add_argument( "--avoid-constant", action="store_true", help="Avoid exploring constant functions for human transactions", ) eth_flags.add_argument( "--limit-loops", action="store_true", help="Limit loops depth", ) eth_flags.add_argument( "--no-testcases", action="store_true", help="Do not generate testcases for discovered states when analysis finishes", ) eth_flags.add_argument( "--only-alive-testcases", action="store_true", help="Do not generate testcases for invalid/throwing states when analysis finishes", ) eth_flags.add_argument( "--quick-mode", action="store_true", help="Configure Manticore for quick exploration. Disable gas, generate testcase only for alive states, " "do not explore constant functions. Disable all detectors.", ) config_flags = parser.add_argument_group("Constants") config.add_config_vars_to_argparse(config_flags) parsed = parser.parse_args(sys.argv[1:]) config.process_config_values(parser, parsed) if not parsed.argv: print(parser.format_usage() + "error: the following arguments are required: argv") sys.exit(1) if parsed.policy.startswith("min"): parsed.policy = "-" + parsed.policy[3:] elif parsed.policy.startswith("max"): parsed.policy = "+" + parsed.policy[3:] return parsed
def main(): from crytic_compile import is_supported, cryticparser parser = argparse.ArgumentParser( description="Solidity property verifier", prog="manticore_verifier", # formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) # Add crytic compile arguments # See https://github.com/crytic/crytic-compile/wiki/Configuration cryticparser.init(parser) parser.add_argument( "source_code", type=str, nargs="*", default=[], help="Contract source code", ) parser.add_argument("-v", action="count", default=0, help="Specify verbosity level from -v to -vvvv") parser.add_argument( "--workspace", type=str, default=None, help=("A folder name for temporaries and results." "(default mcore_?????)"), ) current_version = pkg_resources.get_distribution("manticore").version parser.add_argument( "--version", action="version", version=f"Manticore {current_version}", help="Show program version information", ) parser.add_argument( "--propconfig", type=str, help="Solidity property accounts config file (.yml)", ) eth_flags = parser.add_argument_group("Ethereum flags") eth_flags.add_argument( "--quick-mode", action="store_true", help= "Configure Manticore for quick exploration. Disable gas, generate testcase only for alive states, " "do not explore constant functions. Disable all detectors.", ) eth_flags.add_argument( "--contract_name", type=str, help="The target contract name defined in the source code") eth_flags.add_argument( "--maxfail", type=int, help="stop after maxfail properties are failing. All if None") eth_flags.add_argument( "--maxcov", type=int, default=100, help=" Stop after maxcov %% coverage is obtained in the main contract", ) eth_flags.add_argument("--maxt", type=int, default=3, help="Max transaction count to explore") eth_flags.add_argument( "--deployer", type=str, help="(optional) address of account used to deploy the contract") eth_flags.add_argument( "--senders", type=str, help= "(optional) a comma separated list of sender addresses. The properties are going to be tested sending transactions from these addresses.", ) eth_flags.add_argument( "--psender", type=str, help="(optional) address from where the property is tested") eth_flags.add_argument( "--propre", default=r"crytic_.*", type=str, help="A regular expression for selecting properties", ) eth_flags.add_argument("--timeout", default=240, type=int, help="Exploration timeout in seconds") eth_flags.add_argument("--outputspace_url", type=str, help="where to put the extended result") config_flags = parser.add_argument_group("Constants") config.add_config_vars_to_argparse(config_flags) parsed = parser.parse_args(sys.argv[1:]) config.process_config_values(parser, parsed) if not parsed.source_code: print(parser.format_usage() + "error: You need to provide a contract source code.") sys.exit(1) args = parsed set_verbosity(args.v) logger = logging.getLogger("manticore.main") # read yaml config file deployer = None senders = None psenders = None if args.propconfig: """ deployer: "0x41414141414141414141" #who deploys the contract sender: ["0x51515151515151515151", "0x52525252525252525252"] #who calls the transactions (potentially can be multiple users) psender: "0x616161616161616161" #who calls the property """ import yaml with open(args.propconfig) as f: c = yaml.safe_load(f) deployer = c.get("deployer") if deployer is not None: deployer = int(deployer, 0) senders = c.get("sender") if senders is not None: senders = [int(sender, 0) for sender in senders] psender = c.get("psender") if psender is not None: psender = int(psender, 0) # override with commandline args deployer = None if args.deployer is not None: deployer = int(args.deployer, 0) senders = None if args.senders is not None: senders = [int(sender, 0) for sender in args.senders.split(",")] psender = None if args.psender is not None: psender = int(args.psender, 0) source_code = args.source_code[0] contract_name = args.contract_name maxfail = args.maxfail maxt = args.maxt maxcov = args.maxcov return manticore_verifier(source_code, contract_name, maxfail=maxfail, maxt=maxt, maxcov=100, senders=senders, deployer=deployer, psender=psender, timeout=args.timeout, propre=args.propre, compile_args=vars(parsed))
def parse_args(): """ Parse the underlying arguments for the program. :return: Returns the arguments for the program. """ parser = argparse.ArgumentParser(description="slither_format", usage="slither_format filename") parser.add_argument( "filename", help="The filename of the contract or truffle directory to analyze." ) parser.add_argument( "--verbose-test", "-v", help="verbose mode output for testing", action="store_true", default=False, ) parser.add_argument( "--verbose-json", "-j", help="verbose json output", action="store_true", default=False, ) parser.add_argument( "--version", help="displays the current version", version="0.1.0", action="version", ) parser.add_argument( "--config-file", help="Provide a config file (default: slither.config.json)", action="store", dest="config_file", default="slither.config.json", ) group_detector = parser.add_argument_group("Detectors") group_detector.add_argument( "--detect", help="Comma-separated list of detectors, defaults to all, " "available detectors: {}".format(", ".join(d for d in available_detectors)), action="store", dest="detectors_to_run", default="all", ) group_detector.add_argument( "--exclude", help="Comma-separated list of detectors to exclude," "available detectors: {}".format(", ".join(d for d in available_detectors)), action="store", dest="detectors_to_exclude", default="all", ) cryticparser.init(parser) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) return parser.parse_args()
def parse_args() -> argparse.Namespace: """Parse the underlying arguments for the program. Returns: The arguments for the program. """ parser = argparse.ArgumentParser( description= "Read a variable's value from storage for a deployed contract", usage= ("\nTo retrieve a single variable's value:\n" + "\tslither-read-storage $TARGET address --variable-name $NAME\n" + "To retrieve a contract's storage layout:\n" + "\tslither-read-storage $TARGET address --contract-name $NAME --layout\n" + "To retrieve a contract's storage layout and values:\n" + "\tslither-read-storage $TARGET address --contract-name $NAME --layout --values\n" + "TARGET can be a contract address or project directory"), ) parser.add_argument( "contract_source", help= "The deployed contract address if verified on etherscan. Prepend project directory for unverified contracts.", nargs="+", ) parser.add_argument( "--variable-name", help="The name of the variable whose value will be returned.", default=None, ) parser.add_argument("--rpc-url", help="An endpoint for web3 requests.") parser.add_argument( "--key", help= "The key/ index whose value will be returned from a mapping or array.", default=None, ) parser.add_argument( "--deep-key", help= "The key/ index whose value will be returned from a deep mapping or multidimensional array.", default=None, ) parser.add_argument( "--struct-var", help= "The name of the variable whose value will be returned from a struct.", default=None, ) parser.add_argument( "--storage-address", help= "The address of the storage contract (if a proxy pattern is used).", default=None, ) parser.add_argument( "--contract-name", help="The name of the logic contract.", default=None, ) parser.add_argument( "--layout", action="store_true", help="Toggle used to write a JSON file with the entire storage layout.", ) parser.add_argument( "--value", action="store_true", help="Toggle used to include values in output.", ) parser.add_argument("--max-depth", help="Max depth to search in data structure.", default=20) cryticparser.init(parser) return parser.parse_args()
def parse_arguments() -> argparse.Namespace: def positive(value): ivalue = int(value) if ivalue <= 0: raise argparse.ArgumentTypeError("Argument must be positive") return ivalue parser = argparse.ArgumentParser( description="Symbolic execution tool", prog="manticore", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) # Add crytic compile arguments # See https://github.com/crytic/crytic-compile/wiki/Configuration cryticparser.init(parser) parser.add_argument("--context", type=str, default=None, help=argparse.SUPPRESS) parser.add_argument("--coverage", type=str, default="visited.txt", help="Where to write the coverage data") parser.add_argument("--names", type=str, default=None, help=argparse.SUPPRESS) parser.add_argument("--offset", type=int, default=16, help=argparse.SUPPRESS) # FIXME (theo) Add some documentation on the different search policy options parser.add_argument( "--policy", type=str, default="random", help=("Search policy. random|adhoc|uncovered|dicount" "|icount|syscount|depth. (use + (max) or - (min)" " to specify order. e.g. +random)"), ) parser.add_argument( "argv", type=str, nargs="*", default=[], help= "Path to program, path to mutants folder and program arguments ('+' in arguments indicates symbolic byte).", ) parser.add_argument( "--workspace", type=str, default=None, help=("A folder name for temporaries and results." "(default mcore_?????)"), ) parser.add_argument( "--config", type=str, help= "Manticore config file (.yml) to use. (default config file pattern is: ./[.]m[anti]core.yml)", ) eth_flags = parser.add_argument_group("Ethereum flags") eth_flags.add_argument("--verbose-trace", action="store_true", help="Dump an extra verbose trace for each state") eth_flags.add_argument( "--txlimit", type=positive, help= "Maximum number of symbolic transactions to run (positive integer)", ) eth_flags.add_argument("--txnocoverage", action="store_true", help="Do not use coverage as stopping criteria") eth_flags.add_argument("--txnoether", action="store_true", help="Do not attempt to send ether to contract") eth_flags.add_argument( "--txaccount", type=str, default="attacker", help= 'Account used as caller in the symbolic transactions, either "attacker" or ' '"owner" or "combo1" (uses both)', ) eth_flags.add_argument( "--txpreconstrain", action="store_true", help= "Constrain human transactions to avoid exceptions in the contract function dispatcher", ) eth_flags.add_argument( "--contract", type=str, help="Contract name to analyze in case of multiple contracts") eth_flags.add_argument( "--avoid-constant", action="store_true", help="Avoid exploring constant functions for human transactions", ) eth_flags.add_argument( "--limit-loops", action="store_true", help="Limit loops depth", ) eth_flags.add_argument( "--no-testcases", action="store_true", help= "Do not generate testcases for discovered states when analysis finishes", ) eth_flags.add_argument( "--only-alive-testcases", action="store_true", help= "Do not generate testcases for invalid/throwing states when analysis finishes", ) eth_flags.add_argument( "--quick-mode", action="store_true", help= "Configure Manticore for quick exploration. Disable gas, generate testcase only for alive states, " "do not explore constant functions. Disable all detectors.", ) config_flags = parser.add_argument_group("Constants") config.add_config_vars_to_argparse(config_flags) parsed = parser.parse_args(sys.argv[1:]) config.process_config_values(parser, parsed) if not parsed.argv: print(parser.format_usage() + "error: the following arguments are required: argv") sys.exit(1) if parsed.policy.startswith("min"): parsed.policy = "-" + parsed.policy[3:] elif parsed.policy.startswith("max"): parsed.policy = "+" + parsed.policy[3:] return parsed
def parse_args(detector_classes, printer_classes): # pylint: disable=too-many-statements usage = "slither target [flag]\n" usage += "\ntarget can be:\n" usage += "\t- file.sol // a Solidity file\n" usage += "\t- project_directory // a project directory. See https://github.com/crytic/crytic-compile/#crytic-compile for the supported platforms\n" usage += "\t- 0x.. // a contract on mainet\n" usage += f"\t- NETWORK:0x.. // a contract on a different network. Supported networks: {','.join(x[:-1] for x in SUPPORTED_NETWORK)}\n" parser = argparse.ArgumentParser( description= "For usage information, see https://github.com/crytic/slither/wiki/Usage", usage=usage, ) parser.add_argument("filename", help=argparse.SUPPRESS) cryticparser.init(parser) parser.add_argument( "--version", help="displays the current version", version=require("slither-analyzer")[0].version, action="version", ) group_detector = parser.add_argument_group("Detectors") group_printer = parser.add_argument_group("Printers") group_misc = parser.add_argument_group("Additional options") group_detector.add_argument( "--detect", help="Comma-separated list of detectors, defaults to all, " "available detectors: {}".format(", ".join(d.ARGUMENT for d in detector_classes)), action="store", dest="detectors_to_run", default=defaults_flag_in_config["detectors_to_run"], ) group_printer.add_argument( "--print", help="Comma-separated list fo contract information printers, " "available printers: {}".format(", ".join(d.ARGUMENT for d in printer_classes)), action="store", dest="printers_to_run", default=defaults_flag_in_config["printers_to_run"], ) group_detector.add_argument( "--list-detectors", help="List available detectors", action=ListDetectors, nargs=0, default=False, ) group_printer.add_argument( "--list-printers", help="List available printers", action=ListPrinters, nargs=0, default=False, ) group_detector.add_argument( "--exclude", help="Comma-separated list of detectors that should be excluded", action="store", dest="detectors_to_exclude", default=defaults_flag_in_config["detectors_to_exclude"], ) group_detector.add_argument( "--exclude-dependencies", help="Exclude results that are only related to dependencies", action="store_true", default=defaults_flag_in_config["exclude_dependencies"], ) group_detector.add_argument( "--exclude-optimization", help="Exclude optimization analyses", action="store_true", default=defaults_flag_in_config["exclude_optimization"], ) group_detector.add_argument( "--exclude-informational", help="Exclude informational impact analyses", action="store_true", default=defaults_flag_in_config["exclude_informational"], ) group_detector.add_argument( "--exclude-low", help="Exclude low impact analyses", action="store_true", default=defaults_flag_in_config["exclude_low"], ) group_detector.add_argument( "--exclude-medium", help="Exclude medium impact analyses", action="store_true", default=defaults_flag_in_config["exclude_medium"], ) group_detector.add_argument( "--exclude-high", help="Exclude high impact analyses", action="store_true", default=defaults_flag_in_config["exclude_high"], ) group_detector.add_argument( "--show-ignored-findings", help="Show all the findings", action="store_true", default=defaults_flag_in_config["show_ignored_findings"], ) group_misc.add_argument( "--json", help= 'Export the results as a JSON file ("--json -" to export to stdout)', action="store", default=defaults_flag_in_config["json"], ) group_misc.add_argument( "--sarif", help= 'Export the results as a SARIF JSON file ("--sarif -" to export to stdout)', action="store", default=defaults_flag_in_config["sarif"], ) group_misc.add_argument( "--json-types", help= "Comma-separated list of result types to output to JSON, defaults to " + f'{",".join(output_type for output_type in DEFAULT_JSON_OUTPUT_TYPES)}. ' + f'Available types: {",".join(output_type for output_type in JSON_OUTPUT_TYPES)}', action="store", default=defaults_flag_in_config["json-types"], ) group_misc.add_argument( "--zip", help="Export the results as a zipped JSON file", action="store", default=defaults_flag_in_config["zip"], ) group_misc.add_argument( "--zip-type", help= f'Zip compression type. One of {",".join(ZIP_TYPES_ACCEPTED.keys())}. Default lzma', action="store", default=defaults_flag_in_config["zip_type"], ) group_misc.add_argument( "--markdown-root", help="URL for markdown generation", action="store", default="", ) group_misc.add_argument( "--disable-color", help="Disable output colorization", action="store_true", default=defaults_flag_in_config["disable_color"], ) group_misc.add_argument( "--filter-paths", help="Comma-separated list of paths for which results will be excluded", action="store", dest="filter_paths", default=defaults_flag_in_config["filter_paths"], ) group_misc.add_argument( "--triage-mode", help="Run triage mode (save results in slither.db.json)", action="store_true", dest="triage_mode", default=False, ) group_misc.add_argument( "--config-file", help="Provide a config file (default: slither.config.json)", action="store", dest="config_file", default="slither.config.json", ) group_misc.add_argument( "--solc-ast", help="Provide the contract as a json AST", action="store_true", default=False, ) group_misc.add_argument( "--generate-patches", help="Generate patches (json output only)", action="store_true", default=False, ) # debugger command parser.add_argument("--debug", help=argparse.SUPPRESS, action="store_true", default=False) parser.add_argument("--markdown", help=argparse.SUPPRESS, action=OutputMarkdown, default=False) group_misc.add_argument("--checklist", help=argparse.SUPPRESS, action="store_true", default=False) group_misc.add_argument("--checklist-limit", help=argparse.SUPPRESS, action="store", default="") parser.add_argument("--wiki-detectors", help=argparse.SUPPRESS, action=OutputWiki, default=False) parser.add_argument( "--list-detectors-json", help=argparse.SUPPRESS, action=ListDetectorsJson, nargs=0, default=False, ) parser.add_argument( "--legacy-ast", help=argparse.SUPPRESS, action="store_true", default=defaults_flag_in_config["legacy_ast"], ) parser.add_argument( "--skip-assembly", help=argparse.SUPPRESS, action="store_true", default=defaults_flag_in_config["skip_assembly"], ) parser.add_argument( "--ignore-return-value", help=argparse.SUPPRESS, action="store_true", default=defaults_flag_in_config["ignore_return_value"], ) parser.add_argument( "--perf", help=argparse.SUPPRESS, action="store_true", default=False, ) # if the json is splitted in different files parser.add_argument("--splitted", help=argparse.SUPPRESS, action="store_true", default=False) # Disable the throw/catch on partial analyses parser.add_argument("--disallow-partial", help=argparse.SUPPRESS, action="store_true", default=False) if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) args = parser.parse_args() read_config_file(args) args.filter_paths = parse_filter_paths(args) # Verify our json-type output is valid args.json_types = set(args.json_types.split(",")) for json_type in args.json_types: if json_type not in JSON_OUTPUT_TYPES: raise Exception( f'Error: "{json_type}" is not a valid JSON result output type.' ) return args