fuzz: fix timelock range in miniscript_smart #36996

Manually merged
erickcestari merged 1 commit from fuzz-miniscript-smart-timelock into master 2026-12-02 16:51:56 +00:00 AGit
erickcestari commented 2026-11-27 14:41:07 +00:00 (Migrated from github.com)

ConsumeNodeSmart draws older()/after() values from [1, 0x7FFFFFF], one F short of the [1, 0x7FFFFFFF] range used by the stable target. after() never reaches LOCKTIME_THRESHOLD, so miniscript_smart never builds time-based after() nodes and never exercises the height/time timelock mixing checks in ComputeType.

Use std::numeric_limits<int32_t>::max() for the bound in both targets instead of hand-counted hex literals.

With the fix, replaying the existing qa-assets corpus hits the mixing branches that previously had 0 hits (libFuzzer edges go from 8829 to 8841), and a 5 minute run covers the remaining ones. The corpus stays valid since the byte consumption stays the same.

`ConsumeNodeSmart` draws `older()/after()` values from `[1, 0x7FFFFFF]`, one F short of the `[1, 0x7FFFFFFF] `range used by the stable target. `after()` never reaches `LOCKTIME_THRESHOLD`, so `miniscript_smart` never builds time-based `after()` nodes and never exercises the height/time timelock mixing checks in `ComputeType`. Use `std::numeric_limits<int32_t>::max()` for the bound in both targets instead of hand-counted hex literals. With the fix, replaying the existing qa-assets corpus hits the mixing branches that previously had 0 hits (libFuzzer edges go from 8829 to 8841), and a 5 minute run covers the remaining ones. The corpus stays valid since the byte consumption stays the same.
DrahtBot commented 2026-11-27 14:41:17 +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 kevkevinpal, marcofleon

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36808 (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--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/36996 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36996.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36996#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 | [kevkevinpal](https://github.com/bitcoin/bitcoin/pull/36996#issuecomment-7317921481), [marcofleon](https://github.com/bitcoin/bitcoin/pull/36996#pullrequestreview-6154627215) | 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. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36808](https://github.com/bitcoin/bitcoin/pull/36808) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in `src/test/fuzz` and treat them as errors by hebasto) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

No findings were published from this review.

Review coverage was incomplete.


Reviewed: 54be7fb7e172 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:58e9d98f3110c6e759f3148d974305b843fed33c --> <!-- ralph-head:54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c --> <!-- ralph-case:b154cf7597f41dc90a19e2722787ecaa6127c0110f4b2d87f892e9cc17bddb1b --> No findings were published from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`54be7fb7e172`](<https://git.fish.foo/bitcoin/bitcoin/commit/54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c>) · [Review report](<https://review.fish.foo/report/36996-54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c-3261-2.html>) · [Previous reports](<https://review.fish.foo/traces/36996/>) [permalink](<https://review.fish.foo/report/36996-54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c-3261-2.html>)
maflcko (Migrated from github.com) reviewed 2026-11-27 14:53:41 +00:00
maflcko (Migrated from github.com) commented 2026-11-27 14:53:41 +00:00

Not sure about having to count manually before and after this pull. Why not std::numeric_limits<int32_t>::max() to fix this wholesale?

Not sure about having to count manually before and after this pull. Why not `std::numeric_limits<int32_t>::max()` to fix this wholesale?
erickcestari (Migrated from github.com) reviewed 2026-11-27 15:08:18 +00:00
erickcestari (Migrated from github.com) commented 2026-11-27 15:08:18 +00:00

Thanks for the fast review. I've also updated another place in the same file that used manually written hex that could be replaced by std::numeric_limits<int32_t>::max()

- if (k == 0 || k >= 0x80000000) return {};
+ if (k == 0 || k > std::numeric_limits<int32_t>::max()) return {};
Thanks for the fast review. I've also updated another place in the same file that used manually written hex that could be replaced by `std::numeric_limits<int32_t>::max()` ```diff - if (k == 0 || k >= 0x80000000) return {}; + if (k == 0 || k > std::numeric_limits<int32_t>::max()) return {}; ```
kevkevinpal commented 2026-12-01 16:37:43 +00:00 (Migrated from github.com)

tACK 54be7fb

Built with -DBUILD_FOR_FUZZING=ON -DSANITIZERS=fuzzer the coverage increased cov 4670 -> 4681

Overall, this change makes sense since we were not covering the full range, and now we are.

tACK [54be7fb](https://github.com/bitcoin/bitcoin/pull/36996/commits/54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c) Built with `-DBUILD_FOR_FUZZING=ON -DSANITIZERS=fuzzer` the coverage increased `cov 4670 -> 4681` Overall, this change makes sense since we were not covering the full range, and now we are.
marcofleon (Migrated from github.com) reviewed 2026-12-02 16:11:32 +00:00
marcofleon (Migrated from github.com) left a comment

crACK 54be7fb7e1

crACK 54be7fb7e1726ac5aa80ac5e8a9196e0cf68339c
darosior (Migrated from github.com) reviewed 2026-12-02 22:03:55 +00:00
darosior (Migrated from github.com) commented 2026-12-02 22:03:55 +00:00

For what it's worth i think SEQUENCE_LOCKTIME_DISABLE_FLAG is more self-documenting than int32_t::max() here. (Not worth changing now, just saying. --And thanks for fixing a bug i introduced.)

For what it's worth i think `SEQUENCE_LOCKTIME_DISABLE_FLAG` is more self-documenting than int32_t::max() here. (Not worth changing now, just saying. --And thanks for fixing a bug i introduced.)
Sign in to join this conversation.
No reviewers
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!36996
No description provided.