Skip to content

feat: mask vote utilities#924

Merged
ctrlc03 merged 5 commits into
devfrom
feat/mask-vote
Oct 29, 2025
Merged

feat: mask vote utilities#924
ctrlc03 merged 5 commits into
devfrom
feat/mask-vote

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator

fix #923

Summary by CodeRabbit

  • New Features

    • Added masked vote generation for CRISP inputs.
  • Refactor

    • Consolidated vote encryption API to accept a unified parameter object.
    • Integrated explicit signature validity into Merkle-root gating for voter determination.
    • Signature verification now returns an explicit boolean for clearer control flow.
  • Tests

    • Updated tests and test constants to exercise the new APIs and merkle proof handling.

@ctrlc03 ctrlc03 requested a review from cedoor October 28, 2025 18:54
@vercel

vercel Bot commented Oct 28, 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 Oct 29, 2025 2:41pm
enclave-docs Skipped Skipped Oct 29, 2025 2:41pm

@ctrlc03 ctrlc03 self-assigned this Oct 28, 2025
@coderabbitai

coderabbitai Bot commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Refactors CRISP SDK vote APIs to accept a consolidated parameter object and adds generateMaskVote. ECDSA circuit verify_signature now returns bool instead of asserting; main.nr gates Merkle-root checks on signature validity. Tests and types updated to match new shapes and flows.

Changes

Cohort / File(s) Summary
Circuit signature verification
examples/CRISP/circuits/src/ecdsa.nr, examples/CRISP/circuits/src/main.nr
verify_signature now returns bool (no internal asserts). main.nr reads is_signature_valid and requires (merkle_root_calculated == merkle_root) & (is_signature_valid == true) for voter determination. Tests updated to assert returned bool.
SDK type definitions
examples/CRISP/packages/crisp-sdk/src/types.ts
Added exported interface EncryptVoteAndGenerateCRISPInputsParams consolidating encodedVote, publicKey, previousCiphertext, signature, message, merkleData, balance, and optional bfvParams.
SDK vote implementation
examples/CRISP/packages/crisp-sdk/src/vote.ts
encryptVoteAndGenerateCRISPInputs refactored to accept a single object parameter (EncryptVoteAndGenerateCRISPInputsParams). generateMaskVote added to produce masked CRISP inputs. CRISP input generation adjusted to extract hashed_message, public_key_x, public_key_y, and signature from supplied data and to populate merkle fields from merkleData.
Test support data
examples/CRISP/packages/crisp-sdk/tests/constants.ts
Added votingPowerLeaf and merkleProof exports (using generateMerkleProof) for tests.
Test API & behavior updates
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
Tests updated to call encryptVoteAndGenerateCRISPInputs with the new object param, replaced generateCRISPInputs usage with generateMaskVote, and assert new CRISP input fields (hashed_message, public_key_x/y, signature, merkle proof fields, balance).
Test formatting
examples/CRISP/packages/crisp-sdk/tests/utils.test.ts
Minor formatting/style edits (removed semicolons, adjusted commas/indentation) with no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant SDK as SDK (vote.ts)
    participant ZK as ZK Input Generator
    participant Circuit as CRISP Circuit

    Note right of Test: Normal flow — encrypt vote
    Test->>SDK: encryptVoteAndGenerateCRISPInputs({encodedVote, publicKey, previousCiphertext, signature, message, merkleData, balance})
    SDK->>ZK: generate initial CRISP inputs (vote encoding)
    ZK-->>SDK: CRISPCircuitInputs
    SDK->>SDK: extract hashed_message, public_key_x/y, signature\npopulate merkle_proof_* and balance
    SDK-->>Test: CRISPCircuitInputs (complete)

    Note right of Test: Masking flow — create zero vote
    Test->>SDK: generateMaskVote(publicKey, previousCiphertext, bfvParams?, merkleRoot)
    SDK->>ZK: generate CRISP inputs for zero vote
    ZK-->>SDK: CRISPCircuitInputs
    SDK->>SDK: fill zero-values for signature/pubkey/hashed_message\nset merkle_root to provided value
    SDK-->>Test: CRISPCircuitInputs (masked)

    Note right of Test: Circuit verification
    Test->>Circuit: verify_signature(hashed_message, pub_key_x, pub_key_y, signature)
    Circuit-->>Test: bool (is_signature_valid)
    Test->>Circuit: (if is_signature_valid) proceed with merkle_root == merkle_root_calculated check
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • examples/CRISP/packages/crisp-sdk/src/vote.ts — ensure parameter extraction, signature/hashed_message population, and BFV degree validation remain correct after refactor.
    • examples/CRISP/circuits/src/ecdsa.nr & main.nr — verify boolean-return behavior and that gating of merkle check preserves intended control flow.
    • Tests (tests/vote.test.ts, tests/constants.ts) — confirm test fixtures (merkle proof/leaf) and assertions match new input shapes.

Possibly related PRs

Suggested reviewers

  • cedoor
  • 0xjei

Poem

🐰 A tiny hop, a tidy pack of params in a nest,
Masked votes whisper zero, signatures put to test.
I nibble proofs and build the crate, then pass it on with glee—
A bool that tells the tale, and now the circuit's free. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning While most changes directly support the mask vote generation feature, some modifications appear tangential to the core requirement of issue #923. The changes to examples/CRISP/circuits/src/ecdsa.nr refactor verify_signature from an assert-based function to a bool-returning function, and examples/CRISP/circuits/src/main.nr integrates signature validity checks into the merkle root comparison logic. These signature verification changes are not explicitly required to add a vote masking SDK function and may represent broader refactoring or architectural improvements outside the stated scope. The refactoring of encryptVoteAndGenerateCRISPInputs and the new type definition appear necessary to support the generateMaskVote implementation and are reasonably scoped. The changes to signature verification logic in ecdsa.nr and main.nr should be separated into a distinct PR focused on refactoring signature handling, as they are not directly required to implement the mask vote generation utility described in issue #923. This would keep the PR focused on its primary objective and make code review and potential rollbacks clearer. The remaining changes to vote utilities, types, and tests are appropriately scoped.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: mask vote utilities" accurately reflects the primary addition to the codebase: a new generateMaskVote function and refactored vote-related utilities. The title is concise and clearly communicates the main feature being added. However, the changeset also includes significant refactoring of encryptVoteAndGenerateCRISPInputs, a new type definition EncryptVoteAndGenerateCRISPInputsParams, and changes to signature verification logic across multiple files, which are not explicitly captured in the title. The title focuses on the most prominent user-facing addition but does not fully represent the scope of refactoring and ancillary changes.
Linked Issues Check ✅ Passed Issue #923 requires adding an SDK function to generate a vote masking. The PR directly addresses this requirement by introducing the generateMaskVote function in examples/CRISP/packages/crisp-sdk/src/vote.ts, which generates a zero-value governance vote with placeholder zero values for public keys, signature, hashed_message, and merkle proof fields. The function signature and implementation align with the stated objective, and supporting changes such as the new EncryptVoteAndGenerateCRISPInputsParams type and refactoring of encryptVoteAndGenerateCRISPInputs enable the required functionality. All coding requirements implied by the issue are satisfied.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/mask-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: 1

📜 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 ebd06c3 and 5c1fcd1.

📒 Files selected for processing (8)
  • examples/CRISP/circuits/src/ecdsa.nr (4 hunks)
  • examples/CRISP/circuits/src/main.nr (2 hunks)
  • examples/CRISP/packages/crisp-sdk/src/constants.ts (1 hunks)
  • examples/CRISP/packages/crisp-sdk/src/types.ts (1 hunks)
  • examples/CRISP/packages/crisp-sdk/src/vote.ts (4 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/constants.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
examples/CRISP/packages/crisp-sdk/src/types.ts (1)
examples/CRISP/packages/crisp-sdk/src/index.ts (1)
  • IMerkleProof (19-19)
examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2)
examples/CRISP/packages/crisp-sdk/src/utils.ts (1)
  • generateMerkleTree (27-29)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (1)
  • LEAVES (16-27)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (1)
examples/CRISP/packages/crisp-sdk/src/utils.ts (1)
  • generateMerkleProof (39-80)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (7)
  • votingPowerLeaf (31-31)
  • merkleProof (32-32)
  • LEAVES (16-27)
  • MAX_DEPTH (29-29)
  • VOTE (14-14)
  • SIGNATURE (12-13)
  • MESSAGE (11-11)
