Skip to content

refactor: add isMaskVote to crisp circuit and sdk#1177

Merged
ctrlc03 merged 7 commits into
mainfrom
refactor/crisp-circuit
Jan 21, 2026
Merged

refactor: add isMaskVote to crisp circuit and sdk#1177
ctrlc03 merged 7 commits into
mainfrom
refactor/crisp-circuit

Conversation

@cedoor

@cedoor cedoor commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Closes #1176

This PR simplifies the CRISP circuit by introducing an isMaskVote private input flag instead of inferring vote type from signature validity and address matching.

Changes:

  • Added is_mask_vote boolean parameter to the circuit's main function
  • Refactored vote type detection to use the explicit flag rather than checking signature validity and address match
  • For actual votes (is_mask_vote == false): verify signature and address match within the circuit
  • For mask votes (is_mask_vote == true): skip signature/address checks and verify vote is zero
  • Updated check_coefficient_zero function to use assertions instead of returning a boolean
  • Updated SDK types and vote generation functions to include isMaskVote parameter
  • Updated tests to pass the new isMaskVote flag

Summary by CodeRabbit

  • New Features

    • Added mask-vote support via a new boolean flag to select actual-vote or mask-vote paths; circuit returns appropriate commitment(s) per path.
  • Refactor

    • Verification flow reorganized for vote-type branching; signature checking now asserts validity (fails on invalid); outputs made commitment-centric.
  • Chores

    • On-chain verifier parameters and verification key updated for larger circuit size.
    • Example server env: extended E3 duration.
  • SDK

    • SDK/input interfaces and proof generation wired to the new mask-vote flag.
  • Tests

    • Tests updated for mask-vote paths and assertion-based signature validation.

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

@vercel

vercel Bot commented Jan 21, 2026

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Review Updated (UTC)
crisp Skipped Skipped Jan 21, 2026 2:05pm
enclave-docs Skipped Skipped Jan 21, 2026 2:05pm

Request Review

@cedoor cedoor requested a review from ctrlc03 January 21, 2026 10:55
@coderabbitai

coderabbitai Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds an is_mask_vote flag propagated from SDK to circuit, refactors signature and coefficient checks to assertion-style, and reorganizes main circuit flow to branch on mask vs actual votes and return ciphertext commitments; updates Solidity verifier parameters and verification key values.

Changes

Cohort / File(s) Summary
Circuit Core Logic
examples/CRISP/circuits/src/main.nr
Add is_mask_vote: bool input; reorder steps (Merkle eligibility → GRECO → vote-type logic); branch actual-vote (balance check, validate_signature, derive address, assert slot equality → return ct_commitment) vs mask-vote (enforce k1 == 0; first-vote vs updating-slot flows → return ct_commitment or sum_ct_commitment)
ECDSA Verification
examples/CRISP/circuits/src/ecdsa.nr
Rename verify_signaturevalidate_signature; switch to assertion-style (no boolean return); update tests to use assertions
Circuit Utilities
examples/CRISP/circuits/src/utils.nr
Change check_coefficient_zero<…>(k1) return type from bool to unit; replace boolean aggregation with asserts that coefficients are zero; update tests accordingly
Solidity Verifier
examples/CRISP/packages/crisp-contracts/contracts/CRISPVerifier.sol
Increase N → 524288 and LOG_N → 19; update VK_HASH and full verification key point data to regenerated values (public input count remains 22)
TypeScript SDK Types
examples/CRISP/packages/crisp-sdk/src/types.ts
Add is_mask_vote: boolean to CircuitInputs and isMaskVote: boolean to ProofInputs
Vote Proof Generation (SDK)
examples/CRISP/packages/crisp-sdk/src/vote.ts
Propagate isMaskVote into generated circuit inputs; generateVoteProof() sets false, generateMaskVoteProof() sets true
SDK Tests
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
Update tests to pass isMaskVote into generateCircuitInputs() for mask and non-mask cases
Server Config Example
examples/CRISP/server/.env.example
Tweak E3_DURATION from 60 → 70

