Skip to content

Commit

Permalink
Merge pull request #6285 from guggero/btcec-v2-upgrade
Browse files Browse the repository at this point in the history
Bump btcec to v2, use integrated btcutil module
  • Loading branch information
guggero authored Mar 9, 2022
2 parents 8ee9fc8 + e84c7fb commit 262591c
Show file tree
Hide file tree
Showing 351 changed files with 2,441 additions and 1,306 deletions.
6 changes: 3 additions & 3 deletions autopilot/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"sync"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/lnwire"
)
Expand Down Expand Up @@ -731,7 +731,7 @@ func (a *Agent) executeDirective(directive AttachmentDirective) {
// We'll start out by attempting to connect to the peer in order to
// begin the funding workflow.
nodeID := directive.NodeID
pub, err := btcec.ParsePubKey(nodeID[:], btcec.S256())
pub, err := btcec.ParsePubKey(nodeID[:])
if err != nil {
log.Errorf("Unable to parse pubkey %x: %v", nodeID, err)
return
Expand Down
2 changes: 1 addition & 1 deletion autopilot/agent_constraints.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package autopilot

import (
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)

// AgentConstraints is an interface the agent will query to determine what
Expand Down
2 changes: 1 addition & 1 deletion autopilot/agent_constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/lnwire"
)

Expand Down
4 changes: 2 additions & 2 deletions autopilot/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"testing"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
)

type moreChansResp struct {
Expand Down
4 changes: 2 additions & 2 deletions autopilot/centrality_testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package autopilot
import (
"testing"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion autopilot/combinedattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package autopilot
import (
"fmt"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)

// WeightedHeuristic is a tuple that associates a weight to an
Expand Down
2 changes: 1 addition & 1 deletion autopilot/externalscoreattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"sync"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)

// ExternalScoreAttachment is an implementation of the AttachmentHeuristic
Expand Down
6 changes: 3 additions & 3 deletions autopilot/externalscoreattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package autopilot_test
import (
"testing"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/autopilot"
)

// randKey returns a random public key.
func randKey() (*btcec.PublicKey, error) {
priv, err := btcec.NewPrivateKey(btcec.S256())
priv, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}
Expand Down
22 changes: 12 additions & 10 deletions autopilot/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ package autopilot

import (
"bytes"
"math/big"
"encoding/hex"
"net"
"sort"
"sync/atomic"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)

var (
testSig = &btcec.Signature{
R: new(big.Int),
S: new(big.Int),
}
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
testRScalar = new(btcec.ModNScalar)
testSScalar = new(btcec.ModNScalar)
_ = testRScalar.SetByteSlice(testRBytes)
_ = testSScalar.SetByteSlice(testSBytes)
testSig = ecdsa.NewSignature(testRScalar, testSScalar)

chanIDCounter uint64 // To be used atomically.
)
Expand Down Expand Up @@ -344,7 +346,7 @@ func randChanID() lnwire.ShortChannelID {

// randKey returns a random public key.
func randKey() (*btcec.PublicKey, error) {
priv, err := btcec.NewPrivateKey(btcec.S256())
priv, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion autopilot/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package autopilot_test
import (
"testing"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/autopilot"
)

Expand Down
4 changes: 2 additions & 2 deletions autopilot/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package autopilot
import (
"net"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lnwire"
)

Expand Down
2 changes: 1 addition & 1 deletion autopilot/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"sync"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
Expand Down
4 changes: 2 additions & 2 deletions autopilot/prefattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
prand "math/rand"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
)

// minMedianChanSizeFraction determines the minimum size a channel must have to
Expand Down
8 changes: 3 additions & 5 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
)

Expand Down Expand Up @@ -252,9 +252,7 @@ func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
t1.Fatalf("unable to create channel: %v", err)
}
peerPubBytes := edge1.Peer.PubKey()
peerPub, err := btcec.ParsePubKey(
peerPubBytes[:], btcec.S256(),
)
peerPub, err := btcec.ParsePubKey(peerPubBytes[:])
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion autopilot/top_centrality.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package autopilot
import (
"runtime"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)

