From 4f0b8361da237b5e6ea0b54f1c0fbb825af0b0e4 Mon Sep 17 00:00:00 2001 From: Louis Singer Date: Wed, 31 Jan 2024 15:12:35 +0100 Subject: [PATCH 1/4] fix signTaproot --- Makefile | 5 +++-- pkg/wallet/single-sig/sign.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3b6e6d8..137bd75 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,12 @@ fmt: run: clean @echo "Running oceand..." - @export OCEAN_NETWORK=regtest; \ + @export OCEAN_NETWORK=testnet; \ + export OCEAN_DB_TYPE=badger; \ export OCEAN_LOG_LEVEL=5; \ export OCEAN_NO_TLS=true; \ export OCEAN_STATS_INTERVAL=120; \ - export OCEAN_ELECTRUM_URL=tcp://localhost:50001; \ + export OCEAN_ELECTRUM_URL=ssl://blockstream.info:465; \ export OCEAN_UTXO_EXPIRY_DURATION_IN_SECONDS=60; \ export OCEAN_DB_TYPE=badger; \ go run ./cmd/oceand diff --git a/pkg/wallet/single-sig/sign.go b/pkg/wallet/single-sig/sign.go index 5f69d79..f7c4fce 100644 --- a/pkg/wallet/single-sig/sign.go +++ b/pkg/wallet/single-sig/sign.go @@ -397,10 +397,15 @@ func signTaproot( return nil, err } - prevout := ptx.Inputs[inIndex].GetUtxo() - prevoutScripts := [][]byte{prevout.Script} - prevoutAssets := [][]byte{prevout.Asset} - prevoutValues := [][]byte{prevout.Value} + prevoutScripts := make([][]byte, 0, len(unsignedTx.Inputs)) + prevoutAssets := make([][]byte, 0, len(unsignedTx.Inputs)) + prevoutValues := make([][]byte, 0, len(unsignedTx.Inputs)) + + for _, in := range ptx.Inputs { + prevoutScripts = append(prevoutScripts, in.GetUtxo().Script) + prevoutAssets = append(prevoutAssets, in.GetUtxo().Asset) + prevoutValues = append(prevoutValues, in.GetUtxo().Value) + } hashForSignature := unsignedTx.HashForWitnessV1( inIndex, prevoutScripts, prevoutAssets, prevoutValues, sighashType, genesisBlockHash, leafHash, nil, From a66b67e601aceac223942f4abac5740c7b43b00e Mon Sep 17 00:00:00 2001 From: Louis Singer Date: Wed, 31 Jan 2024 15:14:16 +0100 Subject: [PATCH 2/4] revert MakeFile --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 137bd75..3b6e6d8 100644 --- a/Makefile +++ b/Makefile @@ -34,12 +34,11 @@ fmt: run: clean @echo "Running oceand..." - @export OCEAN_NETWORK=testnet; \ - export OCEAN_DB_TYPE=badger; \ + @export OCEAN_NETWORK=regtest; \ export OCEAN_LOG_LEVEL=5; \ export OCEAN_NO_TLS=true; \ export OCEAN_STATS_INTERVAL=120; \ - export OCEAN_ELECTRUM_URL=ssl://blockstream.info:465; \ + export OCEAN_ELECTRUM_URL=tcp://localhost:50001; \ export OCEAN_UTXO_EXPIRY_DURATION_IN_SECONDS=60; \ export OCEAN_DB_TYPE=badger; \ go run ./cmd/oceand From d8167870caa24616177069aa3cae46f03a670e75 Mon Sep 17 00:00:00 2001 From: Louis Singer Date: Wed, 31 Jan 2024 16:05:15 +0100 Subject: [PATCH 3/4] fix validate --- pkg/wallet/single-sig/sign.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/wallet/single-sig/sign.go b/pkg/wallet/single-sig/sign.go index f7c4fce..b02bb0c 100644 --- a/pkg/wallet/single-sig/sign.go +++ b/pkg/wallet/single-sig/sign.go @@ -163,9 +163,17 @@ type SignTaprootArgs struct { } func (a SignTaprootArgs) validate() error { - if _, err := psetv2.NewPsetFromBase64(a.PsetBase64); err != nil { + decoded, err := psetv2.NewPsetFromBase64(a.PsetBase64) + if err != nil { return err } + + for i, in := range decoded.Inputs { + if in.WitnessUtxo == nil { + return fmt.Errorf("missing witness utxo on input %d", i) + } + } + if len(a.DerivationPathMap) <= 0 { return ErrMissingDerivationPaths } From 8fcfd7de72dbe7cba37b601fc2a63dfd6e00cb33 Mon Sep 17 00:00:00 2001 From: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:24:15 +0100 Subject: [PATCH 4/4] Fixes after review --- pkg/wallet/single-sig/sign.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/wallet/single-sig/sign.go b/pkg/wallet/single-sig/sign.go index b02bb0c..5a9c9d8 100644 --- a/pkg/wallet/single-sig/sign.go +++ b/pkg/wallet/single-sig/sign.go @@ -163,14 +163,14 @@ type SignTaprootArgs struct { } func (a SignTaprootArgs) validate() error { - decoded, err := psetv2.NewPsetFromBase64(a.PsetBase64) + ptx, err := psetv2.NewPsetFromBase64(a.PsetBase64) if err != nil { return err } - for i, in := range decoded.Inputs { - if in.WitnessUtxo == nil { - return fmt.Errorf("missing witness utxo on input %d", i) + for i, in := range ptx.Inputs { + if in.GetUtxo() == nil { + return fmt.Errorf("missing prevout of input %d", i) } }