test: add script_tests cases covering interpreter mutants #36291

Manually merged
ViniciusCestarii merged 6 commits from kill-interpreter-mutants into master 2026-10-07 07:53:25 +00:00 AGit
ViniciusCestarii commented 2026-09-17 19:37:36 +00:00 (Migrated from github.com)

Kills some live mutants on interpreter.cpp found by https://bitcoincore.space. They are:

interpreter.cpp#5168: IsCompressedOrUncompressedPubKey: pubkey with neither compressed nor uncompressed prefix returns true

-    } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
+    } else if (1==1) {

interpreter.cpp#5191: IsValidSignatureEncoding: 73-byte upper bound returns true

     if (sig.size() < 9) return false;
-    if (sig.size() > 73) return false;

interpreter.cpp#5200: IsValidSignatureEncoding: total-length byte check returns true

     // Make sure the length covers the entire signature.
-    if (sig[1] != sig.size() - 3) return false;

interpreter.cpp#5232: IsValidSignatureEncoding: null R byte check lenR > 1 -> lenR >=1

     // Null bytes at the start of R are not allowed, unless R would
     // otherwise be interpreted as a negative number.
-    if (lenR > 1 && (sig[4] == 0x00) && !(sig[5] & 0x80)) return false;
+    if (lenR >= 1 && (sig[4] == 0x00) && !(sig[5] & 0x80)) return false;

interpreter.cpp#5259: IsValidSignatureEncoding: null S byte check lenS > 1 -> lenS >= 1

     // Null bytes at the start of S are not allowed, unless S would otherwise be
     // interpreted as a negative number.
-    if (lenS > 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80)) return false;
+    if (lenS >= 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80)) return false;

interpreter.cpp#5186: IsValidSignatureEncoding: 9-byte lower bound returns true

     // Minimum and maximum size constraints.
-    if (sig.size() < 9) return false;

The first affects policy only, the next four affect consensus, and the last covers the lower bound and lets ASan catch UB: a 3-byte signature reaches the sig[3] read that the sig.size() < 9 guard protects.

Recommend reviewing per commit.

Kills some live mutants on `interpreter.cpp` found by https://bitcoincore.space. They are: [interpreter.cpp#5168](https://bitcoincore.space/src/script/interpreter.cpp#5168): `IsCompressedOrUncompressedPubKey`: pubkey with neither compressed nor uncompressed prefix returns `true` ```diff - } else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) { + } else if (1==1) { ``` [interpreter.cpp#5191](https://bitcoincore.space/src/script/interpreter.cpp#5191): `IsValidSignatureEncoding`: 73-byte upper bound returns `true` ```diff if (sig.size() < 9) return false; - if (sig.size() > 73) return false; ``` [interpreter.cpp#5200](https://bitcoincore.space/src/script/interpreter.cpp#5200): `IsValidSignatureEncoding`: total-length byte check returns `true` ```diff // Make sure the length covers the entire signature. - if (sig[1] != sig.size() - 3) return false; ``` [interpreter.cpp#5232](https://bitcoincore.space/src/script/interpreter.cpp#5232): `IsValidSignatureEncoding`: null R byte check `lenR > 1` -> `lenR >=1` ```diff // Null bytes at the start of R are not allowed, unless R would // otherwise be interpreted as a negative number. - if (lenR > 1 && (sig[4] == 0x00) && !(sig[5] & 0x80)) return false; + if (lenR >= 1 && (sig[4] == 0x00) && !(sig[5] & 0x80)) return false; ``` [interpreter.cpp#5259](https://bitcoincore.space/src/script/interpreter.cpp#5259): `IsValidSignatureEncoding`: null S byte check `lenS > 1` -> `lenS >= 1` ```diff // Null bytes at the start of S are not allowed, unless S would otherwise be // interpreted as a negative number. - if (lenS > 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80)) return false; + if (lenS >= 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80)) return false; ``` [interpreter.cpp#5186](https://bitcoincore.space/src/script/interpreter.cpp#5186): `IsValidSignatureEncoding`: 9-byte lower bound returns `true` ```diff // Minimum and maximum size constraints. - if (sig.size() < 9) return false; ``` The first affects policy only, the next four affect consensus, and the last covers the lower bound and lets ASan catch UB: a 3-byte signature reaches the `sig[3]` read that the `sig.size() < 9` guard protects. Recommend reviewing per commit.
DrahtBot commented 2026-09-17 19:37:46 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK brunoerg, fametrano, sedited

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36291 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36291.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36291#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [brunoerg](https://github.com/bitcoin/bitcoin/pull/36291#pullrequestreview-5357321112), [fametrano](https://github.com/bitcoin/bitcoin/pull/36291#issuecomment-5941346818), [sedited](https://github.com/bitcoin/bitcoin/pull/36291#pullrequestreview-5439189477) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
ViniciusCestarii commented 2026-09-28 16:48:21 +00:00 (Migrated from github.com)

cc @brunoerg

cc @brunoerg
First-time contributor

Base: 7988380da987c0b860885853ace8149b84ac2ee8
Head: efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe

No verified findings are available from this partial review.

