diff --git a/src/merkleblock.h b/src/merkleblock.h --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -148,6 +148,9 @@ * From the peer-node's perspective, the SPV client is a "filtered node". * See BIP37 for details: * https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki + * + * NOTE: The class assumes that the given CBlock has *at least* 1 transaction. + * If the CBlock has 0 txs, it will hit an assertion. */ class CMerkleBlock { public: diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -54,6 +54,10 @@ uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::vector &vTxid) { + // we can never have zero txs in a merkle block, we always need the + // coinbase tx if we do not have this assert, we can hit a memory + // access violation when indexing into vTxid + assert(vTxid.size() != 0); if (height == 0) { // hash at height 0 is the txids themself. return vTxid[pos];