Strike and HRF recently announced 3 bounties for development in the bitcoin ecosystem. The most interesting bounty in my opinion is the “stable channel” bounty.
I tweeted out a thread on how to implement this on my personal twitter account, and we have previously written about Lightning DLCs in March of 2020, but thought there was merit to publishing a new blog post about claiming the bounty published by HRF and Strike using Discreeet Log Contracts.
How a Discreet Log Contract works
For any discreet log contract, you need an oracle that will attest to the event you are interested in. For this challenge, the oracle needs to attest to the BTCUSD exchange rate. Here is an example of an oracle that does that.
Discreet Log Contracts are represented by outputs on a transaction. Here is the transaction graph for a DLC between Alice and Bob.
Similar to lightning, Alice and Bob can both contribute multiple utxos to fund the DLC. Inside of the DLC funding transaction, we have 3 outputs. Alice’s change output, Bob’s change output, and the funding output that represents the DLC. The funding output for the DLC can be spent by ONE of the off chain transactions on the right hand side. Depending upon what the oracle attests to, one of the offchain funding transactions will become valid. If the oracle doesn’t attest to anything, eventually the refund transaction will become valid to refund Alice & Bob their money.
Lifting DLCs to Lightning
To claim the HRF/Strike bounty, you need to copy this part of the DLC and embed it in the lightning networks commitment transaction. Like a puzzle piece, we need to fit the DLC transaction graph into the lightning commitment transaction. This means we need the DLC to be output on the commitment transaction next to the to_local output, to_remote output, and any inflight htlcs.
On the left hand side, we have the normal funding output for a lightning channel. In the middle, we have a lightning commitment transaction. Notice at the bottom of the commitment transaction, there is a new special type of output that represents the DLC funding output.
On the right hand side, we have all of the CETs that represent all of the possible outcomes for the bet.
When the oracle attests to the BTCUSD price, you will have two options
The cooperative case
Clear the DLC funding output from the lightning channel and assign the appropriate amount of money to the “to_local” and “to_remote” outputs. This is similar to the cooperative case in normal lightning operations
The non-cooperative case
This is similar to how you handle a non cooperative peer with normal lightning operations. You need to publish the commitment transaction onto the blockchain, and then use the oracle’s attestments to decrypt one of the CETs and spend the DLC funding output onchain.
It is important to note that the DLC funding output lives on the commitment transaction for the duration of the DLC. Funds do not move back and forth – the capital locked in the DLC funding output cannot be used for other purposes until the oracle attests to the BTCUSD price, or you and your peer cooperatively settle the output based on the fair market price of BTCUSD at time of settlement.
Here is the checklist of things you need to do and implement
- Find an oracle that attests to the BTCUSD market rate (oracle.suredbits.com)
- Understand how to represent a contract for difference using DLCs
- Modify a Lightning implementation so that it can support DLCs on a commitment transaction.
The hardest part will be (3), I highly recommend you limit scope on this task to have no routing, just a DLC between Alice & Bob which can satisfy the requirements from HRF/Strike.
This blog post omits certain real world considerations that would be needed to make a production grade implementation. For instance, you can’t spend from the DLC output on your lightning channel unless your counterparty is willing to renegotiate the DLC. If your counterparty isn’t cooperating, you aren’t able to spend from DLC output until the oracle attests. If the opensats board considers these as a requirement to achieve this bounty, we will follow up with another blog post.