Review coverage was incomplete. The archaeology review had incomplete evidence.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `7988380da987c0b860885853ace8149b84ac2ee8` Head: `efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe` No verified findings are available from this partial review. Review coverage was incomplete. The archaeology review had incomplete evidence. [Full review report](<https://review.fish.foo/traces/36291-efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe-224-1.html>)
brunoerg (Migrated from github.com) reviewed 2026-09-28 17:53:03 +00:00
brunoerg (Migrated from github.com) commented 2026-09-28 17:53:03 +00:00

d34cd78bd5: do we really need this 8-byte vector test? As far as I verified, the mutant is killed with the other test here (3-byte one).

d34cd78bd5ed887f136e0f09a98b519c71470516: do we really need this 8-byte vector test? As far as I verified, the mutant is killed with the other test here (3-byte one).
ViniciusCestarii (Migrated from github.com) reviewed 2026-09-28 18:45:07 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-09-28 18:45:07 +00:00

It is not necessary for killing the mutant. My reasoning was to add case that directly tests the lower bound. But thinking back no signature under 9 bytes is valid and the 3 byte case is only worth it because it causes UB. I will drop the 8 byte cases and keep the 3 byte one. Thanks for spotting this.

It is not necessary for killing the mutant. My reasoning was to add case that directly tests the lower bound. But thinking back no signature under 9 bytes is valid and the 3 byte case is only worth it because it causes UB. I will drop the 8 byte cases and keep the 3 byte one. Thanks for spotting this.
ViniciusCestarii (Migrated from github.com) reviewed 2026-09-28 18:50:10 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-09-28 18:50:10 +00:00

Done on a0ce5b2629.

Done on a0ce5b2629394af8e5d5fde6459e27d2c935d43e.
ViniciusCestarii commented 2026-09-28 18:50:57 +00:00 (Migrated from github.com)
Thanks @brunoerg for the review! Forced push a0ce5b2629394af8e5d5fde6459e27d2c935d43e addressing comment https://github.com/bitcoin/bitcoin/pull/36291#discussion_r4125360401
brunoerg (Migrated from github.com) approved these changes 2026-09-28 23:42:01 +00:00
brunoerg (Migrated from github.com) left a comment

ACK a0ce5b2629

just left a nit, happy to re-ack if you decide to address it.

ACK a0ce5b2629394af8e5d5fde6459e27d2c935d43e just left a nit, happy to re-ack if you decide to address it.
brunoerg (Migrated from github.com) commented 2026-09-28 23:41:20 +00:00

nit: do these new DERSIG test cases really need a real pubkey? I think an empty pubkey would work, e.g. "0 CHECKSIG NOT"

nit: do these new DERSIG test cases really need a real pubkey? I think an empty pubkey would work, e.g. "0 CHECKSIG NOT"
ViniciusCestarii (Migrated from github.com) reviewed 2026-09-29 18:21:55 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-09-29 18:21:55 +00:00

True, it is better to simplify these tests. I noticed this also applies for the sigs on cases of STRICTENC, so I simplified both DERSIG and STRICTENC added tests on efe0dfcf1e

True, it is better to simplify these tests. I noticed this also applies for the sigs on cases of STRICTENC, so I simplified both DERSIG and STRICTENC added tests on efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe
ViniciusCestarii commented 2026-09-29 18:26:22 +00:00 (Migrated from github.com)
Thanks @brunoerg. Forced push efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe addressing https://github.com/bitcoin/bitcoin/pull/36291#discussion_r4128116862. See [DERSIG cases diff](https://github.com/bitcoin/bitcoin/compare/a0ce5b2629394af8e5d5fde6459e27d2c935d43e..a2c90fb8d24189586c734253de44b930f43efac8) and [STRICTENC cases diff](https://github.com/bitcoin/bitcoin/compare/a2c90fb8d24189586c734253de44b930f43efac8..efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe)
brunoerg (Migrated from github.com) approved these changes 2026-09-29 19:23:04 +00:00
brunoerg (Migrated from github.com) left a comment

reACK efe0dfcf1e

reACK efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe
fametrano commented 2026-10-01 21:48:21 +00:00 (Migrated from github.com)

ACK efe0dfcf1e

I ran the 11 new rows through btclib's script interpreter and each gives the expected result and error code.

ACK efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe I ran the 11 new rows through btclib's script interpreter and each gives the expected result and error code.
sedited commented 2026-10-05 09:21:42 +00:00 (Migrated from github.com)

@ViniciusCestarii can you re-write the pull request descriptions of your mutations without having to nest html in it? Maybe just give every mutation as its minimized diff? The pull request description gets added to every merge commit and all the formatting makes it harder to render the same everywhere and a bit harder to read.

@ViniciusCestarii can you re-write the pull request descriptions of your mutations without having to nest html in it? Maybe just give every mutation as its minimized diff? The pull request description gets added to every merge commit and all the formatting makes it harder to render the same everywhere and a bit harder to read.
ViniciusCestarii commented 2026-10-05 12:15:04 +00:00 (Migrated from github.com)

Updated the pr description.

Updated the pr description.
sedited (Migrated from github.com) approved these changes 2026-10-07 07:46:23 +00:00
sedited (Migrated from github.com) left a comment
ACK efe0dfcf1e5c431c62dc9ac4fd2c2d97a62814fe
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36291
No description provided.