Skip to content

test(threading): harden ScryptControlledByCheckPowFlag against sanitizer timing jitter - #483

Merged
frstrtr merged 1 commit into
masterfrom
ltc-doge/test-threading-scrypt-margin
Jun 25, 2026
Merged

test(threading): harden ScryptControlledByCheckPowFlag against sanitizer timing jitter#483
frstrtr merged 1 commit into
masterfrom
ltc-doge/test-threading-scrypt-margin

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Problem

test/test_threading.cpp :: VerifyShareThreading.ScryptControlledByCheckPowFlag is a fragile shared sanitizer test that has been red-ing the ASan+UBSan leg on every lane's PRs (diagnosed on PR #451 — not an nmc regression).

It asserted EXPECT_LT(t_fast_us, t_scrypt_us) over only 5 reps with zero margin. The healthy fast-path cost (non-scrypt verify work W) is empirically ~equal to the scrypt baseline (S), so the ratio sits right on the 1.0x boundary. A 2.3% scheduling wobble under sanitizer instrumentation flips it red (observed 2785µs vs 2721µs) — pure noise, recurring false-stop on the whole fleet.

Fix (test-only, fenced)

  1. Ratio margin. Assert the fast loop stays under 1.5x the scrypt baseline (integer form t_fast*2 < t_scrypt*3). A removed check_pow guard makes each fast call run scrypt too (W+S, ~2.0x); the 1.5x ceiling sits midway between healthy ~1.0x and the regression ~2.0x, absorbing jitter the zero-margin compare could not.
  2. More reps (5 → 40) so per-call scheduling noise averages out.
  3. GTEST_SKIP under sanitizer builds (__SANITIZE_ADDRESS__ / __has_feature), where instrumentation distorts the verify vs scrypt paths unequally. The guard stays live on the non-sanitized legs, so regression coverage is preserved.

Stale header comment (20 reps / ">1 scrypt call") corrected to match.

Verification (workstation, GCC 13, Release)

  • test_threading builds clean; full suite 7/7 PASS, target test stable across 3 consecutive runs.
  • Sanitizer skip branch syntax-checked with __SANITIZE_ADDRESS__ forced on → compiles (GTEST_SKIP taken on the ASan leg).

Label: SAFE — test-only, no production code touched. Commit GPG-signed.

…zer jitter

The wall-clock guard asserted EXPECT_LT(t_fast_us, t_scrypt_us) over only 5
reps with zero margin. The healthy fast-path cost (non-scrypt verify work W)
is empirically ~equal to the scrypt baseline (S), so the ratio sits right on
the 1.0x boundary and a 2.3% scheduling wobble under ASan/UBSan flips it red
(observed 2785us vs 2721us), false-stopping every lane on the shared ASan leg.

Harden three ways, test-only and fenced:
 - Assert the fast loop stays under 1.5x the scrypt baseline (integer form
   t_fast*2 < t_scrypt*3). A removed check_pow guard makes each fast call run
   scrypt too (W+S, ~2.0x); 1.5x sits midway between healthy ~1.0x and the
   regression ~2.0x, absorbing jitter the zero-margin compare could not.
 - Raise reps 5 -> 40 so per-call scheduling noise averages out.
 - GTEST_SKIP under sanitizer builds (__SANITIZE_ADDRESS__ / __has_feature),
   where instrumentation distorts the verify and scrypt paths unequally; the
   guard stays live on the non-sanitized legs.

Stale header comment (20 reps / >1 scrypt call) corrected to match.
@frstrtr
frstrtr merged commit d433ca7 into master Jun 25, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant