|
|
|
@ -3223,10 +3223,10 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
|
|
|
|
// Validation for witness commitments.
|
|
|
|
|
// * We compute the witness hash (which is the hash including witnesses) of all the block's transactions, except the
|
|
|
|
|
// coinbase (where 0x0000....0000 is used instead).
|
|
|
|
|
// * The coinbase scriptWitness is a stack of a single 32-byte vector, containing a witness nonce (unconstrained).
|
|
|
|
|
// * The coinbase scriptWitness is a stack of a single 32-byte vector, containing a witness reserved value (unconstrained).
|
|
|
|
|
// * We build a merkle tree with all those witness hashes as leaves (similar to the hashMerkleRoot in the block header).
|
|
|
|
|
// * There must be at least one output whose scriptPubKey is a single 36-byte push, the first 4 bytes of which are
|
|
|
|
|
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness nonce). In case there are
|
|
|
|
|
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness reserved value). In case there are
|
|
|
|
|
// multiple, the last one is used.
|
|
|
|
|
bool fHaveWitness = false;
|
|
|
|
|
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE) {
|
|
|
|
@ -3238,7 +3238,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
|
|
|
|
// already does not permit it, it is impossible to trigger in the
|
|
|
|
|
// witness tree.
|
|
|
|
|
if (block.vtx[0]->vin[0].scriptWitness.stack.size() != 1 || block.vtx[0]->vin[0].scriptWitness.stack[0].size() != 32) {
|
|
|
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-witness-nonce-size", true, strprintf("%s : invalid witness nonce size", __func__));
|
|
|
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-witness-nonce-size", true, strprintf("%s : invalid witness reserved value size", __func__));
|
|
|
|
|
}
|
|
|
|
|
CHash256().Write(hashWitness.begin(), 32).Write(&block.vtx[0]->vin[0].scriptWitness.stack[0][0], 32).Finalize(hashWitness.begin());
|
|
|
|
|
if (memcmp(hashWitness.begin(), &block.vtx[0]->vout[commitpos].scriptPubKey[6], 32)) {
|
|
|
|
@ -3257,7 +3257,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// After the coinbase witness nonce and commitment are verified,
|
|
|
|
|
// After the coinbase witness reserved value and commitment are verified,
|
|
|
|
|
// we can check if the block weight passes (before we've checked the
|
|
|
|
|
// coinbase witness, it would be possible for the weight to be too
|
|
|
|
|
// large by filling up the coinbase witness, which doesn't change
|
|
|
|
|