From a14a15641bd465669d36f2ee6ec29854b21656ae Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 14 Nov 2017 20:26:51 -0800 Subject: [PATCH] lnwire: add new HtlcPoint to OpenChannel and AcceptChannel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we begin implementing the latest spec change to reduce the attack surface on online channels. In this commit, we introduce a distinct HTLC base point which will be used to sign the second-level HTLC transactions for each active HLTC on the commitment transaction of the remote node. With this, we allow the commitment key to remain offline, as it isn’t needed in routine channel updates, unless we need to go to chain. --- lnwire/accept_channel.go | 12 ++++++++++-- lnwire/lnwire_test.go | 10 ++++++++++ lnwire/open_channel.go | 12 ++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lnwire/accept_channel.go b/lnwire/accept_channel.go index f738e3c0..7248494c 100644 --- a/lnwire/accept_channel.go +++ b/lnwire/accept_channel.go @@ -75,6 +75,12 @@ type AcceptChannel struct { // where they claim funds. DelayedPaymentPoint *btcec.PublicKey + // HtlcPoint is the base point used to derive the set of keys for this + // party that will be used within the HTLC public key scripts. This + // value is combined with the receiver's revocation base point in order + // to derive the keys that are used within HTLC scripts. + HtlcPoint *btcec.PublicKey + // FirstCommitmentPoint is the first commitment point for the sending // party. This value should be combined with the receiver's revocation // base point in order to derive the revocation keys that are placed @@ -105,6 +111,7 @@ func (a *AcceptChannel) Encode(w io.Writer, pver uint32) error { a.RevocationPoint, a.PaymentPoint, a.DelayedPaymentPoint, + a.HtlcPoint, a.FirstCommitmentPoint, ) } @@ -128,6 +135,7 @@ func (a *AcceptChannel) Decode(r io.Reader, pver uint32) error { &a.RevocationPoint, &a.PaymentPoint, &a.DelayedPaymentPoint, + &a.HtlcPoint, &a.FirstCommitmentPoint, ) } @@ -145,6 +153,6 @@ func (a *AcceptChannel) MsgType() MessageType { // // This is part of the lnwire.Message interface. func (a *AcceptChannel) MaxPayloadLength(uint32) uint32 { - // 32 + (8 * 4) + (4 * 1) + (2 * 2) + (33 * 5) - return 237 + // 32 + (8 * 4) + (4 * 1) + (2 * 2) + (33 * 6) + return 270 } diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 191a6697..d6b7528a 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -188,6 +188,11 @@ func TestLightningWireProtocol(t *testing.T) { t.Fatalf("unable to generate key: %v", err) return } + req.HtlcPoint, err = randPubKey() + if err != nil { + t.Fatalf("unable to generate key: %v", err) + return + } req.FirstCommitmentPoint, err = randPubKey() if err != nil { t.Fatalf("unable to generate key: %v", err) @@ -233,6 +238,11 @@ func TestLightningWireProtocol(t *testing.T) { t.Fatalf("unable to generate key: %v", err) return } + req.HtlcPoint, err = randPubKey() + if err != nil { + t.Fatalf("unable to generate key: %v", err) + return + } req.FirstCommitmentPoint, err = randPubKey() if err != nil { t.Fatalf("unable to generate key: %v", err) diff --git a/lnwire/open_channel.go b/lnwire/open_channel.go index 9f7305e7..950752eb 100644 --- a/lnwire/open_channel.go +++ b/lnwire/open_channel.go @@ -102,6 +102,12 @@ type OpenChannel struct { // where they claim funds. DelayedPaymentPoint *btcec.PublicKey + // HtlcPoint is the base point used to derive the set of keys for this + // party that will be used within the HTLC public key scripts. This + // value is combined with the receiver's revocation base point in order + // to derive the keys that are used within HTLC scripts. + HtlcPoint *btcec.PublicKey + // FirstCommitmentPoint is the first commitment point for the sending // party. This value should be combined with the receiver's revocation // base point in order to derive the revocation keys that are placed @@ -141,6 +147,7 @@ func (o *OpenChannel) Encode(w io.Writer, pver uint32) error { o.RevocationPoint, o.PaymentPoint, o.DelayedPaymentPoint, + o.HtlcPoint, o.FirstCommitmentPoint, o.ChannelFlags, ) @@ -168,6 +175,7 @@ func (o *OpenChannel) Decode(r io.Reader, pver uint32) error { &o.RevocationPoint, &o.PaymentPoint, &o.DelayedPaymentPoint, + &o.HtlcPoint, &o.FirstCommitmentPoint, &o.ChannelFlags, ) @@ -186,6 +194,6 @@ func (o *OpenChannel) MsgType() MessageType { // // This is part of the lnwire.Message interface. func (o *OpenChannel) MaxPayloadLength(uint32) uint32 { - // (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 5) + 1 - return 286 + // (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 6) + 1 + return 319 }