Repository: paritytech/parity-bitcoin (language: rust)

Issue:
Invalid verification is_witness_commitment_script
From bip141:

> The commitment is recorded in a scriptPubKey of the coinbase transaction. **It must be at least 38 bytes**, with the first 6-byte of 0x6a24aa21a9ed

Current source state:

```rust
pub fn is_witness_commitment_script(script: &[u8]) -> bool {
	script.len() >= 36 &&
		script[0] == Opcode::OP_RETURN as u8 &&
		script[1] == 0x24 &&
		script[2] == 0xAA &&
		script[3] == 0x21 &&
		script[4] == 0xA9 &&
		script[5] == 0xED
}
```

It should be 38 here, not 36.


Discussion / hints:
From bitcoin/bitcoin source:

```c++
static 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 && ...) {
                commitpos = o;
            }
        }
    }
    return commitpos;
}
```
Thanks for the report, you're right. Will prepare a fix in a minute :)

Fix patch:
diff --git a/script/src/script.rs b/script/src/script.rs
index d0bd6e442..92d9a0f97 100644
--- a/script/src/script.rs
+++ b/script/src/script.rs
@@ -575,7 +575,7 @@ pub type ScriptWitness = Vec<Bytes>;
 /// Passed bytes array is a commitment script?
 /// https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure
 pub fn is_witness_commitment_script(script: &[u8]) -> bool {
-	script.len() >= 36 &&
+	script.len() >= 38 &&
 		script[0] == Opcode::OP_RETURN as u8 &&
 		script[1] == 0x24 &&
 		script[2] == 0xAA &&


Test patch: