示例#1
0
def analyze(bytecode: str,
            contract_name,
            result_printer: Printer,
            verbose=False) -> ContractReport:
    result_printer.info("***************************************************")
    result_printer.info("Analyzing contract: {0}".format(contract_name))
    result = ContractReport()
    c_printer = CPrinter()
    instructions = ByteCode.disasm(bytecode, c_printer)

    result_printer.info("Symbolically executing")
    analyzer = Analyzer(instructions, result_printer, verbose)
    # analyze construction code
    result_printer.info("Checking construction assemble code")
    cfg_r = analyze_cfg(analyzer.construct_cfg, result_printer)
    result.add(cfg_r)
    result_printer.info("Checking construction assemble code...done")
    result_printer.info("- - - - - - - - - - - - - - - - - - - - - - - - - -")
    # analyze body code
    result_printer.info("Checking runtime assemble code")
    cfg_r = analyze_cfg(analyzer.body_cfg, result_printer, verbose)
    result.add(cfg_r)
    result_printer.info("Checking runtime assemble code...done")
    result_printer.info("***************************************************")
    return result
示例#2
0
def test_timestamp_dependency0():
    cwd = getcwd()
    file = path.join(cwd, 'timestamp_dependency0.sol')
    _, bytecodes = utils.compile_sol(file)[0]
    instructions = disasm(bytecodes)
    symer = Analyzer(instructions)
    assert symer.body_cfg.check_timestamp_dependency()["vulnerable"]
示例#3
0
def test_reentrancy2():
    cwd = getcwd()
    file = path.join(cwd, 'reentrancy2.sol')
    _, bytecodes = utils.compile_sol(file)[0]
    instructions = disasm(bytecodes)
    symer = Analyzer(instructions)
    assert symer.body_cfg.check_reentrancy()["vulnerable"]
示例#4
0
def test_unchecked_call1():
    cwd = getcwd()
    file = path.join(cwd, 'unchecked_call1.sol')
    _, bytecodes = utils.compile_sol(file)[0]
    instructions = disasm(bytecodes)
    symer = Analyzer(instructions)
    assert not symer.body_cfg.check_unchecked_call()["vulnerable"]
示例#5
0
def analyze(printer: WPrinter, instructions: List[Instruction]) -> List[dict]:
    analyzer = Analyzer(instructions, printer, True)
    return analyze_cfg(analyzer.construct_cfg) + analyze_cfg(analyzer.body_cfg)