Exemplo n.º 1
0
def main():

    l = logging.getLogger('evm-cfg-builder')
    l.setLevel(logging.INFO)
    args = parse_args()

    if args.perf:
        cp = cProfile.Profile()
        cp.enable()

    if is_supported(args.filename):
        filename = args.filename
        del args.filename
        try:
            cryticCompile = CryticCompile(filename, **vars(args))
            for contract in cryticCompile.contracts_names:
                bytecode_init = cryticCompile.bytecode_init(contract)
                if bytecode_init:
                    for signature, hash in cryticCompile.hashes(contract).items():
                        known_hashes[hash] = signature
                    logger.info(f'Analyze {contract}')
                    _run(bytecode_init, f'{filename}-{contract}-init', args)
                    runtime_bytecode = cryticCompile.bytecode_runtime(contract)
                    if runtime_bytecode:
                        _run(runtime_bytecode,  f'{filename}-{contract}-runtime', args)
                    else:
                        logger.info('Runtime bytecode not available')
        except InvalidCompilation as e:
            logger.error(e)

    else:
        with open(args.filename, 'rb') as f:
            bytecode = f.read()
        logger.info(f'Analyze {args.filename}')
        _run(bytecode, args.filename, args)

    if args.perf:
        cp.disable()
        stats = pstats.Stats(cp).sort_stats("cumtime")
        stats.print_stats()
Exemplo n.º 2
0
def complie_solc(source,
                 contract_name,
                 compiler_version,
                 remappings='',
                 solc_args=''):
    """Function is used to compile solidity contract and return its trimmed bytecode.

    :param source: Path to contract file
    :param contract_name: Name of the contract whose bytecode is required
    :param compiler_version: Compiler version requirement of the contract file
    :param remappings: String containing library remappings required to compile contract
    :param solc_args: String containing additional compiler argument flags
    :return: Trimmed bytecode of the contract
    """
    try:
        com = CryticCompile(source,
                            solc_remaps=remappings,
                            solc_solcs_select=compiler_version,
                            solc_args=solc_args)
        return trim_bytecode(com.bytecode_runtime(contract_name),
                             compiler_version)
    except InvalidCompilation as e:
        logging.exception(e)
        return None
Exemplo n.º 3
0
 def _extract_bin_obj(self, com: CryticCompile):
     return [(com.contracts_filenames[name].absolute + ':' + name, com.bytecode_runtime(name)) for name in com.contracts_names if com.bytecode_runtime(name)]