Previously, the concept of atomic cross chain currency swapping was developed:
https://en.bitcoin.it/wiki/Atomic_cross-chain_tradingToday, I have invented a way to do atomic cross chain options.
For example, someone wants to buy an options contract which gives him the right to exchange x bitcoins for y dogecoins before some specified date in the future. This protocol allows you to do this in a completely decentralized, p2p manner
The protocol is as follows:
Terminology: A is the buyer of the option, and B is the underwriter of the option.
A’s public key refers to A’s altcoin public key.
B’s public key refers to B’s bitcoin public key.
w refers to the amount of Bitcoin A pays to B in exchange for altcoins
v refers to the amount of altcoin B pays to A in exchange for bitcoins
f refers to the fee A pays B in exchange for the option contract
n refers to the number of hours until expiry of the contract
Protocol:
A picks a random number x
B picks a random number y
A creates TX1: "Pay w BTC to <B's public key> if (x for H(x) known and signed by B) or (signed by A & B)"
A creates TX2: "Pay w BTC from TX1 to <A's public key>, locked n+48 hours in the future, signed by A"
A sends TX2 to B
B signs TX2 and returns to A
1) A submits TX1 to the network
B creates TX3: "Pay v alt-coins to <A-public-key> if (x for H(x) known and signed by A and H(y) known and signed by A) or (signed by A & B)“
B creates TX4: "Pay v alt-coins from TX3 to <B's public key>, locked n+24 hours in the future, signed by B"
B sends TX4 to A
A signs TX4 and sends back to B
2) B submits TX3 to the network
3) A creates TX5: “Pay f BTC to <B’s public key> if (y for H(y) known and signed by B)”
A submits TX5 to the network
4) B spends TX5 giving y
5) A spends TX3 giving x
6) B spends TX1 using x
This is atomic (with timeout). If the process is halted, it can be reversed no matter when it is stopped.
Before 1: Nothing public has been broadcast, so nothing happens
Between 1 & 2: A can use refund transaction after n+72 hours to get his money back
Between 2 & 3: B can get refund after n+24 hours. A has n+24 more hours to get his refund
Between 3 and 4: If B does not spend Tx5, A can use refund transaction after n+72 hours to get his money back
Between 4 and 5: A now knows both x and y, allowing him to spend TX3.
B can get refund after n+24 hours. A has 24 more hours to get his refund
After 5: Transaction is completed
- A must spend his new coin within 24 hours or B can claim the refund and keep his coins
- B must spend his new coin within 72 hours or A can claim the refund and keep his coins