> For the complete documentation index, see [llms.txt](https://daoone.gitbook.io/blockchain-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://daoone.gitbook.io/blockchain-handbook/blockchain-basics/oracles.md).

# 1.7 Oracles

在区块链和智能合约的背景下，Oracles是一个代理人，可以找到和验证真实世界的事件并将此信息提交给使用的区块链的智能合约。

智能合约包含价值，并且只有在某些预定义的条件得到满足时才解锁该价值 一个特定的值被达成，智能合约改变它的状态并执行编程预定义的算法， 自动触发区块链上的事件。Oracles的主要任务是提供这些值 以安全可靠的方式进行智能合约。

区块链不能访问网络外部的数据。Oracle是一种数据馈送 - 由第三方提供 - 专为在区块链上的智能合约中使用而设计，Oracles提供外部数据和当预定义的条件满足时触发智能合约执行，这种情况触发条件可以是任何数据，例如天气温度，成功支付，价格波动等。

Oracles是多重签名合约的一部分，例如受托人只有在符合某些条件的情况下才会签署有关未来资金释放的合约。在任何资金被释放之前，Oracle还必须签署智能合约。

## Oracles 类型

根据使用类型可以将oracles分为软件oracles ，硬件oracles，共识oracles和流入和流出oracles。

* **软件 Oracles**

软件oracles在线处理信息，例如温度，商品和商品的价格，航班或火车延误等。数据来源于在线资源，如公司网站。软件oracle提取所需的信息并将其推送到智能合约中。

* **硬件 Oracles**

一些智能合约需要直接来自物理世界的信息，例如，跨越障碍的汽车移动传感器必须检测车辆情况并将数据发送至智能合约。另一个用例是供应链行业的RFID传感器，这是硬件领域最大的挑战 是在不牺牲数据安全性的情况下报告数据的能力。[Oracalize](http://www.oraclize.it) 提出了两步解决风险的方案，通过提供传感器读数和密码的密码证据， 防篡改机制使得设备在违规情况下不可操作。

* **流入 Oracles (Inbound Oracles)**

Inbound Oracles提供了来自外部世界的数据的智能合约。示例，如果美元达到一定的价格，将自动下订单。

* **流出 Oracles (Outbound Oracles)**

Outbound Oracles提供了将数据发送到外部世界的智能合同。示例，物理世界中的智能锁，通过区块链地址和需求接收付款将会自动解锁。

* **基于共识的 Oracles**

像Augur和Gnosis这样的预测市场在很大程度上依靠oracles来确认未来的结果。仅使用一种信息来源可能是有风险和不可靠的。为了避免市场操纵预测市场实施oracles的评级系统，为了进一步的安全，可以使用不同oracles的组合，例如5个oracles中有3个是确定事件的结果。

## 安全挑战

Oracles是第三方服务，不属于区块链共识机制。oracles主要挑战是人们需要信任这些信息来源。无论是一个网站或一个传感器，信息的来源需要值得信赖，不同的可信计算技术可以用作一种解决这些问题的方法，例如[Oracalize](http://www.oraclize.it/) 公司。

例如，一直在利用亚马逊的 [TLSNotary](https://tlsnotary.org) 为基础的证明，另一家公司Town Crier 重点关注英特尔[软件防护扩展（SGX）](https://software.intel.com/en-us/blogs/2013/09/26/protecting-application-secrets-with-intel-sgx)的使用情况。提供智能合约与可靠的信息来源对用户至关重要，如果出现错误，则不会回滚。

## 资料来源 & 延伸阅读

* [Hardware Oracles: bridging the Real World to the Blockchain](https://blog.ledger.co/hardware-oracles-bridging-the-real-world-to-the-blockchain-ca97c2fc3e6c#.2zeggzh6f)
* [Understanding oracles](https://blog.oraclize.it/understanding-oracles-99055c9c9f7b#.6t2fzxto2)
* [A visit to the oracle](https://media.consensys.net/a-visit-to-the-oracle-de9097d38b2f#.97rovs1ho)
* [Smart Contract Oracles](http://about.smartcontract.com)
* [Can oracles send data to smart contracts on multiple blockchains?](https://ethereum.stackexchange.com/questions/7965/can-oracles-send-data-to-smart-contracts-on-multiple-blockchains)
* [How can an Ethereum contract get data from a website?](https://ethereum.stackexchange.com/questions/2/how-can-an-ethereum-contract-get-data-from-a-website)
* [Why Many Smart Contract Use Cases Are Simply Impossible?](https://www.coindesk.com/three-smart-contract-misconceptions/)
* [1,749,693 blocks later](https://blog.oraclize.it/1-749-693-blocks-later-4225f55c68f1#.su7vg1dwc), Oracalize
* [SchellingCoin: A Minimal-Trust Universal Data Feed](https://blog.ethereum.org/2014/03/28/schellingcoin-a-minimal-trust-universal-data-feed/), Vitalike Buterin
* [Town Crier: An Authenticated Data Feed for Smart Contracts: Scientific paper](http://delivery.acm.org/10.1145/2980000/2978326/p270-zhang.pdf?ip=213.162.68.68\&id=2978326\&acc=OA\&key=4D4702B0C3E38B35%2E4D4702B0C3E38B35%2E4D4702B0C3E38B35%2E594C525CFFA2AFAF\&CFID=730799167\&CFTOKEN=28086432&__acm__=1488151135_be7fb06560c8ae75b526b93f81cb4dfd)
