コード例 #1
0
def analyze_solidity(input_type='solidity'):
    global args

    x = dtimer()
    is_runtime = not(args.init)
    print is_runtime
    if input_type == 'solidity':
        helper = InputHelper(InputHelper.SOLIDITY, source=args.source,evm=args.evm,runtime=is_runtime)
    elif input_type == 'standard_json':
        helper = InputHelper(InputHelper.STANDARD_JSON, source=args.source,evm=args.evm, allow_paths=args.allow_paths)
    elif input_type == 'standard_json_output':
        helper = InputHelper(InputHelper.STANDARD_JSON_OUTPUT, source=args.source,evm=args.evm)
    inputs = helper.get_inputs()
    hashes = process_hashes(args.source)
    
    y = dtimer()
    print("*************************************************************")
    print("Compilation time: "+str(y-x)+"s")
    print("*************************************************************")
    results, exit_code = run_solidity_analysis(inputs,hashes)
    helper.rm_tmp_files()

    if global_params.WEB:
        six.print_(json.dumps(results))
    return exit_code
コード例 #2
0
def analyze_solidity(input_type='solidity'):
    global args

    x = dtimer()

    if input_type == 'solidity':
        helper = InputHelper(InputHelper.SOLIDITY,
                             source=args.source,
                             evm=args.evm)
    elif input_type == 'standard_json':
        helper = InputHelper(InputHelper.STANDARD_JSON,
                             source=args.source,
                             evm=args.evm,
                             allow_paths=args.allow_paths)
    elif input_type == 'standard_json_output':
        helper = InputHelper(InputHelper.STANDARD_JSON_OUTPUT,
                             source=args.source,
                             evm=args.evm)
    inputs = helper.get_inputs()
    hashes = process_hashes(args.source)

    y = dtimer()
    print("*************************************************************")
    print("Compilation time: " + str(y - x) + "s")
    print("*************************************************************")

    if check_optimize_dependencies():
        i = 0
        found = False
        while (i < len(inputs) and (not found)):
            if inputs[i]["c_name"] == args.contract_name:
                inp = inputs[i]
                found = True
            i += 1
        results, exit_code = run_solidity_analysis_optimized(inp, hashes)
    else:
        results, exit_code = run_solidity_analysis(inputs, hashes)
        helper.rm_tmp_files()

    if global_params.WEB:
        six.print_(json.dumps(results))
    return exit_code
