fix: correct RevealSubstring LessThan bit widths - #321
Conversation
📝 WalkthroughWalkthrough
ChangesRevealSubstring bit-width validation
Review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/circuits/tests/reveal-substring-bit-width.test.ts (1)
10-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffText-matching assertions guard formatting, not behavior.
This test verifies the circuit source text contains the expected
LessThan(log2Ceil(...))expressions, so it will break on harmless reformatting/renames and won't catch an actual range/overflow regression (e.g., a power-of-twomaxLength). A behavioral test that compiles the circuit and feeds a power-of-two bound (mirroring the harness inreveal-substring.test.ts) would more directly protect against#289recurring. Reasonable to defer ifcircomisn't available in CI.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/circuits/tests/reveal-substring-bit-width.test.ts` around lines 10 - 20, The current assertion in reveal-substring-bit-width.test.ts is checking source text in the circuit rather than behavior, so it is brittle and misses real range/overflow regressions. Replace the string-matching expectations around the LessThan(log2Ceil(...)) expressions with a behavioral test that compiles and exercises the reveal-substring circuit using a power-of-two maxLength, following the same harness pattern used in reveal-substring.test.ts. Keep the test focused on the relevant circuit entry points and bounds so it validates actual runtime behavior instead of formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/circuits/tests/reveal-substring-bit-width.test.ts`:
- Around line 10-20: The current assertion in reveal-substring-bit-width.test.ts
is checking source text in the circuit rather than behavior, so it is brittle
and misses real range/overflow regressions. Replace the string-matching
expectations around the LessThan(log2Ceil(...)) expressions with a behavioral
test that compiles and exercises the reveal-substring circuit using a
power-of-two maxLength, following the same harness pattern used in
reveal-substring.test.ts. Keep the test focused on the relevant circuit entry
points and bounds so it validates actual runtime behavior instead of formatting.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6ad7e831-0270-4e12-8bdf-442f8dfef8c2
📒 Files selected for processing (2)
packages/circuits/helpers/reveal-substring.circompackages/circuits/tests/reveal-substring-bit-width.test.ts
Description
Fixes #289.
LessThan(n)requires both inputs to fit in[0, 2^n - 1].RevealSubstringcompared dynamic signals against exclusive upper-bound constants such asmaxLength,maxSubstringLength + 1, andmaxLength + 1, but computednfrom the constant itself. When one of those constants is a power of two, the constant cannot fit in the selected bit width.This PR updates the three
LessThanbit-width calculations so each exclusive upper-bound constant has one representable value of headroom:substringStartIndex < maxLengthuseslog2Ceil(maxLength + 1)substringLength < maxSubstringLength + 1useslog2Ceil(maxSubstringLength + 2)substringStartIndex + substringLength < maxLength + 1useslog2Ceil(maxLength + 2)It also adds a focused regression test that guards those formulas.
Validation
npx.cmd jest tests/reveal-substring-bit-width.test.ts --runInBandnpx.cmd prettier --check tests/reveal-substring-bit-width.test.tsgit diff --checkI also ran
npx.cmd jest tests/reveal-substring.test.ts --runInBand --detectOpenHandles --forceExit --verbose, but this local Windows environment does not havecircomin PATH, so the existing circuit execution tests stop atcircom --versionbefore running assertions.Summary by CodeRabbit
Bug Fixes
Tests