From 0b7a7234f9b11d1224d0a104569136947993c621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Mo=CC=88ser?= Date: Mon, 13 Apr 2020 11:23:23 -0400 Subject: [PATCH] fix: BCH's Pubkey/Schnorr signature detection in inputs BREAKING CHANGE: Reparsing existing BCH parsings is strongly recommended. This fixes that BCH's new Schnorr signatures are erroneously detected as public keys because both can have a length of 65 bytes. Based on https://github.com/mplattner/BlockSci/commit/910dadefaccf597cb4c786c87aa7d8520b650135 --- tools/parser/script_input.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/parser/script_input.cpp b/tools/parser/script_input.cpp index 9881ea38..4e044c51 100644 --- a/tools/parser/script_input.cpp +++ b/tools/parser/script_input.cpp @@ -89,11 +89,13 @@ ScriptInputData::ScriptInputData(const // tx 1b008139698117162a9539295ada34fc745f06f733b5f400674f15bf47e720a5 contains a OP_0 before the signature // tx bcd1835ebd7e0d44abcab84ec64a488eefd9fa048d2e11a5a24b197838d8af11 (testnet) contains an Push(13) before the real data // tx 4c65efdf4e60e9c1bbc1a1a452c3c758789efc7894bff9ed694305eb9c389e7b (testnet) super weird - + // tx 054291a582fe7f34d8247a8760232ce6ac11d6657c51cb961856029fada2749a (bch mainnet): schnorr signatures can (as pubkeys) have a length of 65 bytes + + // Select last matching item, since BCH's Schnorr signatures can look like valid public keys while (scriptView.GetOp(pc, opcode, vchSig2)) { - if (vchSig2.size() == 65 || vchSig2.size() == 33) { + if ((vchSig2.size() == 65 || vchSig2.size() == 33) + && blocksci::CPubKey::GetLen(vchSig2[0]) == vchSig2.size()) { vchSig = vchSig2; - break; } } assert(vchSig.size() == 65 || vchSig.size() == 33);