Merge #12798: doc: Refer to witness reserved value as spec. in the BIP
adc2586
doc: Refer to witness reserved value as spec. in the BIP (MarcoFalke)
Pull request description:
BIP141 refers to the coinbase's input's witness that consists of a single 32-byte array as "witness reserved value".
This updates the code to follow the BIP
Tree-SHA512: 49c9463519bd11b9ff322eeecd638f7627aa8efdfb869f8549f9a160ff34281e1b5a0b9d83545a692de6f5ff795055292c423403b0f3ce7597e3f32273cf1deb
This commit is contained in:
commit
174d0160cb
3 changed files with 7 additions and 7 deletions
|
@ -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) == ThresholdState::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
|
||||
|
|
|
@ -411,7 +411,7 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
|
|||
/** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */
|
||||
bool RewindBlockIndex(const CChainParams& params);
|
||||
|
||||
/** Update uncommitted block structures (currently: only the witness nonce). This is safe for submitted blocks. */
|
||||
/** Update uncommitted block structures (currently: only the witness reserved value). This is safe for submitted blocks. */
|
||||
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
|
||||
|
||||
/** Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). */
|
||||
|
|
|
@ -425,7 +425,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
|
||||
assert(self.nodes[0].getbestblockhash() == block.hash)
|
||||
|
||||
# Now make sure that malleating the witness nonce doesn't
|
||||
# Now make sure that malleating the witness reserved value doesn't
|
||||
# result in a block permanently marked bad.
|
||||
block = self.build_next_block()
|
||||
add_witness_commitment(block)
|
||||
|
@ -436,7 +436,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack = [ ser_uint256(1) ]
|
||||
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=False)
|
||||
|
||||
# Changing the witness nonce doesn't change the block hash
|
||||
# Changing the witness reserved value doesn't change the block hash
|
||||
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack = [ ser_uint256(0) ]
|
||||
test_witness_block(self.nodes[0].rpc, self.test_node, block, accepted=True)
|
||||
|
||||
|
|
Loading…
Reference in a new issue