コード例 #3
0
def main():
    # TODO: Implement -o switch.
    
    global args
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group(required=True)

    group.add_argument("-s",  "--source",    type=str, help="local source file name. Solidity by default. Use -b to process evm instead. Use stdin to read from stdin.")

    # parser.add_argument("--version", action="version", version="EthIR version 1.0.7 - Commonwealth")
    parser.add_argument("-glt", "--global-timeout", help="Timeout for symbolic execution", action="store", dest="global_timeout", type=int)
    parser.add_argument( "-e",   "--evm",                    help="Do not remove the .evm file.", action="store_true")
    parser.add_argument( "-b",   "--bytecode",               help="read bytecode in source instead of solidity file", action="store_true")
    
    #Added by Pablo Gordillo
    parser.add_argument( "-disasm", "--disassembly",        help="Consider a dissasembly evm file directly", action="store_true")
    parser.add_argument( "-d", "--debug",                   help="Display the status of the stack after each opcode", action = "store_true")
    parser.add_argument( "-cfg", "--control-flow-graph",    help="Store the CFG", action="store_true")
    # parser.add_argument( "-eop", "--evm-opcodes",           help="Include the EVM opcodes in the translation", action="store_true")
    parser.add_argument( "-saco", "--saco",                 help="Translate EthIR RBR to SACO RBR", action="store_true")
    parser.add_argument( "-c", "--cfile",                 help="Translate EthIR RBR to SACO RBR", choices = ["int","uint"])
    parser.add_argument("-v", "--verify",             help="Applies abstraction depending on the verifier (CPAchecker, VeryMax or SeaHorn). Use with -c flag", choices = ["cpa","verymax","seahorn"])
    parser.add_argument("-i", "--invalid",             help="Translate the specified invalid bytecodes into SV-COMP error labels. Use with -c flag", choices = ["array","div0","all"])
    parser.add_argument("-g", "--goto",             help="Transform recursive rules into iterative rules using gotos. Use with -c flag", action="store_true")
    parser.add_argument( "-hashes", "--hashes",             help="Generate a file that contains the functions of the solidity file", action="store_true")
    args = parser.parse_args()

    # if args.root_path:
    #     if args.root_path[-1] != '/':
    #         args.root_path += '/'
    # else:
    #     args.root_path = ""

    # if args.timeout:
    #     global_params.TIMEOUT = args.timeout

    # if args.verbose:
    #     logging.basicConfig(level=logging.DEBUG)
    # else:
    #     logging.basicConfig(level=logging.INFO)
    
    global_params.PRINT_PATHS = 0 #1 if args.paths else 0
    global_params.REPORT_MODE = 0 #1  if args.report else 0
    global_params.USE_GLOBAL_BLOCKCHAIN = 0#1 if args.globalblockchain else 0
    global_params.INPUT_STATE = 0#1 if args.state else 0
    global_params.WEB = 0#1 if args.web else 0
    global_params.STORE_RESULT = 0#1 if args.json else 0
    global_params.CHECK_ASSERTIONS = 0#1 if args.assertion else 0
    global_params.DEBUG_MODE = 0#1 if args.debug else 0
    global_params.GENERATE_TEST_CASES = 0#1 if args.generate_test_cases else 0
    global_params.PARALLEL = 0#1 if args.parallel else 0

    # if args.depth_limit:
    #     global_params.DEPTH_LIMIT = args.depth_limit
    # # if args.gas_limit:
    # #     global_params.GAS_LIMIT = args.gas_limit
    # if args.loop_limit:
    #     global_params.LOOP_LIMIT = args.loop_limit
    # if global_params.WEB:
    #     if args.global_timeout and args.global_timeout < global_params.GLOBAL_TIMEOUT:
    #         global_params.GLOBAL_TIMEOUT = args.global_timeout
    # else:
    #     if args.global_timeout:
    #         global_params.GLOBAL_TIMEOUT = args.global_timeout

    if not has_dependencies_installed():
        return

    # if args.remote_URL:
    #     r = requests.get(args.remote_URL)
    #     code = r.text
    #     filename = "remote_contract.evm" if args.bytecode else "remote_contract.sol"
    #     args.source = filename
    #     with open(filename, 'w') as f:
    #         f.write(code)

    # exit_code = 0

    clean_dir()

    #Added by Pablo Gordillo
    if args.disassembly:
        exit_code = analyze_disasm_bytecode()
    elif args.bytecode:
        exit_code = analyze_bytecode()
    # elif args.standard_json:
    #     exit_code = analyze_solidity(input_type='standard_json')
    # elif args.standard_json_output:
    #     exit_code = analyze_solidity(input_type='standard_json_output')
    elif hashes_cond(args):
        mp = process_hashes(args.source)
        generate_saco_hashes_file(mp)
        exit_code = 0
        
    else:
        exit_code = analyze_solidity()
    six.print_("The files generated by EthIR are stored in the following directory: "+costabs_path)

    exit(exit_code)