examples/CRISP/packages/crisp-sdk/src/utils.ts (1)
  • generateMerkleProof (39-80)
examples/CRISP/packages/crisp-sdk/src/vote.ts (3)
  • encodeVote (60-86)
  • encryptVoteAndGenerateCRISPInputs (154-188)
  • generateMaskVote (197-228)
examples/CRISP/packages/crisp-sdk/src/vote.ts (2)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
  • DEFAULT_BFV_PARAMS (24-24)
examples/CRISP/packages/crisp-sdk/src/types.ts (3)
  • EncryptVoteAndGenerateCRISPInputsParams (208-217)
  • CRISPCircuitInputs (148-172)
  • IVote (81-90)
⏰ 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). (7)
  • GitHub Check: build_enclave_cli
  • GitHub Check: test_net
  • GitHub Check: integration_prebuild
  • GitHub Check: build_sdk
  • GitHub Check: test_contracts
  • GitHub Check: rust_integration
  • GitHub Check: rust_unit
🔇 Additional comments (16)
examples/CRISP/packages/crisp-sdk/src/types.ts (1)

205-217: LGTM! Well-structured parameter interface.

The new EncryptVoteAndGenerateCRISPInputsParams interface provides a clean, object-based API that improves the function signature's maintainability and extensibility compared to multiple positional parameters.

examples/CRISP/circuits/src/main.nr (2)

42-43: LGTM! Captures signature verification result.

Storing the boolean result from verify_signature enables the subsequent check at line 60, improving the circuit's security guarantees.


60-62: Excellent security improvement.

The updated condition now requires both a valid Merkle proof AND a valid signature to classify as a voter, preventing unauthorized votes from attackers who might obtain valid Merkle proofs without corresponding signature authority.

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

26-44: LGTM! Centralized default cryptographic values.

These constants provide standardized default values for testing and align with the test data used in the circuit's test_verify_signature_sdk_input test case in examples/CRISP/circuits/src/ecdsa.nr.

examples/CRISP/packages/crisp-sdk/tests/constants.ts (2)

7-7: LGTM! Import added for Merkle proof generation.


31-32: LGTM! Precomputed Merkle proof for test reuse.

Centralizing the merkleProof constant improves test maintainability by avoiding duplicate computation across test files.

examples/CRISP/circuits/src/ecdsa.nr (4)

10-17: LGTM! Improved API design.

