fix(crisp): account for remainder in multi-option segment boundaries#1345
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds remainder-based offset to circuit segment indexing to handle non-divisible polynomial degrees; introduces test helper and SLOT_ADDRESS constant replacing static LEAVES; updates tests to use generated leaves; updates verifier verification key and bumps several package versions. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@examples/CRISP/circuits/src/utils.nr`:
- Line 32: Add a targeted regression test that exercises the non-divisible D
case so the new remainder logic is actually used: create a unit test that sets D
and num_options such that D % num_options != 0 (e.g., D=100, num_options=3) and
supplies a non-zero vote/coefficient so start_idx (computed from remainder,
segment_size, circuit_segment) must be correct; verify the circuit output or
index access that previously could go out-of-bounds. Update or add this test
alongside the existing tests (e.g., augment test_zero_vote_passes /
test_check_coefficient_zero_passes or add a new test) and ensure it runs for the
code paths using remainder, D, segment_size, num_options, start_idx and any
k1.reverse() logic; replicate the same regression test for the other occurrences
noted (lines referenced around 44, 105, 110) so all similar fixes are exercised.
…ries - Add remainder offset to start_idx when D is not evenly divisible by num_options - TypeScript puts remainder zeros at end; after k1.reverse() they appear at start - Fixes valid_vote constraint failure for 3+ options with D=512 (remainder=2) - Apply fix to both check_coefficient_values_with_balance and check_coefficient_zero Co-authored-by: Cursor <cursoragent@cursor.com>
- Updated @crisp-e3/sdk to 0.5.11 - Updated @crisp-e3/contracts to 0.5.11 - Updated @crisp-e3/zk-inputs to 0.5.11 - Published to npm
- Add test_non_divisible_d_vote_passes for check_coefficient_values_with_balance (D=100, num_options=3) - Add test_check_coefficient_zero_non_divisible_d_fails for check_coefficient_zero - Exercise remainder, segment_size, start_idx indexing when D % num_options != 0 Co-authored-by: Cursor <cursoragent@cursor.com>
60e3159 to
c8c1b8b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)
37-37:zeroVoteuses 2 options whilevoteuses 3 — intentional but potentially fragile.
getZeroVote(2)on line 37 is used forpreviousCiphertext(line 69) and the mask vote tests (numOptions: 2on lines 265, 288), while the real vote[10n, 0n, 0n]has 3 options. These are independent test scenarios so it's currently fine, but if someone later unifiesnumOptionsacross tests, thezeroVote(2)will silently produce the wrong-sized ciphertext.Consider deriving
zeroVotefrom a shared constant or adding a brief comment clarifying the intentional mismatch.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/CRISP/packages/crisp-sdk/tests/vote.test.ts` at line 37, zeroVote is created with getZeroVote(2) while the real vote array (vote) has 3 options, which may lead to silent size mismatches later; update tests to derive zeroVote from a shared constant or the same source used for vote (e.g., replace getZeroVote(2) with getZeroVote(NUM_OPTIONS) or construct NUM_OPTIONS and use it for both zeroVote and vote), and/or add a short comment next to getZeroVote(2) explaining the intentional mismatch referencing zeroVote, getZeroVote, vote, previousCiphertext, and numOptions so future maintainers won’t accidentally unify sizes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@examples/CRISP/packages/crisp-sdk/tests/vote.test.ts`:
- Line 37: zeroVote is created with getZeroVote(2) while the real vote array
(vote) has 3 options, which may lead to silent size mismatches later; update
tests to derive zeroVote from a shared constant or the same source used for vote
(e.g., replace getZeroVote(2) with getZeroVote(NUM_OPTIONS) or construct
NUM_OPTIONS and use it for both zeroVote and vote), and/or add a short comment
next to getZeroVote(2) explaining the intentional mismatch referencing zeroVote,
getZeroVote, vote, previousCiphertext, and numOptions so future maintainers
won’t accidentally unify sizes.
Closes #1344
check_coefficient_values_with_balanceandcheck_coefficient_zerok1.reverse()they appear at start — usestart_idx = remainder + (circuit_segment * segment_size)to align segmentstotal_votes <= balanceconstraint failure for 3+ options with D=512 (remainder=2)generateTestLeaveshelper and refactor tests to use dynamic leaves from (address, balance) pairsLEAVESwithgenerateTestLeavesin vote and utils testsSummary by CodeRabbit
Bug Fixes
Contracts
Tests
Chores