// TopCentrality is a simple greedy technique to create connections to nodes
Expand Down
4 changes: 2 additions & 2 deletions autopilot/top_centrality_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package autopilot
import (
"testing"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion blockcache/blockcache.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package blockcache

import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/neutrino/cache"
"github.com/lightninglabs/neutrino/cache/lru"
"github.com/lightningnetwork/lnd/lntypes"
Expand Down
2 changes: 1 addition & 1 deletion blockcache/blockcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"sync"
"testing"

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/neutrino/cache"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion brontide/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor"
Expand Down
30 changes: 5 additions & 25 deletions brontide/noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"math"
"time"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/hkdf"
Expand Down Expand Up @@ -63,7 +63,7 @@ var (
// ephemeralGen is the default ephemeral key generator, used to derive a
// unique ephemeral key for each brontide handshake.
ephemeralGen = func() (*btcec.PrivateKey, error) {
return btcec.NewPrivateKey(btcec.S256())
return btcec.NewPrivateKey()
}
)

Expand Down Expand Up @@ -500,7 +500,7 @@ func (b *Machine) RecvActOne(actOne [ActOneSize]byte) error {
copy(p[:], actOne[34:])

// e
b.remoteEphemeral, err = btcec.ParsePubKey(e[:], btcec.S256())
b.remoteEphemeral, err = btcec.ParsePubKey(e[:])
if err != nil {
return err
}
Expand Down Expand Up @@ -578,7 +578,7 @@ func (b *Machine) RecvActTwo(actTwo [ActTwoSize]byte) error {
copy(p[:], actTwo[34:])

// e
b.remoteEphemeral, err = btcec.ParsePubKey(e[:], btcec.S256())
b.remoteEphemeral, err = btcec.ParsePubKey(e[:])
if err != nil {
return err
}
Expand Down Expand Up @@ -654,7 +654,7 @@ func (b *Machine) RecvActThree(actThree [ActThreeSize]byte) error {
if err != nil {
return err
}
b.remoteStatic, err = btcec.ParsePubKey(remotePub, btcec.S256())
b.remoteStatic, err = btcec.ParsePubKey(remotePub)
if err != nil {
return err
}
Expand Down Expand Up @@ -890,23 +890,3 @@ func (b *Machine) ReadBody(r io.Reader, buf []byte) ([]byte, error) {
// buffer to decode the plaintext.
return b.recvCipher.Decrypt(nil, buf[:0], buf)
}

// SetCurveToNil sets the 'Curve' parameter to nil on the handshakeState keys.
// This allows us to log the Machine object without spammy log messages.
func (b *Machine) SetCurveToNil() {
if b.localStatic != nil {
b.localStatic.PubKey().Curve = nil
}

if b.localEphemeral != nil {
b.localEphemeral.PubKey().Curve = nil
}

if b.remoteStatic != nil {
b.remoteStatic.Curve = nil
}

if b.remoteEphemeral != nil {
b.remoteEphemeral.Curve = nil
}
}
16 changes: 8 additions & 8 deletions brontide/noise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"testing/iotest"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor"
Expand All @@ -23,7 +23,7 @@ type maybeNetConn struct {

func makeListener() (*Listener, *lnwire.NetAddress, error) {
// First, generate the long-term private keys for the brontide listener.
localPriv, err := btcec.NewPrivateKey(btcec.S256())
localPriv, err := btcec.NewPrivateKey()
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -56,7 +56,7 @@ func establishTestConnection() (net.Conn, net.Conn, func(), error) {

// Nos, generate the long-term private keys remote end of the connection
// within our test.
remotePriv, err := btcec.NewPrivateKey(btcec.S256())
remotePriv, err := btcec.NewPrivateKey()
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestConcurrentHandshakes(t *testing.T) {

// Now, construct a new private key and use the brontide dialer to
// connect to the listener.
remotePriv, err := btcec.NewPrivateKey(btcec.S256())
remotePriv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to generate private key: %v", err)
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestBolt0008TestVectors(t *testing.T) {
t.Fatalf("unable to decode hex: %v", err)
}
initiatorPriv, _ := btcec.PrivKeyFromBytes(
btcec.S256(), initiatorKeyBytes,
initiatorKeyBytes,
)
initiatorKeyECDH := &keychain.PrivKeyECDH{PrivKey: initiatorPriv}

Expand All @@ -337,7 +337,7 @@ func TestBolt0008TestVectors(t *testing.T) {
t.Fatalf("unable to decode hex: %v", err)
}
responderPriv, responderPub := btcec.PrivKeyFromBytes(
btcec.S256(), responderKeyBytes,
responderKeyBytes,
)
responderKeyECDH := &keychain.PrivKeyECDH{PrivKey: responderPriv}

Expand All @@ -353,7 +353,7 @@ func TestBolt0008TestVectors(t *testing.T) {
return nil, err
}

priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), eBytes)
priv, _ := btcec.PrivKeyFromBytes(eBytes)
return priv, nil
})
responderEphemeral := EphemeralGenerator(func() (*btcec.PrivateKey, error) {
Expand All @@ -364,7 +364,7 @@ func TestBolt0008TestVectors(t *testing.T) {
return nil, err
}

priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), eBytes)
priv, _ := btcec.PrivKeyFromBytes(eBytes)
return priv, nil
})

Expand Down
Loading

0 comments on commit 262591c

Please sign in to comment.