Skip to content

Commit

Permalink
[Bug] Fix contextCheckBlock for the first block that it's a v1 block.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy authored and Stamek committed Aug 22, 2020
1 parent 5c14bd7 commit af29139
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4320,10 +4320,13 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
}

// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
CScript expect = CScript() << nHeight;
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
!std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
return state.DoS(100, error("%s : block height mismatch in coinbase", __func__), REJECT_INVALID, "bad-cb-height");
if (pindexPrev) { // pindexPrev is only null on the first block which is a version 1 block.
CScript expect = CScript() << nHeight;
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
!std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
return state.DoS(100, error("%s : block height mismatch in coinbase", __func__), REJECT_INVALID,
"bad-cb-height");
}
}
LogPrint("debug", "ContextualCheckBlock returning true");
return true;
Expand Down

0 comments on commit af29139

Please sign in to comment.