Returning a boolean instead of asserting internally provides better flexibility, allowing callers to handle verification failures according to their context (as demonstrated in main.nr where it's used in a conditional).


90-90: LGTM! Test correctly updated for boolean return.


115-115: LGTM! Test correctly updated for boolean return.


138-139: LGTM! Negative test case correctly updated.

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

127-135: LGTM! Updated to use new object-based API.

The refactored function signature with a single parameter object improves readability and maintainability.


146-154: LGTM! Extended assertions for new CRISP input fields.

The test now properly validates the expanded circuit inputs including signature, public key, Merkle proof, and balance fields.


158-181: LGTM! New test for mask vote generation.

The test properly validates that generateMaskVote produces well-formed CRISP inputs with placeholder values for signature and Merkle proof data.

examples/CRISP/packages/crisp-sdk/src/vote.ts (3)

154-163: LGTM! Improved function signature with object parameter.

The refactored API using destructured object parameters enhances maintainability and makes the function call sites more readable.


176-187: LGTM! Properly spreads and extends CRISP inputs.

The function now correctly returns the complete CRISP circuit inputs including signature verification and Merkle proof fields.


197-228: Verify that hardcoded Merkle proof array lengths match circuit expectations for mask votes.

The generateMaskVote function creates placeholder circuit inputs with hardcoded merkle_proof_indices and merkle_proof_siblings arrays of length 4, while MAX_DEPTH is 20. The merkle_proof_length is hardcoded to '1'. These values appear intentional (the function generates all dummy/zero-filled data), but without circuit specifications or protocol documentation, their correctness cannot be confirmed. Tests only verify field presence, not array lengths.

Please confirm:

  1. Is length 4 correct for mask vote Merkle proofs, or should these match MAX_DEPTH (20)?
  2. Should merkle_proof_length be '1' for mask votes, or should it reflect the array length?
  3. Are there circuit constraints that define the expected structure for mask votes?

Comment thread examples/CRISP/packages/crisp-sdk/tests/vote.test.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – crisp October 28, 2025 20:37 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 28, 2025 20:37 Inactive
@ctrlc03 ctrlc03 linked an issue Oct 28, 2025 that may be closed by this pull request
Comment thread examples/CRISP/packages/crisp-sdk/src/constants.ts Outdated
@ctrlc03 ctrlc03 requested a review from cedoor October 29, 2025 11:20
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 29, 2025 11:20 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp October 29, 2025 11:20 Inactive
@ctrlc03 ctrlc03 enabled auto-merge (squash) October 29, 2025 11:20

@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-sdk/tests/vote.test.ts (1)

162-184: Strengthen balance assertion for mask vote.

The test validates the generateMaskVote function well, but the balance assertion on line 183 could be more specific. Since mask votes should have a balance of '0' (as per the implementation in vote.ts line 226), consider asserting the exact value instead of just checking that it's defined.

Apply this diff to strengthen the assertion:

-      expect(crispInputs.balance).toBeDefined()
+      expect(crispInputs.balance).toBe('0')
📜 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 db52260 and 41b4d7a.

📒 Files selected for processing (7)
  • examples/CRISP/circuits/src/ecdsa.nr (4 hunks)
  • examples/CRISP/circuits/src/main.nr (2 hunks)
  • examples/CRISP/packages/crisp-sdk/src/types.ts (1 hunks)
  • examples/CRISP/packages/crisp-sdk/src/vote.ts (4 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/constants.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • examples/CRISP/packages/crisp-sdk/tests/constants.ts
  • examples/CRISP/circuits/src/main.nr
  • examples/CRISP/packages/crisp-sdk/tests/utils.test.ts
🧰 Additional context used
🧬 Code graph analysis (3)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3)
examples/CRISP/packages/crisp-sdk/src/vote.ts (2)
  • encryptVoteAndGenerateCRISPInputs (154-188)
  • generateMaskVote (197-228)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (4)
  • SIGNATURE (12-13)
  • MESSAGE (11-11)
  • merkleProof (32-32)
  • votingPowerLeaf (31-31)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
  • DEFAULT_BFV_PARAMS (24-24)
examples/CRISP/packages/crisp-sdk/src/types.ts (1)
examples/CRISP/packages/crisp-sdk/src/index.ts (1)
  • IMerkleProof (19-19)
examples/CRISP/packages/crisp-sdk/src/vote.ts (2)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
  • DEFAULT_BFV_PARAMS (24-24)
examples/CRISP/packages/crisp-sdk/src/types.ts (3)
  • EncryptVoteAndGenerateCRISPInputsParams (208-217)
  • CRISPCircuitInputs (148-172)
  • IVote (81-90)
⏰ 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). (7)
  • GitHub Check: test_net
  • GitHub Check: build_sdk
  • GitHub Check: build_enclave_cli
  • GitHub Check: integration_prebuild
  • GitHub Check: test_contracts
  • GitHub Check: rust_integration
  • GitHub Check: rust_unit
🔇 Additional comments (6)
examples/CRISP/circuits/src/ecdsa.nr (2)

15-17: Excellent refactor to return bool instead of asserting internally.

This change improves API flexibility by allowing callers to explicitly handle signature verification failures. The approach aligns with best practices for verification functions and makes the code more composable.


90-90: Test assertions correctly updated for boolean return.

All test cases properly validate the new boolean return value, covering both successful verification (lines 90, 115) and failed verification (line 139).

Also applies to: 115-115, 139-139

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

205-217: Well-designed parameter consolidation.

The new EncryptVoteAndGenerateCRISPInputsParams interface effectively consolidates function parameters into a single object, improving API ergonomics and maintainability. The use of typed hex strings for signature and optional bfvParams demonstrates good TypeScript practices.

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

131-159: Test correctly updated for new parameter object API.

The test properly validates the refactored encryptVoteAndGenerateCRISPInputs function with comprehensive assertions for all new fields including signature components, merkle proof data, and balance.

