Skip to content

chore: add voting token with balance 1#1172

Merged
ctrlc03 merged 3 commits into
mainfrom
chore/crisp-voting-token
Jan 19, 2026
Merged

chore: add voting token with balance 1#1172
ctrlc03 merged 3 commits into
mainfrom
chore/crisp-voting-token

Conversation

@ctrlc03

@ctrlc03 ctrlc03 commented Jan 18, 2026

Copy link
Copy Markdown
Collaborator

Fixes deployed demo on sepolia, where it is not possible to vote because of balance mismatch (crisp app hardcodes 1, and the backend creates the tree using the actual token balance)

Summary by CodeRabbit

  • New Features

    • Added a mock voting token with per-address balance caps.
  • Updates

    • Reduced minted token amount in the mint flow.
    • Improved voting flow to avoid stale callbacks.
    • Deployment/config updated to use a unified mock flag and to support mock token deployments.
    • Added mock deployment entries and helper scripts.

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

@ctrlc03 ctrlc03 requested review from cedoor and hmzakhalid January 18, 2026 22:57
@vercel

vercel Bot commented Jan 18, 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 19, 2026 8:26am
enclave-docs Skipped Skipped Jan 19, 2026 8:26am

Request Review

@coderabbitai

coderabbitai Bot commented Jan 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a mock ERC20 (MockVotingToken) with per-address cap, consolidates mock deployment flags into USE_MOCKS and updates deploy scripts/records, reduces client mint amount from 1e18→1e9, and adds getMerkleLeaves to a voting hook dependency to avoid stale closures.

Changes

Cohort / File(s) Summary
Client Hooks
examples/CRISP/client/src/hooks/generic/useMintToken.tsx, examples/CRISP/client/src/hooks/voting/useVoteCasting.ts
Mint amount reduced from BigInt(1 * 1e18) → BigInt(1 * 1e9); added getMerkleLeaves to a useCallback dependency array in useVoteCasting
Smart Contracts (Mocks)
examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol
New ERC20 mock MockVotingToken with MAX_BALANCE = 1e9, constructor mints 1e9 to deployer, public mint(address,uint256) that mints capped amount (silent no-op if cap exceeded), and decimals() override returning 18
Deployment & Packaging
examples/CRISP/packages/crisp-contracts/deploy/crisp.ts, examples/CRISP/packages/crisp-contracts/deployed_contracts.json, examples/CRISP/packages/crisp-contracts/package.json, examples/CRISP/packages/crisp-contracts/.env.example, examples/CRISP/scripts/crisp_deploy.sh
Replaced USE_MOCK_VERIFIER/related flags with unified USE_MOCKS; conditionally deploys MockVotingToken and records MockCRISPToken in deployed_contracts.json; added deploy:contracts:mock script and updated mock deploy invocations and env example

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Deployer (script)
  participant DeployTS as deploy/crisp.ts
  participant Chain as Blockchain
  participant Token as MockVotingToken
  participant Client as Web Client

  Dev->>DeployTS: run with USE_MOCKS=true
  DeployTS->>Chain: deploy MockVotingToken
  Chain-->>DeployTS: address & blockNumber
  DeployTS->>DeployTS: write deployed_contracts.json (MockCRISPToken)
  Dev->>Client: start client (uses mint hook)
  Client->>Token: call mint(to, amount=1e9)
  Token-->>Client: success / silent no-op if cap exceeded
  Client->>Client: useVoteCasting uses updated getMerkleLeaves dependency
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • cedoor
  • hmzakhalid

Poem

🐇 I hopped a build and minted small,
A capped token answers voting's call.
Flags combined, deployments sing,
Merkle leaves now wake on spring.
Tiny hops, big changes — CRISP for all! ✨

🚥 Pre-merge checks | ✅ 3
✅ 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 concisely describes adding a voting token with balance 1, which directly matches the PR's objective to fix a balance mismatch in the deployed demo by introducing a voting token with the hardcoded balance value.
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.

✨ Finishing touches
  • 📝 Generate docstrings

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

🤖 Fix all issues with AI agents
In `@examples/CRISP/packages/crisp-contracts/deploy/crisp.ts`:
- Around line 29-43: The MockVotingToken deployment is not waited on, so the
blockNumber captured in storeDeploymentArgs may be before the tx is mined;
update the MockVotingToken deployment code (where you call
ethers.deployContract('MockVotingToken')) to call and await the
contract.waitForDeployment() before calling token.getAddress() and before
calling storeDeploymentArgs (using the same pattern as other deployments like
ZKTranscriptLib/RiscZeroGroth16Verifier), and also make the network name
derivation resilient by replacing the existing chain lookup with a safe fallback
using (await owner.provider?.getNetwork())?.name ?? "localhost" so chain is
never undefined.
🧹 Nitpick comments (2)
examples/CRISP/packages/crisp-contracts/deploy/crisp.ts (1)

117-117: Avoid logging undefined token address when mocks are off.
Line 117 prints TokenAddress: undefined when USE_MOCKS is false; consider guarding the line or logging a clearer message.

examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol (1)

16-29: Use MAX_BALANCE constant and fix the stale comment.
Line 16’s “half of 10e18” doesn’t match 1e9, and 1e9 is repeated in constructor/mint. Consider using MAX_BALANCE to avoid drift.

♻️ Suggested refactor
-  // half of 10e18
+  // Cap per address for mock voting power
   uint256 public constant MAX_BALANCE = 1e9;

   constructor() ERC20("Mock Voting Token", "MVT") {
-    _mint(msg.sender, 1e9);
+    _mint(msg.sender, MAX_BALANCE);
   }

   function mint(address to, uint256) external {
-    if (balanceOf(to) + 1e9 > MAX_BALANCE) {
+    if (balanceOf(to) + MAX_BALANCE > MAX_BALANCE) {
       // silently fail
       return;
     }
-    _mint(to, 1e9);
+    _mint(to, MAX_BALANCE);
   }

Comment thread examples/CRISP/packages/crisp-contracts/deploy/crisp.ts Outdated
@vercel vercel Bot temporarily deployed to Preview – crisp January 19, 2026 08:26 Inactive
@vercel vercel Bot temporarily deployed to Preview – enclave-docs January 19, 2026 08:26 Inactive

@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

@ctrlc03 ctrlc03 merged commit 279b6e4 into main Jan 19, 2026
26 checks passed
@ctrlc03 ctrlc03 deleted the chore/crisp-voting-token branch January 19, 2026 14:06
@coderabbitai coderabbitai Bot mentioned this pull request Feb 7, 2026
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