| 78 | } |
| 79 | |
| 80 | void validateCompactBlock(const CompactBlock& cmpctblock, uint64_t currMaxBlockSize) { |
| 81 | if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) |
| 82 | throw std::invalid_argument("empty data in compact block"); |
| 83 | |
| 84 | validateNumTxs(cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size(), currMaxBlockSize); |
| 85 | |
| 86 | int32_t lastprefilledindex = -1; |
| 87 | for (size_t i = 0; i < cmpctblock.prefilledtxn.size(); i++) { |
| 88 | if (cmpctblock.prefilledtxn[i].tx.IsNull()) |
| 89 | throw std::invalid_argument("null tx in compact block"); |
| 90 | |
| 91 | lastprefilledindex += cmpctblock.prefilledtxn[i].index + 1; //index is a uint16_t, so cant overflow here |
| 92 | if (lastprefilledindex > std::numeric_limits<uint16_t>::max()) |
| 93 | throw std::invalid_argument("tx index overflows"); |
| 94 | |
| 95 | if (static_cast<uint32_t>(lastprefilledindex) > cmpctblock.shorttxids.size() + i) { |
| 96 | // If we are inserting a tx at an index greater than our full list of shorttxids |
| 97 | // plus the number of prefilled txn we've inserted, then we have txn for which we |
| 98 | // have neither a prefilled txn or a shorttxid! |
| 99 | throw std::invalid_argument("invalid index for tx"); |
| 100 | } |
| 101 | } |
| 102 | } |