examples/CRISP/packages/crisp-sdk/src/vote.ts (2)

154-188: Clean refactor with proper parameter validation.

The refactored function effectively uses the parameter object pattern and maintains proper validation. The extraction and transformation of signature and merkle proof data is correct, and all fields are appropriately converted to the required string format for circuit inputs.


197-214: Good implementation of mask vote generation.

The function correctly generates a zero vote for masking purposes, properly encoding it with zero voting power and generating the corresponding ZK inputs.

Comment thread examples/CRISP/packages/crisp-sdk/src/vote.ts

@cedoor cedoor 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

@vercel vercel Bot temporarily deployed to Preview – crisp October 29, 2025 14:41 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs October 29, 2025 14:41 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

♻️ Duplicate comments (1)
examples/CRISP/packages/crisp-sdk/src/vote.ts (1)

218-226: Fix merkle_proof_length inconsistency and consider extracting magic numbers.

Two issues with the placeholder field initialization:

  1. Line 224: merkle_proof_length is set to '1' while merkle_proof_indices and merkle_proof_siblings are arrays of length 4. This inconsistency was flagged in a previous review and remains unresolved.

  2. Lines 218-223: The hardcoded array lengths (32, 64, 4) are magic numbers that should ideally be extracted as named constants for maintainability.

Apply this diff to fix the inconsistency:

     public_key_x: Array.from({ length: 32 }, () => '0'),
     public_key_y: Array.from({ length: 32 }, () => '0'),
     signature: Array.from({ length: 64 }, () => '0'),
     hashed_message: Array.from({ length: 32 }, () => '0'),
     merkle_proof_indices: Array.from({ length: 4 }, () => '0'),
     merkle_proof_siblings: Array.from({ length: 4 }, () => '0'),
-    merkle_proof_length: '1',
+    merkle_proof_length: '4',
     merkle_root: merkleRoot.toString(),
     balance: '0',

Consider also extracting the array lengths as constants:

const ECDSA_PUBKEY_COMPONENT_LENGTH = 32
const ECDSA_SIGNATURE_LENGTH = 64
const MERKLE_PROOF_PLACEHOLDER_LENGTH = 4
🧹 Nitpick comments (3)
examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (1)

38-41: Unpad indices alongside siblings to keep proof arrays aligned

Slice indices to the same length as siblings to avoid verifier assumptions about equal lengths.

Apply:

-      const unpaddedProof = {
-        ...proof.proof,
-        siblings: proof.proof.siblings.slice(0, proof.length),
-      }
+      const unpaddedProof = {
+        ...proof.proof,
+        indices: proof.proof.indices.slice(0, proof.length),
+        siblings: proof.proof.siblings.slice(0, proof.length),
+      }

Optionally assert lengths before verify:

expect(unpaddedProof.siblings.length).toBe(proof.length)
expect(unpaddedProof.indices.length).toBe(proof.length)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)

162-185: Consider asserting specific placeholder values in mask vote test.

The test validates that all fields are defined but doesn't check the specific placeholder values. For better test coverage, consider asserting that placeholder fields contain expected values (e.g., balance should be '0', signature fields should be arrays of '0').

Apply this diff to add more specific assertions:

      expect(crispInputs.merkle_proof_siblings).toBeDefined()
      expect(crispInputs.merkle_proof_length).toBeDefined()
      expect(crispInputs.merkle_root).toBeDefined()
-      expect(crispInputs.balance).toBeDefined()
+      expect(crispInputs.balance).toBe('0')
+      expect(crispInputs.public_key_x).toEqual(Array.from({ length: 32 }, () => '0'))
+      expect(crispInputs.public_key_y).toEqual(Array.from({ length: 32 }, () => '0'))
+      expect(crispInputs.signature).toEqual(Array.from({ length: 64 }, () => '0'))
+      expect(crispInputs.hashed_message).toEqual(Array.from({ length: 32 }, () => '0'))
examples/CRISP/packages/crisp-sdk/src/vote.ts (1)

197-228: Consider adding inline comments explaining the masking strategy.

