Skip to content

Commit 86c55b0

Browse files
committed
Remove restrictions on coinbase witness
This relaxes the restriction on the coinbase witness that limited it to only having one entry that must be 32 bytes; instead there may be up to 255 items on the coinbase witness stack, and they may be any length. In order to have multiple entries on the coinbase witness stack, the number of entries must be specified in the coinbase commitment, by changing the witness commitment from a 36 byte push: OP_RETURN [ 0xaa 0x21 0xa9 0xed HASH ] to a 37 byte push: OP_RETURN [ 0xaa 0x21 0xa9 0xed HASH N ] where N is the number of entries on the coinbase witness stack (from 0 to 255).
1 parent 0a25cca commit 86c55b0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,9 +3063,17 @@ bool IsWitnessEnabled(const CBlock& block, const CBlockIndex* pindexPrev, const
30633063
}
30643064

30653065

3066-
bool CheckWitnessCommitAndNonce(const CBlock& block, int commitpos, CValidationState& state)
3066+
bool CheckWitnessCommit(const CBlock& block, int commitpos, CValidationState& state)
30673067
{
3068-
if (block.vtx[0].wit.vtxinwit.size() != 1 || block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.size() != 1 || block.vtx[0].wit.vtxinwit[0].scriptWitness.stack[0].size() != 32) {
3068+
size_t stack_size;
3069+
3070+
if (block.vtx[0].vout[commitpos].scriptPubKey[1] == 0x24) {
3071+
stack_size = 1;
3072+
} else {
3073+
stack_size = block.vtx[0].vout[commitpos].scriptPubKey[38];
3074+
}
3075+
3076+
if (block.vtx[0].wit.vtxinwit.size() != 1 || block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.size() != stack_size) {
30693077
return state.DoS(100, error("%s : invalid witness commitment size", __func__), REJECT_INVALID, "bad-witness-merkle-size", true);
30703078
}
30713079

@@ -3088,7 +3096,9 @@ int FindWitnessCommitPos(const CBlock& block)
30883096
for (size_t o = 0; o < block.vtx[0].vout.size(); o++) {
30893097
if (block.vtx[0].vout[o].scriptPubKey.size() >= 38
30903098
&& block.vtx[0].vout[o].scriptPubKey[0] == OP_RETURN
3091-
&& block.vtx[0].vout[o].scriptPubKey[1] == 0x24
3099+
&& (block.vtx[0].vout[o].scriptPubKey[1] == 0x24
3100+
|| (block.vtx[0].vout[o].scriptPubKey[1] == 0x25
3101+
&& block.vtx[0].vout[o].scriptPubKey.size() >= 39))
30923102
&& block.vtx[0].vout[o].scriptPubKey[2] == 0xaa
30933103
&& block.vtx[0].vout[o].scriptPubKey[3] == 0x21
30943104
&& block.vtx[0].vout[o].scriptPubKey[4] == 0xa9
@@ -3222,7 +3232,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
32223232
if (IsWitnessEnabled(block, pindexPrev, consensusParams)) {
32233233
int commitpos = FindWitnessCommitPos(block);
32243234
if (commitpos != -1) {
3225-
if (!CheckWitnessCommitAndNonce(block, commitpos, state)) {
3235+
if (!CheckWitnessCommit(block, commitpos, state)) {
32263236
return false;
32273237
}
32283238

0 commit comments

Comments
 (0)