Skip to content

Commit

Permalink
[bitcoin#9102] really don't validate genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Oct 25, 2018
1 parent ccf40db commit c7e5549
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,25 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
assert(*pindex->phashBlock == block.GetHash());
int64_t nTimeStart = GetTimeMicros();

// verify that the view's current state corresponds to the previous block
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
assert(hashPrevBlock == view.GetBestBlock());

const Consensus::Params& consensusParams = chainparams.GetConsensus();
// Add genesis outputs but don't validate.
if (block.GetHash() == consensusParams.hashGenesisBlock) {
if (!fJustCheck) {
if (consensusParams.connect_genesis_outputs) {
for (const auto& tx : block.vtx) {
// Directly add new coins to DB
AddCoins(view, *tx, 0);
}
}
view.SetBestBlock(pindex->GetBlockHash());
}
return true;
}

// Check it again in case a previous version let a bad block in
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
// ContextualCheckBlockHeader() here. This means that if we add a new
Expand All @@ -1836,25 +1855,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
}

// verify that the view's current state corresponds to the previous block
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
assert(hashPrevBlock == view.GetBestBlock());

const Consensus::Params& consensusParams = chainparams.GetConsensus();
// Add genesis outputs but don't validate.
if (block.GetHash() == consensusParams.hashGenesisBlock) {
if (!fJustCheck) {
if (consensusParams.connect_genesis_outputs) {
for (const auto& tx : block.vtx) {
// Directly add new coins to DB
AddCoins(view, *tx, 0);
}
}
view.SetBestBlock(pindex->GetBlockHash());
}
return true;
}

nBlocksTotal++;

// Check that all non-zero coinbase outputs pay to the required destination
Expand Down Expand Up @@ -3100,9 +3100,10 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos,
static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{
// Check proof of work matches claimed amount
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
if (fCheckPOW && block.GetHash() != consensusParams.hashGenesisBlock
&& !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) {
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");

}
return true;
}

Expand Down

0 comments on commit c7e5549

Please sign in to comment.