The generateMaskVote function creates a vote with zero values and placeholder signature/merkle fields, but it's not immediately clear from the code why these specific placeholder values are used or how mask votes integrate with the voting protocol. Adding a brief inline comment explaining the masking strategy would improve code comprehension.

For example:

export const generateMaskVote = async (
  publicKey: Uint8Array,
  previousCiphertext: Uint8Array,
  bfvParams = DEFAULT_BFV_PARAMS,
  merkleRoot: bigint,
): Promise<CRISPCircuitInputs> => {
  // Create a zero vote for masking purposes. Mask votes allow users to
  // participate in the voting protocol without revealing their actual vote,
  // using placeholder values for signature verification fields.
  const plaintextVote: IVote = {
    yes: 0n,
    no: 0n,
  }
  // ... rest of implementation
}
📜 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 41b4d7a and 5abb27b.

📒 Files selected for processing (7)
  • examples/CRISP/circuits/src/ecdsa.nr (4 hunks)
  • examples/CRISP/circuits/src/main.nr (2 hunks)
  • examples/CRISP/packages/crisp-sdk/src/types.ts (1 hunks)
  • examples/CRISP/packages/crisp-sdk/src/vote.ts (4 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/constants.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • examples/CRISP/circuits/src/ecdsa.nr
  • examples/CRISP/circuits/src/main.nr
  • examples/CRISP/packages/crisp-sdk/tests/constants.ts
  • examples/CRISP/packages/crisp-sdk/src/types.ts
🧰 Additional context used
🧬 Code graph analysis (3)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (3)
examples/CRISP/packages/crisp-sdk/src/vote.ts (2)
  • encryptVoteAndGenerateCRISPInputs (154-188)
  • generateMaskVote (197-228)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (4)
  • SIGNATURE (12-13)
  • MESSAGE (11-11)
  • merkleProof (32-32)
  • votingPowerLeaf (31-31)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
  • DEFAULT_BFV_PARAMS (24-24)
examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2)
examples/CRISP/packages/crisp-sdk/src/utils.ts (1)
  • generateMerkleTree (27-29)
examples/CRISP/packages/crisp-sdk/tests/constants.ts (1)
  • LEAVES (16-27)
examples/CRISP/packages/crisp-sdk/src/vote.ts (2)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
  • DEFAULT_BFV_PARAMS (24-24)
examples/CRISP/packages/crisp-sdk/src/types.ts (3)
  • EncryptVoteAndGenerateCRISPInputsParams (208-217)
  • CRISPCircuitInputs (148-172)
  • IVote (81-90)
⏰ 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). (7)
  • GitHub Check: test_net
  • GitHub Check: build_enclave_cli
  • GitHub Check: build_sdk
  • GitHub Check: integration_prebuild
  • GitHub Check: rust_unit
  • GitHub Check: rust_integration
  • GitHub Check: test_contracts
🔇 Additional comments (5)
examples/CRISP/packages/crisp-sdk/tests/utils.test.ts (2)

30-30: LGTM: deterministic tree setup

Tree generation from fixed LEAVES looks good for a stable test fixture.


43-43: LGTM: explicit boolean verification

Assert against true is precise here; no change needed.

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

15-15: LGTM: Import updates align with API refactoring.

The import changes correctly reflect the updated API surface, importing generateMaskVote and consolidating test constants from a shared location.

Also applies to: 19-19, 21-21


131-158: LGTM: Test correctly validates updated API and expanded output shape.

The test properly exercises the refactored encryptVoteAndGenerateCRISPInputs with the new parameter object and validates all expanded public input fields including signature, merkle proof, and balance.

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

154-188: LGTM: Breaking API change properly handled.

The refactoring to accept a single parameter object has been completed successfully. There is only one caller in the codebase (the test at examples/CRISP/packages/crisp-sdk/tests/vote.test.ts:131), and it has been correctly updated to use the new signature with all required fields: encodedVote, publicKey, previousCiphertext, signature, message, merkleData, and balance.

Comment thread examples/CRISP/packages/crisp-sdk/src/vote.ts
@ctrlc03 ctrlc03 merged commit 8d9d326 into dev Oct 29, 2025
23 checks passed
@ctrlc03 ctrlc03 deleted the feat/mask-vote branch October 29, 2025 15:00
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.

Generate masking vote

2 participants