A bridge between Blockchain Network and the Outside world: Blockchain Oracles

September 29, 2020

Image for post

The term blockchain wouldn’t be new to most people. It’s one of those emerging technologies which has gained the attention of many, including both tech and non-tech people. It’s a very simple idea with profound implications. All it does is change the way data is being stored; instead of storing data in separate central systems, the idea is to keep them with concerned individuals parties and sync the data in realtime. This simple idea could increase operational efficiency, reduce trust issues, reduce reconciliation efforts, and multiple other frictions in businesses.

But like with every good thing, it has its shortcomings. One such problem is accessing data that is not native to the blockchain network. A particular fact in a blockchain ledger is considered to be trusted since it has been recorded in the ledger after a process of consensus, and all the evolution of that fact has happened within the blockchain network. But the same can’t be true for facts that haven’t originated or evolved within the network. That seems to be quite a limitation, its not always possible to have all the pieces of data involved in a transaction to be stored in the blockchain ledger; there are always third parties involved in enterprise software systems. This is where blockchain oracles come in handy.

Blockchain Oracles

Blockchain oracles are trusted third-party services that feed trusted data to the blockchain networks. They serve as a bridge between the outside world and the blockchains. Blockchain nodes can query these trusted third-party services when there is a need for external data. These oracle services provide signed data that could be trusted and used in blockchain transactions.

Examples

  • An insurance blockchain consulting an oracle to check an individual’s credit worthiness.
  • A betting blockchain accessing an oracle to fetch the outcome of a real-world event.
  • Tracking the GPS coordinates of a shipment using an oracle in a supply chain blockchain.

Oracles in Corda

Oracles in Corda are Corda Nodes running Corda Services, which links the Corda Network to the outside world. They are not generally participants in a business transaction but provide network services. A node in needs of any data served by the Oracle Service would request the oracle node to provide signed external data, which the transacting node could then use in a business transaction.

New to Corda? A great way to start with Corda is to take a look at one of our online bootcamp webinars. The recording for one of them is available here: https://www.youtube.com/watch?v=tVE1rKbFA3g

You may also consider joining us for one of our in-person or live virtual bootcamps. Keep an eye on the link below to know what events are coming up: https://www.corda.net/blockchain-bootcamp/

A Typical Flow involving an Oracle Service

An oracle node is a regular Corda node hosting CorDapps which has few Corda flows and services. The flows are used for communicating with the transacting nodes while the service, as you could guess, is the oracle service.

Image for post

Typical Flow for Fetching Data from Oracle Service

Let’s take an example to understand the concept. Consider two parties Bob and Alice, who wants to bet on a football match between Portugal and Argentina. Bob is a Messi fan and bets on Messi to be the highest goal scorer in the game, while Alice is a Ronaldo fan and puts his stakes on Ronaldo. Once the match is finished, they want to settle their bet. Let us look at how it would work.

  • The initiator of the transaction (say Alice) initiates a flow say SettleBetFlow. This flow needs to know the outcome of the match to create a transaction to settle the bet.
  • Alice uses an initiating subflow flow, say QueryOracleDataFlow, to request the oracle for the number of goals scored by each player.
  • The oracle would need to respond to QueryOracleDataFlow using a responder say QueryOracleDataFlowResponder. The responder flow internally calls the oracle service to fetch the requested data and returns it to the Initiator (Alice) node.
  • Alice now has the data she needs and she could now create the transaction to settle the bet.
  • Alice would need the transaction to be signed by the Oracle. Oracle should also sign the transaction for others (Bob) to trust the data. (Alice could just include any random data stating that it has come from the oracle if we don’t get the oracle to sign.) However, we do not want to have privacy leaks and oracle not being a party to the transaction should not see the data involved in the transaction. Hence we create a filtered transaction where oracle only see the data he is concerned about and other pieces of data are masked out. A Merkle tree is used to achieve this. To fetch the oracle signature Alice uses an initiating subflow say FetchOracleSignatureFlow.
  • The responder of the FetchOracleSignatureFlow at the Oracle node handles the signature request and internally consulting the oracle-service to verify the data before signing the transaction and the signed transaction is returned back to the initiator (if data is verified correctly).
  • Alice now has a transaction build which includes the data fetch from the oracle service as well as the signature of the oracle node. This transaction can now proceed as a usual Corda transaction. Alice would request for Bob’s signature and once Bob has signed the transaction it can go to the notary for notarization.
  • The counterpart (Bob) would verify and sign the transaction and finally, it would be recorded in the ledger.

That’s how external data is fetched from a trusted oracle node in Corda.

Source Code

We have a sample CorDapp available in the Corda samples repository if you would want to have a look at how it’s done at the code level.

Thank you so much for reading.

Want to learn more about building awesome blockchain applications on Corda? Be sure to visit corda.net, check out our community page to learn how to connect with other Corda developers, and sign up for one of our newsletters for the latest updates.


— Ashutosh Meher is a Developer Evangelist at R3, an enterprise blockchain software firm working with a global ecosystem of more than 350 participants across multiple industries from both the private and public sectors to develop on Corda, its open-source blockchain platform, and Corda Enterprise, a commercial version of Corda for enterprise usage.

Follow Ashutosh on Twitter here.

Share: