mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Merge #18780: validation: add const for minimum witness commitment size
692f8307fctest: add test for witness commitment index (fanquake)06442549f8validation: Add minimum witness commitment size constant (fanquake) Pull request description:16101de5f3: Per [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure), the witness commitment structure is at least 38 bytes, OP_RETURN (0x6a) + 36 (0x24) + 4 byte header (0xaa21a9ed) + 32 byte SHA256 hash. It can be longer, however any additional data has no consensus meaning.54f8c48d6a: As per BIP 141, if there is more than 1 pubkey that matches the witness commitment structure, the one with the highest output index should be chosen. This adds a sanity check that we are doing that, which will fail if anyone tries to "optimize" GetWitnessCommitmentIndex() by returning early. ACKs for top commit: MarcoFalke: ACK692f8307fc🌵 jonatack: Code review ACK692f830ajtowns: ACK692f8307fcjnewbery: utACK692f8307fclaanwj: ACK692f8307fcTree-SHA512: 7af3fe4b8a52fea2cdd0aec95f7bb935351a77b73d934bc88d6625a3503311b2a062cba5190b2228f97caa76840db3889032d910fc8e318ca8e7810a8afbafa0
This commit is contained in:
@@ -3386,7 +3386,14 @@ int GetWitnessCommitmentIndex(const CBlock& block)
|
||||
int commitpos = -1;
|
||||
if (!block.vtx.empty()) {
|
||||
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
|
||||
if (block.vtx[0]->vout[o].scriptPubKey.size() >= 38 && block.vtx[0]->vout[o].scriptPubKey[0] == OP_RETURN && block.vtx[0]->vout[o].scriptPubKey[1] == 0x24 && block.vtx[0]->vout[o].scriptPubKey[2] == 0xaa && block.vtx[0]->vout[o].scriptPubKey[3] == 0x21 && block.vtx[0]->vout[o].scriptPubKey[4] == 0xa9 && block.vtx[0]->vout[o].scriptPubKey[5] == 0xed) {
|
||||
const CTxOut& vout = block.vtx[0]->vout[o];
|
||||
if (vout.scriptPubKey.size() >= MINIMUM_WITNESS_COMMITMENT &&
|
||||
vout.scriptPubKey[0] == OP_RETURN &&
|
||||
vout.scriptPubKey[1] == 0x24 &&
|
||||
vout.scriptPubKey[2] == 0xaa &&
|
||||
vout.scriptPubKey[3] == 0x21 &&
|
||||
vout.scriptPubKey[4] == 0xa9 &&
|
||||
vout.scriptPubKey[5] == 0xed) {
|
||||
commitpos = o;
|
||||
}
|
||||
}
|
||||
@@ -3417,7 +3424,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
|
||||
CHash256().Write(witnessroot.begin(), 32).Write(ret.data(), 32).Finalize(witnessroot.begin());
|
||||
CTxOut out;
|
||||
out.nValue = 0;
|
||||
out.scriptPubKey.resize(38);
|
||||
out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
|
||||
out.scriptPubKey[0] = OP_RETURN;
|
||||
out.scriptPubKey[1] = 0x24;
|
||||
out.scriptPubKey[2] = 0xaa;
|
||||
|
||||
Reference in New Issue
Block a user