Sequence Diagram(s)

sequenceDiagram
    participant SDK as TypeScript SDK
    participant Circuit as CRISP Circuit
    participant Verifier as Solidity Verifier

    rect rgba(200,200,255,0.5)
    alt Actual vote (is_mask_vote = false)
        SDK->>SDK: generateVoteProof(isMaskVote=false)
        SDK->>Circuit: submit circuit inputs (is_mask_vote=false)
        Circuit->>Circuit: Merkle eligibility check
        Circuit->>Circuit: GRECO verification
        Circuit->>Circuit: validate_signature (assert)
        Circuit->>Circuit: derive address, assert equals slot
        Circuit->>Circuit: compute & return ct_commitment
        Circuit-->>SDK: proof
        SDK->>Verifier: submit proof (public inputs)
    end
    end

    rect rgba(200,255,200,0.5)
    alt Mask vote (is_mask_vote = true)
        SDK->>SDK: generateMaskVoteProof(isMaskVote=true)
        SDK->>Circuit: submit circuit inputs (is_mask_vote=true)
        Circuit->>Circuit: Merkle eligibility check
        Circuit->>Circuit: GRECO verification
        Circuit->>Circuit: enforce k1 == 0
        alt First vote
            Circuit->>Circuit: return ct_commitment
        else Updating slot
            Circuit->>Circuit: build prev & sum commitments
            Circuit->>Circuit: verify CiphertextAddition
            Circuit->>Circuit: return sum_ct_commitment
        end
        Circuit-->>SDK: proof
        SDK->>Verifier: submit proof (public inputs)
    end
    end

    Verifier->>Verifier: loadVerificationKey() (updated N, LOG_N, VK_HASH, vk data)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested labels

crisp

Suggested reviewers

  • ctrlc03
  • 0xjei

Poem

🐰 I hopped through code and checked each vote,

With mask or voice I learned to note.
Signatures assert, commitments bloom,
Branches split and proofs find room.
A tiny rabbit cheers the crypto boom!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning One minor out-of-scope change detected: E3_DURATION was changed from 60 to 70 in .env.example, which is unrelated to the isMaskVote refactoring objective and should be in a separate PR. Remove the E3_DURATION change from .env.example as it is unrelated to the isMaskVote feature and belongs in a separate pull request.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: add isMaskVote to crisp circuit and sdk' clearly and specifically describes the main change: adding a new isMaskVote parameter across the circuit and SDK layers, which is the primary objective of this PR.
Linked Issues check ✅ Passed All coding requirements from issue #1176 are met: is_mask_vote parameter added to circuit main, signature/address verification conditional on is_mask_vote flag, mask votes enforced with zero value check, SDK types and functions updated with isMaskVote, and assertion-based validation implemented in utility functions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 10:57 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 10:57 Inactive
ctrlc03
ctrlc03 previously approved these changes Jan 21, 2026

@ctrlc03 ctrlc03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@ctrlc03 ctrlc03 enabled auto-merge (squash) January 21, 2026 11:00
Comment thread examples/CRISP/circuits/src/main.nr Outdated
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 11:12 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 11:12 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 11:15 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 11:15 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 11:16 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 11:16 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 11:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 11:29 Inactive
ctrlc03
ctrlc03 previously approved these changes Jan 21, 2026
@cedoor cedoor requested a review from ctrlc03 January 21, 2026 11:31
@cedoor cedoor force-pushed the refactor/crisp-circuit branch from e7a9302 to be6a59d Compare January 21, 2026 12:06
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 12:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 12:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 21, 2026 14:05 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp January 21, 2026 14:05 Inactive
@ctrlc03 ctrlc03 merged commit 09e35c0 into main Jan 21, 2026
27 checks passed
@ctrlc03 ctrlc03 deleted the refactor/crisp-circuit branch January 21, 2026 14:38
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.

Simplify CRISP circuit with isMaskVote private input

2 participants