Research/Bitcoin Dev Archive / lightning-dev list
Anchor (funding) transactions without segregated witness
3 messages, Jul 7 to 14, 2015. Started by Rusty Russell.
Rusty Russell (2), Joseph Poon
Hi all,
http://ozlabs.org/~rusty/diagrams/dual-anchor.svg
Since I posted my first design of HTLC yesterday, and noted that it doesn't seem to require new sighash modes, I went back and revisited my discarded ideas for establishing an anchor without new sighash modes. If we can do that (and my HTLC design stands up), then lightning network only needs OP_CHECKSEQUENCEVERIFY and OP_CHECKLOCKTIMEVERIFY, which are fairly low-albedo soft forks.
To recap: the draft paper and current code trade signatures on the first commitment transaction before signing the anchor transaction. That way you are sure to have a way to get your funds back before you put them into the anchor. (The paper uses the term funding transaction; I prefer anchor).
This can't be done in normal bitcoin, as you don't know the TXID of the anchor until after its inputs are signed, so you can't sign the commitment transaction without knowing the txid of the anchor. It works in Elements Alpha because they have segregated witness; the txid of the anchor doesn't hash the input scripts. It could work in bitcoin with a softfork of a new CHECKSIG2 which has new signature modes, but there's not even a BIP for that, and there are so many things that could be done there that it's likely to be long delayed.
So, how can we solve this? Well, we can have two anchors instead of one. I put my inputs into my anchor, you put your inputs into yours: each one requires both our signatures to spend. The commitment tx has two inputs, one for each.
We can trade anchor txids, so we can both sign the commitment tx. But now one of could withhold our anchor, leaving us with an unusable commitment tx and stuck output from an anchor. We need a way to get the funds back in that "abort" case.
Thus we add an intermediary transaction (called "Escape" transactions) which spends the 2 of 2 anchor output, but can be spent either by 2 of 2 (ie. the commitment tx), OR back to the anchor owner after a delay (using OP_CHECKSEQUENCEVERIFY).
The order is as follows:
1) We both trade anchor txids and amounts. 2) We both trade signatures for the escape transactions, so either one can broadcast them. 3) Now we are sure to be able to recover our funds, we each broadcast our anchor txs. 4) If the other side broadcasts their escape transaction, abort and broadcast our escape transaction. After the timeout, we can spend it. 5) If the other side doesn't broadcast their anchor tx, abort and broadcast our escape transaction. 6) Otherwise, when the anchor txs reach the required depth, we exchange signatures for the commitment transaction. 7) If the other side broadcasts either escape transaction, broadcast the other escape transaction and the commitment tx as normal (this is a unilateral close) before they can reclaim their anchor funds.
I think this works, and doesn't add any new requirements; you now need to watch out for escape txs being broadcast instead of commitment txs.
The downside is that there are 3 extra transactions involved; 1 extra for the channel open, and 2 for the channel close.
Feedback, optimizations, horrible holes? Rusty.
On Tue, Jul 07, 2015 at 03:39:39PM +0930, Rusty Russell wrote:
Quoted text (1 line)
> Feedback, optimizations, horrible holes?
I think this model works! As soon as OP_CHECKLOCKTIMEVERIFY soft-forks into bitcoin, a basic lightning implementation may be theoretically possible in real bitcoin (with some significant caveats)!
I think Thaddeus Dryja came up with a similar implementation to resolve malleability in multisig (involving a clock and 2-input/2-output). However, I think a true malleability fix is still ideal.
To complete the thought, I think it's possible to make the Commitment Transactions malleability-safe under this construction.
Quoted text (17 lines)
> The order is as follows: > > 1) We both trade anchor txids and amounts. > 2) We both trade signatures for the escape transactions, so either one > can broadcast them. > 3) Now we are sure to be able to recover our funds, we each broadcast > our anchor txs. > 4) If the other side broadcasts their escape transaction, abort and > broadcast our escape transaction. After the timeout, we can spend > it. > 5) If the other side doesn't broadcast their anchor tx, abort and > broadcast our escape transaction. > 6) Otherwise, when the anchor txs reach the required depth, we exchange > signatures for the commitment transaction. > 7) If the other side broadcasts either escape transaction, broadcast > the other escape transaction and the commitment tx as normal (this is > a unilateral close) before they can reclaim their anchor funds.
To create the Commitment Transaction (in step 6 and all future Commitment Transactions), it requires spending from the two inputs separately and the output would require having OP_CLTV or OP_CSV in the script output to determine whether a Commitment has been revoked. This is necessary since one cannot be fully confident about the Transaction ID beforehand.
If the inputs are 0.5 Alice and 0.5 Bob, the first Commitment Transaction would refund 0.5 to Alice and 0.5 to Bob. As always, there are a pair of Commitment Transactions per commitment state. Presume the current block height is 350,000 and the channel closes at 355,760.
The Commitment Transaction which only Alice can broadcast, Commitment 1a, would have the following outputs:
0. 0.5 BTC BobKey 1. 0.5 BTC OP_IF <AlicePubKey> OP_CHECKSIGVERIFY <355,760> OP_CLTV OP_DROP OP_ELSE OP_HASH160 <RevocationHash> OP_EQUALVERIFY <BobPubKey> OP_CHECKSIGVERIFY OP_END
This is the general idea at least (haven't checked the script). Bob gets all his money if Alice broadcasts it immediately because Alice is attesting Bob should get *at least* 0.5 BTC. For the second output (output 1), the first path gives Alice the funds at channel expiration. The second path is so if the current Commitment transaction is not Commitment 1 and Alice should lose all her money for incorrectly broadcasting Commitment 1. Alice does this by attesting to Bob she wouldn't broadcast Commitment 1 by giving the RevocationPreimage which is hashed into RevocationHash.
Bob also has a Commitment Transaction which is the opposite (Alice's funds get paid immediately, Bob's funds is encumbered by time).
The purpose of doing this type of construction instead of using nLockTime on the transactions spending from the Commitment Transaction is so that each output only requires one signature. By having only one signature, malleability concerns can be mitigated, since that single party can simply resign and is not dependent upon the cooperation of the counterparty if the Commitment Transaction itself gets mutated. Since the Commitment Transaction is only build after the Anchor and Escape transactions exist, then this construction will allow for Lightning Network channels to exist with OP_CLTV, with the caveat that with uncooperative counterparties, you will have to wait until channel expiration to get your money back. However, it does mean that playing with LN is a possibility on the real bitcoin chain in the near future.
Very cool, Rusty!
Joseph Poon <joseph at lightning.network> writes:
Quoted text (6 lines)
> On Tue, Jul 07, 2015 at 03:39:39PM +0930, Rusty Russell wrote: >> Feedback, optimizations, horrible holes? > > I think this model works! As soon as OP_CHECKLOCKTIMEVERIFY soft-forks > into bitcoin, a basic lightning implementation may be theoretically > possible in real bitcoin (with some significant caveats)!
We could. I think OP_CHECKSEQUENCEVERIFY (ie. relative CTLV) would reduce those caveats enough that we should assume that, too (if that proves too optimistic, we can return to global timeous and OP_CLTV).
[ BTW, Joseph and I had a deep and complex discussion over the last week via private email. I'm summarizing here. ]
It *almost* works, but once you drew my attention to the malleability issue, it's clear that the escape transaction(s) can be malleated[1], causing the commitment transaction to be useless.
Then I came up with another variant, which Joseph approved of. And then, of course, improved upon! I'm writing up final result now.
Thanks! Rusty.