Skip to content

Commit

Permalink
Merge pull request #13 from stroomnetwork/migration_to_frost_9
Browse files Browse the repository at this point in the history
Migrated btcwallet to frost v0.0.9
  • Loading branch information
diminio1 authored Jun 1, 2024
2 parents 4a8783a + a4bbfff commit 5557678
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
fail-fast: false
matrix:
unit_type:
- unit-race
#- unit-race
- unit-cover
steps:
- name: extract bitcoind from docker image
Expand Down
26 changes: 13 additions & 13 deletions frost/frost.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stroomnetwork/frost/approver"
frostConfig "github.com/stroomnetwork/frost/config"
"github.com/stroomnetwork/frost/crypto"
"github.com/stroomnetwork/frost/networking"
"github.com/stroomnetwork/frost/network"
"github.com/stroomnetwork/frost/storage"
_ "net/http/pprof" // nolint:gosec
"time"
Expand All @@ -27,7 +27,7 @@ func NewApprovalRequests() *ApprovalRequests {
}
}

func GetValidators(n int, k int) []*frost.Signer {
func GetValidators(n int, k int) []*frost.NetworkSigner {
createStorageFunc := func() (storage.Storage, error) {
return storage.NewInMemoryStorage(), nil
}
Expand All @@ -38,7 +38,7 @@ func GetValidators(n int, k int) []*frost.Signer {
return validators
}

func SetupInMemoryNetworkWithGeneratedKeys(n int, k int, createStorage func() (storage.Storage, error)) []*frost.Signer {
func SetupInMemoryNetworkWithGeneratedKeys(n int, k int, createStorage func() (storage.Storage, error)) []*frost.NetworkSigner {

pubKeys := make([]*btcec.PublicKey, n)
privKeys := make([]*btcec.PrivateKey, n)
Expand All @@ -52,9 +52,9 @@ func SetupInMemoryNetworkWithGeneratedKeys(n int, k int, createStorage func() (s
return createSigners(createStorage, nodes, bindingInfos)
}

func createSigners(createStorage func() (storage.Storage, error), nodes []networking.Node, bindingInfos []frostConfig.BindingInfo) []*frost.Signer {
func createSigners(createStorage func() (storage.Storage, error), nodes []network.Node, bindingInfos []frostConfig.BindingInfo) []*frost.NetworkSigner {
n := len(nodes)
signers := make([]*frost.Signer, n)
signers := make([]*frost.NetworkSigner, n)
for i := 0; i < n; i++ {
st, _ := createStorage()

Expand All @@ -71,14 +71,14 @@ func createSigners(createStorage func() (storage.Storage, error), nodes []networ

// signers[i] is the validator(or frost signer).
signers[i], _ = frost.CreateSigner(signerParams)
_ = signers[i].Start()
signers[i].Start()
}
time.Sleep(10 * time.Millisecond)

return signers
}

func SetupInMemoryNetworkWithProvidedKeys(k int) ([]networking.Node, []frostConfig.BindingInfo) {
func SetupInMemoryNetworkWithProvidedKeys(k int) ([]network.Node, []frostConfig.BindingInfo) {

privKeys := crypto.GetTestPrivateKeys()
n := len(privKeys)
Expand All @@ -91,22 +91,22 @@ func SetupInMemoryNetworkWithProvidedKeys(k int) ([]networking.Node, []frostConf
return SetupInMemoryNetwork(k, pubKeys, privKeys)
}

func SetupInMemoryNetwork(k int, pubKeys []*btcec.PublicKey, privKeys []*btcec.PrivateKey) ([]networking.Node, []frostConfig.BindingInfo) {
func SetupInMemoryNetwork(k int, pubKeys []*btcec.PublicKey, privKeys []*btcec.PrivateKey) ([]network.Node, []frostConfig.BindingInfo) {
n := len(pubKeys)
network := networking.NewInMemoryNetwork()
nodes := make([]networking.Node, n)
inMemoryNetwork := network.NewInMemoryNetwork()
nodes := make([]network.Node, n)

for i := 0; i < n; i++ {
nodes[i], _ = network.NewNode(pubKeys[i])
nodes[i], _ = inMemoryNetwork.NewNode(pubKeys[i])
}

bindingInfos := make([]frostConfig.BindingInfo, n)
for i := 0; i < n; i++ {
// bindingConfig contains information about the binding of this validator to the validators network.
// bindingConfig contains information about the binding of this validator to the validators inMemoryNetwork.
bindingConfig := frostConfig.NewBindingConfig(privKeys[i], pubKeys, k)

// bi is the binding information of this validator.
// it is used for the generation of the bound keys which are the original keys modified with this specific network information)
// it is used for the generation of the bound keys which are the original keys modified with this specific inMemoryNetwork information)
bi, _ := bindingConfig.GetBindingInfo()
bindingInfos[i] = *bi
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/lightningnetwork/lnd/ticker v1.0.0
github.com/lightningnetwork/lnd/tlv v1.0.2
github.com/stretchr/testify v1.8.4
github.com/stroomnetwork/frost v0.0.8
github.com/stroomnetwork/frost v0.0.9
golang.org/x/crypto v0.22.0
golang.org/x/net v0.24.0
golang.org/x/term v0.19.0
Expand All @@ -41,6 +41,7 @@ require (
github.com/lightningnetwork/lnd/clock v1.0.1 // indirect
github.com/lightningnetwork/lnd/queue v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/steveyen/gkvlite v0.0.0-20141117050110-5b47ed6d7458 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/steveyen/gkvlite v0.0.0-20141117050110-5b47ed6d7458 h1:xPexFI9EsTjMbQAW0Z7414/Y6N6jtcIiL2QG1OIG0Ro=
github.com/steveyen/gkvlite v0.0.0-20141117050110-5b47ed6d7458/go.mod h1:I50Pwzl9dKZDA6bxpAzy+WYhEbW4yDMkh6/G6iRoock=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand All @@ -132,6 +134,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stroomnetwork/frost v0.0.8 h1:7p119MT7uMwfc8m5kkzhXiohhBwC9lh17IsIln7Dm8w=
github.com/stroomnetwork/frost v0.0.8/go.mod h1:PLGdtwk0v3polO0YQDVvu6xIrlqWaWneEHXGLSh2sNU=
github.com/stroomnetwork/frost v0.0.9 h1:JZH/mmA0hqqnZUC9kz0Vzm03pSOD8kf1Ge4zIVIlMtw=
github.com/stroomnetwork/frost v0.0.9/go.mod h1:Dlb0hdxTQ76mdyWSmI8xK3+MLu+cDZnJTa9pzzjo9uQ=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
Expand Down
2 changes: 1 addition & 1 deletion run/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
cfg *config
)

func InitWallet(signer frost.ISigner, pk1, pk2 *btcec.PublicKey, bitcoindConfig *chain.BitcoindConfig) (*wallet.Wallet, error) {
func InitWallet(signer frost.Signer, pk1, pk2 *btcec.PublicKey, bitcoindConfig *chain.BitcoindConfig) (*wallet.Wallet, error) {
// Load configuration and parse command line. This function also
// initializes logging and configures it accordingly.
tcfg, _, err := loadConfig()
Expand Down
4 changes: 2 additions & 2 deletions run/signer_with_wallet_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func Example() {
runtime.GOMAXPROCS(runtime.NumCPU())

validators := frost.GetValidators(5, 3)
pk1, err := validators[0].MakePubKey("test1")
pk1, err := validators[0].RequestPubKey("test1")
if err != nil {
log.Info(err)
return
}

pk2, err := validators[0].MakePubKey("test2")
pk2, err := validators[0].RequestPubKey("test2")
if err != nil {
log.Info(err)
return
Expand Down
4 changes: 2 additions & 2 deletions wallet/frost_signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func TestFrostSigning(t *testing.T) {
defer cleanup()

validators := frost.GetValidators(5, 3)
pk1, err := validators[0].MakePubKey("test1")
pk1, err := validators[0].RequestPubKey("test1")
require.NoError(t, err)
require.NotNil(t, pk1)

pk2, err := validators[0].MakePubKey("test2")
pk2, err := validators[0].RequestPubKey("test2")
require.NoError(t, err)
require.NotNil(t, pk1)

Expand Down
4 changes: 2 additions & 2 deletions wallet/import_btc_addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func (w *Wallet) lcFromEthAddr(ethAddrStr string) (*crypto.LinearCombination, er
ethAddr,
)
h1 := crypto.Sha256(b1)
c1FromAddr, _ := crypto.PrivkeyFromBytes(h1[:])
c1FromAddr, _ := crypto.PrivKeyFromBytes(h1[:])

b2, _ := arguments.Pack(
pk2.X(),
pk2.Y(),
ethAddr,
)
h2 := crypto.Sha256(b2)
c2FromAddr, _ := crypto.PrivkeyFromBytes(h2[:])
c2FromAddr, _ := crypto.PrivKeyFromBytes(h2[:])

lc, err := crypto.NewLinearCombination(
[]*btcec.PublicKey{w.Pk1, w.Pk2},
Expand Down
6 changes: 3 additions & 3 deletions wallet/txauthor/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ type SecretsSource interface {
// are passed in prevPkScripts and the slice length must match the number of
// inputs. Private keys and redeem scripts are looked up using a SecretsSource
// based on the previous output script.
func AddAllInputScripts(signer frost.ISigner, linearCombinations map[string]*crypto.LinearCombination, tx *wire.MsgTx, prevPkScripts [][]byte, inputValues []btcutil.Amount, secrets SecretsSource) error {
func AddAllInputScripts(signer frost.Signer, linearCombinations map[string]*crypto.LinearCombination, tx *wire.MsgTx, prevPkScripts [][]byte, inputValues []btcutil.Amount, secrets SecretsSource) error {

inputFetcher, err := TXPrevOutFetcher(tx, prevPkScripts, inputValues)
if err != nil {
Expand Down Expand Up @@ -331,7 +331,7 @@ func spendWitnessKeyHash(txIn *wire.TxIn, pkScript []byte,
// correspond to the output value of the previous pkScript, or else verification
// will fail since the new sighash digest algorithm defined in BIP0341 includes
// the input value in the sighash.
func spendTaprootKey(signer frost.ISigner, linearCombinations map[string]*crypto.LinearCombination, txIn *wire.TxIn, pkScript []byte,
func spendTaprootKey(signer frost.Signer, linearCombinations map[string]*crypto.LinearCombination, txIn *wire.TxIn, pkScript []byte,
inputValue int64, params *chaincfg.Params, tx *wire.MsgTx, sigHashes *txscript.TxSigHashes, idx int) error {

// First obtain the key pair associated with this p2tr address. If the
Expand Down Expand Up @@ -441,7 +441,7 @@ func spendNestedWitnessPubKeyHash(txIn *wire.TxIn, pkScript []byte,
// AddAllInputScripts modifies an authored transaction by adding inputs scripts
// for each input of an authored transaction. Private keys and redeem scripts
// are looked up using a SecretsSource based on the previous output script.
func (tx *AuthoredTx) AddAllInputScripts(signer frost.ISigner, linearCombinations map[string]*crypto.LinearCombination, secrets SecretsSource) error {
func (tx *AuthoredTx) AddAllInputScripts(signer frost.Signer, linearCombinations map[string]*crypto.LinearCombination, secrets SecretsSource) error {
return AddAllInputScripts(
signer, linearCombinations, tx.Tx, tx.PrevScripts, tx.PrevInputValues, secrets,
)
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type Wallet struct {
db walletdb.DB
Manager *waddrmgr.Manager
TxStore *wtxmgr.Store
FrostSigner frost.ISigner
FrostSigner frost.Signer

btcAddrToEthAddr map[string]string
btcAddrToLc map[string]*crypto.LinearCombination
Expand Down

0 comments on commit 5557678

Please sign in to comment.