Research/Bitcoin Dev Archive / lightning-dev list
Breach of contract?
7 messages, Jul 25 to 30, 2015. Started by Christopher Jämthagen.
Joseph Poon (3), Rusty Russell (3), Christopher Jämthagen
An HTML attachment was scrubbed... URL: <http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20150725/ebfeffe0/attachment.html>
On Sat, Jul 25, 2015 at 10:59:16PM +0200, Christopher Jamthagen wrote:
Quoted text (7 lines)
> <div>According to the whitepaper: " If three days have elapsed, > then the above clause is null and void and the clearing process is > invalidated, both parties must not attempt to settle and claim payment > after three days." But clearly there is nothing stopping Bob from > taking the HTLC output when Alice is forced to broadcast the > commitment transaction, even if it is supposed to be null and > void.</div>
Hi Christopher,
The design of the HTLCs have a contestation period built-in where the party which broadcasts the Commitment Transaction must wait a period of time before the payment goes back to themselves.
I think your concern may have some implications for Rusty's dual anchor/funding version. I had incorrectly stated that it might be possible to do it only with OP_CLTV, but it clearly requires both OP_CLTV and OP_CSV.
There's more information being attested when relying on OP_CSV for the HTLC without a transaction chained 2 levels deep. It will require greater time delay between each hop in the payment to account for the relative time to prove whether the Commitment has been revoked. This greater time creates a tradeoff which requires each channel participant (for every hop) to watch the blockchain at a more frequent interval, since that OP_CSV value is intrinsically linked to the payment.
With a SIGHASH_NOINPUT (or similar) model having transactions two-deep, this contestation period can be independent of the actual HTLC payments. In effect, the first transaction spending from the HTLC validates whether the preimages are known, the second is whether the Commitment itself is invalidated. With separated anchor/funding, those two steps are combined inside the Commitment Transaction -- AFAIK, (minus the above tradeoffs) it still works though, but I'll double-check.
Christopher Jamthagen <cjamthagen at gmx.com> writes:
Quoted text (4 lines)
> When a HTLC's CLTV has expired, the receiver of the HTLC should not be > able to use the pre-image to spend the output from a commitment > transaction that has not been invalidated. > Assume a circuit is established: Alice -> Bob -> Dave
Yes, I assume that the HTLC gets eliminated by a commitment transaction update at (or before) that time.
We could add an additional delay for this case, but it seems like overengineering?
Cheers, Rusty.
On Mon, Jul 27, 2015 at 11:20:54AM +0930, Rusty Russell wrote:
Quoted text (5 lines)
> Yes, I assume that the HTLC gets eliminated by a commitment transaction > update at (or before) that time. > > We could add an additional delay for this case, but it seems like > overengineering?
To ensure that the older version of the transaction does not get broadcast through a credible threat, there needs to be some contestation period for one's own HTLC when one is redeeming funds.
However, there are less elegant solutions that are possible as a stop-gap before a full malleability fix which permits you to generate child transactions before signing the parent.
Current/unexpired HTLCs will have the same payout and enforcement, but there is a risk of broadcasting older Commitments and stealing the HTLC payout, e.g. transactions that are believed to be timed out but whose preimages are known after-the-fact. Theft of the HTLC via broadcast of expired Commitments can be mitigated by having some funds in reserve available on one's own channel balance to ensure honesty. In effect, the total value of the HTLCs must be below one's own reserve balance (for both parties). The reserve balance must not be used ever.
Note that this presumes dual-funder. I'll go into single-funder model later.
For example, if Alice and Bob have a channel with the latest Commitment: 0.49 to Alice (0.02 in permanent reserve) 0.50 to Bob (0.02 in permanent reserve) 0.01 HTLC Alice to Bob
This is a valid HTLC, since Alice's current channel balance not allocated to HTLCs is 0.49. This balance must be at or above 0.02 at all times throughout the life of the channel, until Alice closes it out or does a final payment to zero it out and close. Similarly, Bob also must maintain a balance of 0.02 throughout the life of the channel.
The sum of all HTLCs going from Alice to Bob must be at or (preferably) below this 0.02 limit at all times before closing out the channel.
The result is if Alice broadcasts an old Commitment, Bob is assured that the balance of the HTLC will be at or below 0.02. The maximum Alice can send will be 0.98 in the channel, so even if she attempts to steal the HTLC, Bob can be made whole by taking back all his funds, as well as all of Alice's funds as penalty. Even if he is unable to take back the HTLC, he will take all of Alice's funds in reserve, which is less than the balance of all HTLCs in transit from Alice to Bob at all times throughout the historical life of the channel.
Depending on how willing you are to enforce the HTLC past this point, you can make the script substantially simpler, as well.
To fund this using single-funder, one should be very cognizant of risks related to systemic risks related to trust asymmetry of the channel counterparties. If we construct a model using single-funder, it requires very shallow rebalancing of funding for symmetric trust, i.e. Alice opens a channel to Bob first, then Bob opens a channel to Alice. This initial channel funding would probably have a very high OP_CSV value. For the OP_CSV value to be this high and functional without DoS risks, it requires the number of LN hops to be fairly low during this channel setup phase (but won't matter after), as they may be potentially locking up money for a longer period of time if the HTLC payment is not fulfilled). For OP_CLTV only (without OP_CSV) I think it'll be to the point where it *requires* setting up two channels with the same person.
Personally, I have some reservations for models which have funds in permanent reserve, but this model is a fairly good stop-gap before a real malleability fix (SIGHASH_NOINPUT or segregated witness). This model should be able to work with just OP_CLTV (and with OP_CSV too), but may not be quite as fun. Also, to maximize fun under this model to mitigate when a counteparty is a jerk, you should always make sure the amount in permanent reserve is *always above* (not equal to) the value encumbered in HTLCs.
Joseph Poon <joseph at lightning.network> writes:
Quoted text (10 lines)
> On Mon, Jul 27, 2015 at 11:20:54AM +0930, Rusty Russell wrote: >> Yes, I assume that the HTLC gets eliminated by a commitment transaction >> update at (or before) that time. >> >> We could add an additional delay for this case, but it seems like >> overengineering? > > To ensure that the older version of the transaction does not get > broadcast through a credible threat, there needs to be some contestation > period for one's own HTLC when one is redeeming funds.
The rule, AFAICT, is: if it's A's commitment transaction, all outputs which are redeemable by A must be delayed.
For HTLCs, this means: 1) Timeout returns for HTLCs A initiates must be OP_CSV delayed. 2) Payments for HTLCs A receives must be delayed.
I just noticed the scripts in the 0.1 draft are a bit messed up; in particular they're missing a delay. Here's the (fixed!) A offers HTLC to B case:
(See https://github.com/ElementsProject/lightning/blob/master/doc/ )
HTLC Sender Redeemscript (A):
OP_HASH160 OP_DUP Replace top element with two copies of its hash
<R-HASH> OP_EQUAL Test if they supplied the HTLC R value
OP_SWAP <COMMIT-REVOCATION-HASH> OP_EQUAL OP_ADD
Or the commitment revocation hash
OP_IF If any hash matched.
<KEY-B> Pay to B.
OP_ELSE Must be A, after HTLC has timed out.
<HTLC-TIMEOUT> OP_CHECKLOCKTIMEVERIFY OP_DROP
Ensure (absolute) time has passed.
<DELAY> OP_CHECKSEQUENCEVERIFY OP_DROP
Delay gives B enough time to use revocation if it has it.
<KEY-A> Pay to A.
OP_ENDIF
OP_CHECKSIG Verify A or B's signature is correct.
HTLC Receiver Redeemscript (B):
OP_HASH160 OP_DUP Replace top element with two copies of its hash
<R-HASH> OP_EQUAL B redeeming the contract, using R preimage?
OP_IF
OP_DROP Remove extra hash
<DELAY> OP_CHECKSEQUENCEVERIFY OP_DROP
Delay gives A enough time to use revocation if it has it.
<KEY-B> Pay to B
OP_ELSE
<COMMIT-REVOCATION-HASH> OP_EQUAL
If the commit has been revoked.
OP_NOTIF
If not, you need to wait for timeout.
<HTLC-TIMEOUT> OP_CHECKLOCKTIMEVERIFY OP_DROP
Ensure (absolute) time has passed.
OP_ENDIF
<KEY-A> Pay to A OP_ENDIF OP_CHECKSIG Verify A or B's signature is correct.
Quoted text (4 lines)
> Current/unexpired HTLCs will have the same payout and enforcement, but > there is a risk of broadcasting older Commitments and stealing the HTLC > payout, e.g. transactions that are believed to be timed out but whose > preimages are known after-the-fact.
I see that?
If A broadcast an older commitment, B can steal the HTLC payout, but that's as designed.
Cheers, Rusty.
On Tue, Jul 28, 2015 at 11:08:05AM +0930, Rusty Russell wrote:
Quoted text (7 lines)
> For HTLCs, this means: > 1) Timeout returns for HTLCs A initiates must be OP_CSV delayed. > 2) Payments for HTLCs A receives must be delayed. > > I just noticed the scripts in the 0.1 draft are a bit messed up; in > particular they're missing a delay. Here's the (fixed!) A offers HTLC > to B case:
Ah ok, cool!
Quoted text (1 line)
> [scripts]
After thinking about this for a bit, there's two implications for this script:
1. De-facto requires constantly watching the blockchain for a very low interval. If Alice and Bob establish a channel, make a couple payments, and now the balance of the channel is now 0 to Alice and 1 BTC to Bob, if Bob doesn't constantly watch the chain, he can lose money. If the HTLC-TIMEOUT is defined as 1 day, Alice can broadcast an old Commitment and then hope Bob isn't paying attention and steal some money. In effect, the maximum time between watching the chain will be the minimum HTLC-TIMEOUT throughout the life of the channel when the channel balance is currently tiled heavily in one direction.
2. Probably at the minimum doubles the HTLC timelock on LN payments. If there is a minimum amount of time to wait to redeem funds (or receive a refund), then the HTLC timeout must give you sufficient amount of time to redeem as well. I suspect the amount of time necessary is about the same since they're both dependent upon the estimated amount of time to enter into the blockchain. If that's the case, doubling the HTLC timeouts has some implications since it'll result in higher fees as a downside, but might bias towards less graph centralization as well.
Fundamentally, the cause is derived from the fact that the HTLC timeout and the OP_CSV revocation are inextricably linked.
Number 1 is more relevant to me (IMO), which is why I brought up the reserve thing. I'm not so into the reserve balance concept, simply because it severely limits the amount of transactional flow available at once (it also limits the number of retries/multiplexing sends), which matters more for liquidity providers (that model can reduce available liquidity by 4x in best-case scenarios).
Joseph Poon <joseph at lightning.network> writes:
Quoted text (25 lines)
> On Tue, Jul 28, 2015 at 11:08:05AM +0930, Rusty Russell wrote: >> For HTLCs, this means: >> 1) Timeout returns for HTLCs A initiates must be OP_CSV delayed. >> 2) Payments for HTLCs A receives must be delayed. >> >> I just noticed the scripts in the 0.1 draft are a bit messed up; in >> particular they're missing a delay. Here's the (fixed!) A offers HTLC >> to B case: > > Ah ok, cool! > >> [scripts] > > After thinking about this for a bit, there's two implications for this > script: > > 1. De-facto requires constantly watching the blockchain for a very low > interval. If Alice and Bob establish a channel, make a couple payments, > and now the balance of the channel is now 0 to Alice and 1 BTC to Bob, > if Bob doesn't constantly watch the chain, he can lose money. If the > HTLC-TIMEOUT is defined as 1 day, Alice can broadcast an old Commitment > and then hope Bob isn't paying attention and steal some money. In > effect, the maximum time between watching the chain will be the minimum > HTLC-TIMEOUT throughout the life of the channel when the channel balance > is currently tiled heavily in one direction.
HTLC-TIMEOUT is an absolute time/block, not relative. Thus OP_CHECKLOCKTIMEVERIFY is a noop for old HTLCs.
So, if A broadcasts, they need to wait <DELAY> to spend. I don't think I added anything new here?
Quoted text (8 lines)
> 2. Probably at the minimum doubles the HTLC timelock on LN payments. If > there is a minimum amount of time to wait to redeem funds (or receive a > refund), then the HTLC timeout must give you sufficient amount of time > to redeem as well. I suspect the amount of time necessary is about the > same since they're both dependent upon the estimated amount of time to > enter into the blockchain. If that's the case, doubling the HTLC > timeouts has some implications since it'll result in higher fees as a > downside, but might bias towards less graph centralization as well.
Yes, the effective minimum HTLC-TIMEOUT is "current-time + <DELAY>", because if A broadcasts its commitment tx, the HTLC stays redeemable until A spends it (which it can't do until after <DELAY>).
But it's not clear that this "htlc timeout doubling" applies to every step on the route, it seems to just add one?
Or am I missing something else?
Cheers, Rusty.