OracleΒΆ

This example is part of the smart contracts presented in [AB+18POST].

In many concrete scenarios one would like to make the execution of a contract depend on some real-world events, e.g. results of football matches for a betting contract, or feeds of flight delays for an insurance contract. However, the evaluation of Bitcoin scripts can not depend on the environment, so in these scenarios one has to resort to a trusted third-party, or oracle, who notifies real-world events by providing signatures on certain transactions.

For example, assume that Alice wants to transfer 1 BTC to Bob only if a certain event, notified by an oracle Oscar, happens. To do that, Alice puts on the blockchain the transaction T which can be redeemed by a transactions carrying the signatures of both Bob and Oscar. Further, Alice instructs the oracle to provide his signature to Bob upon the occurrence of the expected event.

The transactions of the protocol are shown below, where create a fictional transaction T_A redeemable by Alice.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
package oracle

const kA = wif:cSthBXr8YQAexpKeh22LB9PdextVE1UJeahmyns5LzcmMDSy59L4
const kB = wif:cQtkW1zgFCckRYvJ2Nm8rryV825GyDJ51qoJCw72rhHG4YmGfYgZ
const kO = wif:cRLgSnk3t7DhitfxkS21dWrBEiF8mFm2fSwEskLhk9shV4Jkuz66

transaction T_A {input = _ output = 1BTC: fun(x). versig(kA; x)}

transaction T {
	input = T_A: sig(kA)
	output = 1BTC: fun(sigB, sigO). versig(kB, kO; sigB, sigO)
}

const sigO = ... //receive from Oracle

transaction T_B {
	input = T: sig(kB) sigO
	output = 1BTC: fun(x). versig(kB; x)
}

compile T T_B

In this smart contract, Bob waits to receive the signature sigO from Oscar, then he puts T_B on the blockchain (after setting its witness) to redeem T. In practice, oracles like the one needed in this contract are available as services in the Bitcoin ecosystem. Notice that, in case the event certified by the oracle never happens, the bitcoins within T are frozen forever. To avoid this situation, one can add a time constraint to the output script of T, as shown below.

transaction T {
        input = TA: sig(kA)
        output = 1BTC: fun(sigma, sigO). versig(kB, kO; sigma, sigO)
                                        || after date dateD : versig(kA;sigma)
}