It looks to me like decoding of prefilled transactions is incorrect in Bitcoin Core 0.13. The error is in PartiallyDownloadedBlock::InitData where it decodes CBlockHeaderAndShortTxIDs incorrectly.
Given a block with 5 transactions, where transactions 3 and 5 are prefilled (+ coinbase). Prefilled transactions are encoded like this:
| TX | Prefilled? | Encoded ID |
|---|---|---|
| 0 | YES | 0 |
| 1 | ||
| 2 | ||
| 3 | YES | 3 |
| 4 | ||
| 5 | YES | 2 |
However in lines 60 to 75, this is decoded like this:
| Prefilled index | Decoded index |
|---|---|
| 0 | 0 (-1 + 0 + 1) |
| 1 | 4 (0 + 3 + 1) |
| 2 | 7 (4 + 2 + 1) |
If you change line 60 from:
int32_t lastprefilledindex = -1;
to
int32_t lastprefilledindex = 0;
and line 65 from
lastprefilledindex += cmpctblock.prefilledtxn[i].index + 1; //index is a uint16_t, so cant overflow here
to
lastprefilledindex += cmpctblock.prefilledtxn[i].index; //index is a uint16_t, so cant overflow here
The decoding would become:
| Prefilled index | Decoded index |
|---|---|
| 0 | 0 (0 + 0) |
| 1 | 3 (0 + 3) |
| 2 | 5 (3 + 2) |
This would match the original index in the block.
Since shortids depend on prefilledtxn being decoded correctly, these also will also decode incorrectly.