-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
btc: update btcd to fix critical block parsing failure
This updates the btcd require to v0.23.2, which includes a critical fix to the wire package's block parsing code that resolves a failure to deserialize a block with a script witness item larger than 11000. There are now blocks on mainnet and testnet that cannot be deserialized with v0.23.1, meaning this is a critical fix for takers who need to find the maker's redeem transaction and pull the block containing the spending transaction. For SPV, only the matching block is pulled. For a full node RPC wallet, the blocks are pulled in sequence and each transaction is checked directly. As such, the issue affects both types of wallet clients. See mainnet block 0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb containing and enormous 998-of-999 tapscript multisig in txn 7393096d97bfee8660f4100ffd61874d62f9a65de9fb6acf740c4c386990ef73. See also testnet block 0000000000000032fcf519b61aad2b966348e3f2d27687b26277933cc9881965 containing taproot transaction 44692bc2da73192cd0b89bc7a43c0ce43578f6b3567bc945e46e6952e8ec5ca5. This also updates the btcwallet require from 0.15.1 to 0.16.1. This also adds a new test with the above mainnet block and transaction as test vectors.
- Loading branch information
Showing
8 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+96.6 KB
...asset/btc/bitcoin-tx-7393096d97bfee8660f4100ffd61874d62f9a65de9fb6acf740c4c386990ef73.dat
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
"github.com/btcsuite/btcd/rpcclient" | ||
) | ||
|
||
var host = flag.String("host", "127.0.0.1:8332", "node RPC host:port") | ||
var user = flag.String("user", "", "node RPC username") | ||
var pass = flag.String("pass", "", "node RPC password") | ||
|
||
func main() { | ||
os.Exit(mainCore()) | ||
} | ||
|
||
func mainCore() int { | ||
flag.Parse() | ||
|
||
client, err := rpcclient.New(&rpcclient.ConnConfig{ | ||
HTTPPostMode: true, | ||
DisableTLS: true, | ||
Host: *host, | ||
User: *user, | ||
Pass: *pass, | ||
}, nil) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: Unable to connect to RPC server: %v\n", err) | ||
return 1 | ||
} | ||
defer client.Shutdown() | ||
|
||
infoResult, err := client.GetNetworkInfo() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: GetInfo failed: %v\n", err) | ||
return 1 | ||
} | ||
fmt.Printf("Node connection count: %d\n", infoResult.Connections) | ||
|
||
hash, err := client.GetBestBlockHash() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: GetBestBlockHash failed: %v\n", err) | ||
return 2 | ||
} | ||
hdr, err := client.GetBlockHeaderVerbose(hash) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "ERROR: GetBestBlockHash failed: %v\n", err) | ||
return 2 | ||
} | ||
fmt.Println(hdr.Height, hash) | ||
|
||
// block with tx with big witness item that fails for old btcd/wire | ||
bigBlockHash, _ := chainhash.NewHashFromStr("0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb") | ||
msgBlock, err := client.GetBlock(bigBlockHash) | ||
if err != nil { | ||
fmt.Println(err) | ||
return 1 | ||
} | ||
fmt.Println(msgBlock.BlockHash()) | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//go:build !spvlive | ||
|
||
package btc | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/btcsuite/btcd/wire" | ||
) | ||
|
||
//go:embed bitcoin-block-757922.dat | ||
var block757922 []byte | ||
|
||
//go:embed bitcoin-tx-7393096d97bfee8660f4100ffd61874d62f9a65de9fb6acf740c4c386990ef73.dat | ||
var tx7393096d9 []byte | ||
|
||
func TestBigWitness(t *testing.T) { | ||
msgBlock := &wire.MsgBlock{} | ||
err := msgBlock.Deserialize(bytes.NewReader(block757922)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wantHash := "0000000000000000000400a35a007e223a7fb8a622dc7b5aa5eaace6824291fb" | ||
if h := msgBlock.BlockHash().String(); h != wantHash { | ||
t.Errorf("got %v, wanted %v", h, wantHash) | ||
} | ||
|
||
msgTx := &wire.MsgTx{} | ||
err = msgTx.Deserialize(bytes.NewReader(tx7393096d9)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
wantHash = "7393096d97bfee8660f4100ffd61874d62f9a65de9fb6acf740c4c386990ef73" | ||
if h := msgTx.TxHash().String(); h != wantHash { | ||
t.Errorf("got %v, wanted %v", h, wantHash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters