Skip to content

chore: increase max vote allowed#1103

Merged
ctrlc03 merged 2 commits into
mainfrom
chore/increase-max-vote
Dec 12, 2025
Merged

chore: increase max vote allowed#1103
ctrlc03 merged 2 commits into
mainfrom
chore/increase-max-vote

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

We need to be able to support larger values due to token supplies, unless we want to lose precision by scaling down.

Summary by CodeRabbit

  • Chores

    • Increased maximum supported vote value to 2^50 - 1 and expanded validation windows; updated tests and input vectors to match.
    • Replaced the on-chain verification key used for contract verification.
  • Documentation

    • Added guidance recommending the use of different signature messages across applications.

✏️ Tip: You can customize this high-level summary in your review settings.

@ctrlc03 ctrlc03 requested a review from 0xjei December 12, 2025 10:02
@vercel

vercel Bot commented Dec 12, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
crisp Skipped Skipped Dec 12, 2025 10:24am
enclave-docs Skipped Skipped Dec 12, 2025 10:24am

@coderabbitai

coderabbitai Bot commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR increases HALF_LARGEST_MINIMUM_DEGREE from 28 to 50 in CRISP circuit utilities and the SDK, updates MAXIMUM_VOTE_VALUE accordingly, adjusts test vectors, and replaces the verifier key data (VK_HASH and verification key G1 points) in the CRISP verifier contract.

Changes

Cohort / File(s) Summary
CRISP circuit coefficient validation
examples/CRISP/circuits/src/utils.nr
Increased HALF_LARGEST_MINIMUM_DEGREE from 28 → 50 in check_coefficient_values_with_balance and check_coefficient_zero; widened validation window and adjusted coefficient arrays/indices to match the new bounds.
SDK constants and tests
examples/CRISP/packages/crisp-sdk/src/constants.ts, examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
Bumped HALF_LARGEST_MINIMUM_DEGREE to 50 and recalculated MAXIMUM_VOTE_VALUE (now 2^50 − 1); added @notice to SIGNATURE_MESSAGE; expanded tally/test vectors with additional '0' entries to align with the larger window.
Verifier contract data
examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol
Replaced VK_HASH constant and substituted the verification key G1 point data inside loadVerificationKey; changes are data-only within the VerificationKey structure (no signature/control-flow changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review attention: ensure constant propagation across Noir and TypeScript is complete; verify test vector lengths and indices match the new HALF_LARGEST_MINIMUM_DEGREE; validate verifier key replacement (VK_HASH and G1 points) correctness and consistency with expected verifier format.

Possibly related PRs

Suggested labels

noir

Suggested reviewers

  • 0xjei
  • cedoor

Poem

🐰 I hopped the constant up a bit,

Fifty now — a wider fit.
Tests stretched long, verifier keys new,
Circuits hum a fresher tune,
Hooray — a hop, a tweak, and through!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: increase max vote allowed' accurately describes the main change across the pull request, which systematically increases HALF_LARGEST_MINIMUM_DEGREE from 28 to 50, thereby increasing MAXIMUM_VOTE_VALUE and supporting larger token supplies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/increase-max-vote

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)

29-29: Good security documentation, but unrelated to PR scope.

The @notice about signature reuse is a valuable security reminder. However, it's unrelated to the main PR objective of increasing the maximum vote value. Consider whether this should be in a separate commit for cleaner history.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab80318 and aacf6f9.

📒 Files selected for processing (3)
  • examples/CRISP/circuits/src/utils.nr (4 hunks)
  • examples/CRISP/packages/crisp-sdk/src/constants.ts (1 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-11-08T01:31:47.505Z
Learnt from: ryardley
Repo: gnosisguild/enclave PR: 969
File: packages/enclave-sdk/src/enclave-sdk.ts:101-103
Timestamp: 2025-11-08T01:31:47.505Z
Learning: In packages/enclave-sdk/src/enclave-sdk.ts, the TRBFV protocol parameter setup is intentionally incomplete as of PR #969. The constructor sets BFV_THRESHOLD parameters for TRBFV, but the encryption methods (encryptNumber, encryptVector, encryptNumberAndGenInputs, encryptVectorAndGenInputs) intentionally only support BFV and will throw "Protocol not supported" for TRBFV until future implementation is completed.

Applied to files:

  • examples/CRISP/packages/crisp-sdk/src/constants.ts
📚 Learning: 2025-08-27T13:49:48.617Z
Learnt from: 0xjei
Repo: gnosisguild/enclave PR: 648
File: examples/CRISP/circuits/src/main.nr:40-44
Timestamp: 2025-08-27T13:49:48.617Z
Learning: In CRISP circuits using Greco library, the binary check `assert(0 == b * (qmt - b))` for polynomial k1 should not be applied to all coefficients - only specific coefficients require this constraint, such as `k1.coefficients[2048 - 1]`.

Applied to files:

  • examples/CRISP/circuits/src/utils.nr
📚 Learning: 2025-09-22T15:08:29.814Z
Learnt from: ozgurarmanc
Repo: gnosisguild/enclave PR: 734
File: packages/circuits/crates/libs/polynomial/src/lib.nr:140-155
Timestamp: 2025-09-22T15:08:29.814Z
Learning: Greco (packages/circuits/crates/libs/greco/src/lib.nr) performs range_check_1bound/2bounds on all polynomials (u, e0/e1, k1, pk*, r*, p*) before serialization; packer/flatten rely on these bounds, so per-limb asserts inside packer are unnecessary in this crate’s flow.

Applied to files:

  • examples/CRISP/circuits/src/utils.nr
🧬 Code graph analysis (1)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
examples/CRISP/packages/crisp-sdk/src/index.ts (1)
  • MAXIMUM_VOTE_VALUE (9-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: crisp_unit
  • GitHub Check: build_e3_support_dev
  • GitHub Check: test_net
  • GitHub Check: build_enclave_cli
  • GitHub Check: test_contracts
  • GitHub Check: integration_prebuild
  • GitHub Check: build_ciphernode_image
  • GitHub Check: rust_integration
  • GitHub Check: rust_unit
  • GitHub Check: build_sdk
🔇 Additional comments (6)
examples/CRISP/circuits/src/utils.nr (4)

61-61: Constant update consistent with check_coefficient_values_with_balance.

The same HALF_LARGEST_MINIMUM_DEGREE increase ensures both functions validate the same coefficient window.


92-92: Test coefficient array correctly expanded.

The array now has 100 elements (50 per half) with padding zeros added to accommodate the new window size. The test validates that binary 111 (value 7) is within the balance of 1000.

Also applies to: 95-95


168-168: Test array correctly reflects expanded window boundaries.

The array expansion maintains test validity by properly positioning the non-zero coefficient at index 50 (YES section boundary).

Also applies to: 171-171


15-16: The 50-bit vote window expansion is mathematically sound and safely fits within u64 storage.

The change correctly supports vote values up to 2^50 (1,125,899,906,842,624) for both yes and no outcomes, well within the u64 bounds (2^64 - 1). The polynomial coefficients are properly validated with the assertion 0 == coeff * (q_mod_t - coeff), ensuring only binary values (0 or q_mod_t) are accepted.

No action needed on BFV compatibility—the BFV encryption degree parameter (512, 1024, 2048) is independent of this 50-bit vote window used for coefficient validation. However, note that existing proofs generated with the previous vote encoding will not be compatible with this change, as the bit positions and validation windows have shifted.

examples/CRISP/packages/crisp-sdk/src/constants.ts (1)

18-18: Constant increase drives maximum vote value expansion.

The change correctly updates HALF_LARGEST_MINIMUM_DEGREE from 28 to 50, which drives the maximum vote value from ~268 million (2^28 - 1) to ~1.125 quadrillion (2^50 - 1). The minimum BFV degree correspondingly increases from 56 to 100 to support the larger range. Verify that all usages of these constants and the BFV implementation support the expanded degree and vote value parameters.

examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)

75-96: Test data correctly expanded to match new HALF_LARGEST_MINIMUM_DEGREE value of 50.

The tally array in the decodeTally test contains 97 zero entries, maintaining the expected test assertions of yes=22n and no=1n. The expansion preserves the decoded values and aligns with the constant change from 28 to 50 (delta of 22 entries).

@vercel vercel Bot temporarily deployed to Preview – crisp December 12, 2025 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs December 12, 2025 10:24 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol (1)

14-129: Add an automated "VK points are on-curve" check to prevent bad key material merges.

The Honk.VerificationKey struct loaded in loadVerificationKey() (lines 14–129) contains hardcoded G1Point coordinates with no on-curve validation. While a validateOnCurve() function exists in this file (line 1827) and is used to validate proof points, it is not applied to the VK literals themselves. A single typo in any coordinate would only be caught as an on-chain revert during verification—a late signal. Adding a compile-time or deploy-time check to validate all VK points against the curve equation y² ≡ x³ + 3 (mod Q) would catch transcription errors earlier and prevent corrupted key material from being merged.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aacf6f9 and 6240533.

📒 Files selected for processing (1)
  • examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: build_e3_support_dev
  • GitHub Check: build_sdk
  • GitHub Check: build_enclave_cli
  • GitHub Check: test_net
  • GitHub Check: crisp_unit
  • GitHub Check: rust_integration
  • GitHub Check: rust_unit
  • GitHub Check: build_ciphernode_image
  • GitHub Check: integration_prebuild
  • GitHub Check: test_contracts

Comment thread examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol

@0xjei 0xjei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@ctrlc03 ctrlc03 enabled auto-merge (squash) December 12, 2025 10:47
@ctrlc03 ctrlc03 merged commit 6712fcd into main Dec 12, 2025
30 of 42 checks passed
@ctrlc03 ctrlc03 deleted the chore/increase-max-vote branch December 12, 2025 10:55
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.

2 participants