aboutsummaryrefslogtreecommitdiff
path: root/src/pubkey.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2021-09-02 10:18:59 +0800
committerfanquake <fanquake@gmail.com>2021-09-02 10:41:16 +0800
commit01fa1481f9d81cc39a8d2eb1408086ddc30e226b (patch)
tree95559053053d6260b0ad766d091a6da967eae6b3 /src/pubkey.cpp
parent3af495d6972379b07530a5fcc2665aa626d01621 (diff)
parent56a42f10f452f0ac0e3e333646a8effcbebf6b30 (diff)
downloadbitcoin-01fa1481f9d81cc39a8d2eb1408086ddc30e226b.tar.xz
Merge bitcoin/bitcoin#22836: Stricter BIP32 decoding and test vector 5
56a42f10f452f0ac0e3e333646a8effcbebf6b30 Stricter BIP32 decoding and test vector 5 (Pieter Wuille) Pull request description: This adds detection for various edge cases when decoding BIP32 extended pubkeys/privkeys, and tests them using the proposed https://github.com/bitcoin/bips/pull/921 BIP32 test vector 5. ACKs for top commit: darosior: utACK 56a42f10f452f0ac0e3e333646a8effcbebf6b30 -- Had to implement essentially the same fix in python-bip32. kristapsk: ACK 56a42f10f452f0ac0e3e333646a8effcbebf6b30. Checked that test vectors are the same as in BIP32 and that tests pass. Tree-SHA512: 5cc800cc9dc10e43ae89b659ce4f44026d04ec3cabac4eb5122d2e72ec2ed66cd5ace8c7502259e469a9ecaa5ecca2457e55dfe5fedba59948ecbf6673af67a7
Diffstat (limited to 'src/pubkey.cpp')
-rw-r--r--src/pubkey.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index 100b315615..d14a20b870 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -350,6 +350,7 @@ void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
memcpy(chaincode.begin(), code+9, 32);
pubkey.Set(code+41, code+BIP32_EXTKEY_SIZE);
+ if ((nDepth == 0 && (nChild != 0 || ReadLE32(vchFingerprint) != 0)) || !pubkey.IsFullyValid()) pubkey = CPubKey();
}
bool CExtPubKey::Derive(CExtPubKey &out, unsigned int _nChild) const {