diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index 18df2923..ba084e28 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -850,9 +850,8 @@ Parser.parseBlockCompact = function parseBlockCompact(p) { inCount = p.readVarint(); if (inCount === 0) { - if (p.readU8() === 0) - throw new Error('Invalid witness tx (flag == 0)'); - inCount = p.readVarint(); + if (p.readU8() !== 0) + inCount = p.readVarint(); } if (inCount > 0) @@ -1055,12 +1054,11 @@ Parser.parseWitnessTX = function parseWitnessTX(p) { version = p.readU32(); // Technically signed marker = p.readU8(); + flag = p.readU8(); if (marker !== 0) throw new Error('Invalid witness tx (marker != 0)'); - flag = p.readU8(); - if (flag === 0) throw new Error('Invalid witness tx (flag == 0)'); @@ -1085,7 +1083,8 @@ Parser.parseWitnessTX = function parseWitnessTX(p) { hasWitness = true; } - assert(hasWitness, 'Serialized wtx has an empty witness.'); + if (!hasWitness) + throw new Error('Witness tx has an empty witness.'); witnessSize = p.end() + 2;