コード例 #4
0
def main():
    # TODO: Implement -o switch.

    global rbr_dir

    rbr_dir = "/tmp/costabs/"

    global args

    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group(required=True)

    group.add_argument(
        "-s",
        "--source",
        type=str,
        help=
        "local source file name. Solidity by default. Use -b to process evm instead. Use stdin to read from stdin."
    )
    # group.add_argument("-ru", "--remoteURL", type=str, help="Get contract from remote URL. Solidity by default. Use -b to process evm instead.", dest="remote_URL")

    parser.add_argument("--version",
                        action="version",
                        version="oyente version 0.2.7 - Commonwealth")

    #parser.add_argument("-t",   "--timeout",        help="Timeout for Z3 in ms.", action="store", type=int)
    #parser.add_argument("-gl",  "--gaslimit",       help="Limit Gas", action="store", dest="gas_limit", type=int)
    #parser.add_argument("-rp",   "--root-path",     help="Root directory path used for the online version", action="store", dest="root_path", type=str)
    parser.add_argument("-ll",
                        "--looplimit",
                        help="Limit number of loops",
                        action="store",
                        dest="loop_limit",
                        type=int)
    parser.add_argument("-dl",
                        "--depthlimit",
                        help="Limit DFS depth",
                        action="store",
                        dest="depth_limit",
                        type=int)
    #parser.add_argument("-ap",  "--allow-paths",    help="Allow a given path for imports", action="store", dest="allow_paths", type=str)
    parser.add_argument("-glt",
                        "--global-timeout",
                        help="Timeout for symbolic execution",
                        action="store",
                        dest="global_timeout",
                        type=int)

    parser.add_argument("-e",
                        "--evm",
                        help="Do not remove the .evm file.",
                        action="store_true")
    #parser.add_argument( "-w",   "--web",                    help="Run Oyente for web service", action="store_true")
    #parser.add_argument( "-j",   "--json",                   help="Redirect results to a json file.", action="store_true")
    #parser.add_argument( "-p",   "--paths",                  help="Print path condition information.", action="store_true")
    #parser.add_argument( "-db",  "--debug",                  help="Display debug information", action="store_true")
    #parser.add_argument( "-st",  "--state",                  help="Get input state from state.json", action="store_true")
    #parser.add_argument( "-r",   "--report",                 help="Create .report file.", action="store_true")
    #parser.add_argument( "-v",   "--verbose",                help="Verbose output, print everything.", action="store_true")
    #parser.add_argument( "-pl",  "--parallel",               help="Run Oyente in parallel. Note: The performance may depend on the contract", action="store_true")
    parser.add_argument(
        "-b",
        "--bytecode",
        help="read bytecode in source instead of solidity file",
        action="store_true")
    #parser.add_argument( "-a",   "--assertion",              help="Check assertion failures.", action="store_true")
    #parser.add_argument( "-sj",  "--standard-json",          help="Support Standard JSON input", action="store_true")
    #parser.add_argument( "-gb",  "--globalblockchain",       help="Integrate with the global ethereum blockchain", action="store_true")
    #parser.add_argument( "-gtc", "--generate-test-cases",    help="Generate test cases each branch of symbolic execution tree", action="store_true")
    #parser.add_argument( "-sjo",  "--standard-json-output",  help="Support Standard JSON output", action="store_true")
    #Added by Pablo Gordillo
    parser.add_argument("-disasm",
                        "--disassembly",
                        help="Consider a dissasembly evm file directly",
                        action="store_true")
    parser.add_argument("-cfg",
                        "--control-flow-graph",
                        help="Store the CFG",
                        action="store_true")
    parser.add_argument("-eop",
                        "--evm-opcodes",
                        help="Include the EVM opcodes in the translation",
                        action="store_true")
    parser.add_argument("-saco",
                        "--saco",
                        help="Translate EthIR RBR to SACO RBR",
                        action="store_true")
    parser.add_argument(
        "-hashes",
        "--hashes",
        help="Generate a file that contains the functions of the solidity file",
        action="store_true")
    args = parser.parse_args()

    # if args.root_path:
    #     if args.root_path[-1] != '/':
    #         args.root_path += '/'
    # else:
    #     args.root_path = ""

    # if args.timeout:
    #     global_params.TIMEOUT = args.timeout

    # if args.verbose:
    #     logging.basicConfig(level=logging.DEBUG)
    # else:
    #     logging.basicConfig(level=logging.INFO)

    global_params.PRINT_PATHS = 0  #1 if args.paths else 0
    global_params.REPORT_MODE = 0  #1  if args.report else 0
    global_params.USE_GLOBAL_BLOCKCHAIN = 0  #1 if args.globalblockchain else 0
    global_params.INPUT_STATE = 0  #1 if args.state else 0
    global_params.WEB = 0  #1 if args.web else 0
    global_params.STORE_RESULT = 0  #1 if args.json else 0
    global_params.CHECK_ASSERTIONS = 0  #1 if args.assertion else 0
    global_params.DEBUG_MODE = 0  #1 if args.debug else 0
    global_params.GENERATE_TEST_CASES = 0  #1 if args.generate_test_cases else 0
    global_params.PARALLEL = 0  #1 if args.parallel else 0

    if args.depth_limit:
        global_params.DEPTH_LIMIT = args.depth_limit
    # if args.gas_limit:
    #     global_params.GAS_LIMIT = args.gas_limit
    if args.loop_limit:
        global_params.LOOP_LIMIT = args.loop_limit
    # if global_params.WEB:
    #     if args.global_timeout and args.global_timeout < global_params.GLOBAL_TIMEOUT:
    #         global_params.GLOBAL_TIMEOUT = args.global_timeout
    # else:
    #     if args.global_timeout:
    #         global_params.GLOBAL_TIMEOUT = args.global_timeout

    if not has_dependencies_installed():
        return

    # if args.remote_URL:
    #     r = requests.get(args.remote_URL)
    #     code = r.text
    #     filename = "remote_contract.evm" if args.bytecode else "remote_contract.sol"
    #     args.source = filename
    #     with open(filename, 'w') as f:
    #         f.write(code)

    # exit_code = 0

    clean_dir()

    #Added by Pablo Gordillo
    if args.disassembly:
        exit_code = analyze_disasm_bytecode()
    elif args.bytecode:
        exit_code = analyze_bytecode()
    # elif args.standard_json:
    #     exit_code = analyze_solidity(input_type='standard_json')
    # elif args.standard_json_output:
    #     exit_code = analyze_solidity(input_type='standard_json_output')
    elif hashes_cond(args):
        mp = process_hashes(args.source)
        generate_saco_hashes_file(mp)
        exit_code = 0

    else:
        exit_code = analyze_solidity()

    six.print_(
        "The files generated by EthIR are stored in the following directory: "
        + rbr_dir)
    exit(exit_code)