code: async def verify_chain_of_trust(chain):
      
      log_path = os.path.join(chain.context.config["task_log_dir"], "chain_of_trust.log")
      scriptworker_log = logging.getLogger('scriptworker')
      with contextual_log_handler(
          chain.context, path=log_path, log_obj=scriptworker_log,
          formatter=AuditLogFormatter(
              fmt=chain.context.config['log_fmt'],
              datefmt=chain.context.config['log_datefmt'],
          )
      ):
          try:
              # build LinkOfTrust objects
              await build_task_dependencies(chain, chain.task, chain.name, chain.task_id)
              # download the signed chain of trust artifacts
              await download_cot(chain)
              # verify the signatures and populate the ``link.cot``s
              verify_cot_signatures(chain)
              # download all other artifacts needed to verify chain of trust
              await download_cot_artifacts(chain)
              # verify the task types, e.g. decision
              task_count = await verify_task_types(chain)
              check_num_tasks(chain, task_count)
              # verify the worker_impls, e.g. docker-worker
              await verify_worker_impls(chain)
              await trace_back_to_tree(chain)
          except (BaseDownloadError, KeyError, AttributeError) as exc:
              log.critical("Chain of Trust verification error!", exc_info=True)
              if isinstance(exc, CoTError):
                  raise
              else:
                  raise CoTError(str(exc))
          log.info("Good.")
docs: Build and verify the chain of trust.
  
      Args:
          chain (ChainOfTrust): the chain we're operating on
  
      Raises:
          CoTError: on failure