btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.2k stars 2.35k forks source link

Issue/Bug with PSBT deserialization #2199

Closed hax0kartik closed 3 months ago

hax0kartik commented 3 months ago

Hello,

BTCD does not fail as it should when trying to deserialize the following bytes:

70736274ff01001c000000000002000000000000000000000000736210ff01000001010010ff70ff01001c00000000000000000000000000000000000000000000

For the above input, Bitcoin-core fails while trying to deserialize and throws the error ReadCompactSize(): size too large.

This issue partly seems to be due to incorrect implementation of bip-174. Bip-174 says that keytype is a compact size int and from what I see btcd simply treats keytype as a single byte.

The test case given below can be used to reproduce this issue:


func TestKeyType(t *testing.T) {
    k, _ := hex.DecodeString("70736274ff01001c000000000002000000000000000000000000736210ff01000001010010ff70ff01001c00000000000000000000000000000000000000000000")
    if _, err := NewFromRawBytes(bytes.NewReader(k), false); err == nil {
        require.Error(t, err, "Err should not be nil")
    }
}

cc: @brunoerg

Roasbeef commented 3 months ago

Bip-174 says that keytype is a compact size int and from what I see btcd simply treats keytype as a single byte.

Nice find! This should be easy enough to fix.