Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/Bug with PSBT deserialization #2199

Closed
hax0kartik opened this issue Jun 19, 2024 · 1 comment · Fixed by #2206
Closed

Issue/Bug with PSBT deserialization #2199

hax0kartik opened this issue Jun 19, 2024 · 1 comment · Fixed by #2206

Comments

@hax0kartik
Copy link

hax0kartik commented Jun 19, 2024

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
Copy link
Member

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.

guggero added a commit to guggero/btcd that referenced this issue Jun 25, 2024
Fixes btcsuite#2199.

Previous to this fix the keytype was only interpreted as a single byte,
even though BIP-0174 states it is to be parsed as a CompactSize/VarInt.
btcfind pushed a commit to btcfind/btcd that referenced this issue Sep 26, 2024
Fixes btcsuite#2199.

Previous to this fix the keytype was only interpreted as a single byte,
even though BIP-0174 states it is to be parsed as a CompactSize/VarInt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants