mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
validation: Add minimum witness commitment size constant
Per BIP 141, the witness commitment structure is atleast 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.
This commit is contained in:
parent
ba348dbc51
commit
06442549f8
2 changed files with 11 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -92,6 +92,8 @@ static const unsigned int DEFAULT_CHECKLEVEL = 3;
|
|||
// one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
|
||||
// Setting the target to >= 550 MiB will make it likely we can respect the target.
|
||||
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
|
||||
/** Minimum size of a witness commitment structure. Defined in BIP 141. **/
|
||||
static constexpr size_t MINIMUM_WITNESS_COMMITMENT{38};
|
||||
|
||||
struct BlockHasher
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue