While humans invent several “smart” things to make our lives easier, there is continual debate on whether these items are dumbing us down. While using the term “smart” for describing meters, phones, homes, cities, etc., definitely increases their market value, their actual “smartness” needs to be assessed judiciously. Joining this bandwagon are smart contracts, which are inherent within blockchain technology.
Understanding Smart Contracts in Blockchain
The second generation of blockchain involved the invention of the Ethereum blockchain platform, which is a generic, fully decentralized, smart contract-enabled platform. The most significant advantage of Ethereum was the introduction of smart contracts, allowing incorporating business logic that is executed and enforced by all blockchain nodes to achieve distributed consensus. Smart contracts also represent the agreement between two or more parties on blockchain. This compelling feature allows for various use cases to be implemented on blockchain where both the data and the logic are decentralized. Currently, several public and permissioned blockchain platforms provide out-of-the-box smart contract capabilities.
Smart contracts have the following characteristics:
- Smart contracts are written using a programming language that comprises logic to process data, validate it and store/update it on blockchain. The result of smart contract processing on each blockchain is taken into consideration for achieving consensus and committing the transaction on blockchain.
- Smart contracts are used for querying ledger data from the blockchain node’s database.
- Smart contracts are deployed on blockchain node and leverage blockchain’s runtime engine for execution.
- Smart contracts are required to be deterministic, i.e., the same version of the smart contract executing on any blockchain node should always provide the same output.
- Smart contracts are not allowed to interact with the external systems so that their output is always deterministic.
- Smart contracts can access the current state and historical data on blockchain with certain constraints.
Analyzing the Smartness Quotient of Smart Contracts
Smart contracts are as good as the logic incorporated in them, which is true for any software application. The biggest strength of smart contracts is that the same version must be executed on multiple nodes of a blockchain network to achieve consensus and finalize the transaction. Thus, a smart contract automatically inherits the blockchain features of transparency and trust. Keeping the performance and scaling challenges of blockchain aside, smart contracts provide a definite advantage over traditional, centralized systems.
For incorporating intelligence into smart contracts, the corresponding business/application logic must be embedded into it. This logic can access and use data already on blockchain for validations and enforcing business rules. However, what if data outside of blockchain is required? Blockchain must rely on off-chain components to provide the data from any external system. But, unless the quality and integrity of the data provided are ensured, blockchain can very quickly become a “garbage-in, garbage-forever” system. Different techniques can ensure data quality and accuracy before relaying data to blockchain, but what if the last-mile check for data needs to be enforced in blockchain itself. Although smart contracts can help, these programs are not allowed to communicate with the external world.
Other scenarios are when smart contracts need time-sensitive data from the external world or information is required at a particular execution step of a business process. For example, if the latest currency conversion rates, payment confirmation, or national ID verification is required. How can smart contracts obtain reliable, authentic data?
It is quite evident that smart contracts need a bridge between the on-chain and off-chain worlds so that blockchain smart contracts can provide real value and cater to various use cases.
Smart Contract Oracles – Blockchain’s Window to the External World
Smart contract oracles is an approach where smart contracts can be supplied with external information and link on-chain smart contracts to off-chain data sources. Through oracles, smart contracts can exponentially increase the use cases blockchain can cater to. Smart contract oracles can be leveraged in the following ways:
- Inbound data access where a smart contract needs external data on-demand can be achieved through an event-driven approach in which the smart contract generates an event when external data is required. The event handler registers with the oracle, which integrates with the external data source, retrieves the required information, digitally signs the transaction, and invokes the smart contract. The smart contract can validate the authenticity (by validating the transaction using the oracle’s public key) and then process the required data in real-time to continue the execution per the logic incorporated into it.
- Outbound data operations require the information resulting from blockchain transactions to be relayed to external systems. A prevalent scenario is the requirement to update enterprise business applications when the blockchain state changes. A similar event-driven approach can be followed in which the oracle receives the smart contract event, provides its digital signature, and invokes the interface of an enterprise business application. This kind of implementation will require an integration adapter depending on the type of integration capabilities the external application provides (refer to https://www.networkcomputing.com/network-security/enterprise-integration-and-interoperability-blockchain).
Oracles are essential to realizing the full potential of blockchain smart contracts. Therefore, the reliability and trustworthiness of an oracle are very critical. If the oracle is compromised, then the data relayed to/from blockchain will hold no value; its usage will become counter-productive. Oracles can be classified into two types:
- Centralized Oracles – A centralized oracle is configured to listen to a particular blockchain node and its smart contract events, taking appropriate action based on the event type. There will be security vulnerabilities that can be mitigated using either a trusted execution environment to secure the oracle or secured multi-party computing to safeguard the oracle’s signing key.
- Decentralized Oracles – Similar to how blockchain is decentralized, the same approach can be adopted for oracles. In this approach, the oracle’s functionality is provided as a service with a blockchain-based implementation. Any interaction with the outside world is validated by the decentralized oracle service so that the trustworthiness of data relayed through the oracle is maintained, and a single point of failure can be avoided.
Smart contracts on blockchain cannot operate in isolation. One part of the outside world interaction is through the distributed applications that provide human and machine interface. To provide holistic business functionality and authenticated provenance, smart contracts need a gateway to obtain off-chain data inputs in a trustless manner. This capability is fulfilled via oracles, making smart contracts truly “smart!” As predicted by Gartner, smart contract oracles will be a mandatory requirement for any use case implemented using blockchain, and more innovative alternatives will be required in the near future.