chore: use different signature per round#1094
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Warning Rate limit exceeded@ctrlc03 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 5 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (10)
WalkthroughThe PR introduces support for per-round message hashes throughout the CRISP voting system. Each voting round now uses a unique message hash (computed from the round ID) instead of a constant signature message, preventing signature re-use across different voting rounds. The messageHash parameter is threaded from the UI through voting hooks, down to SDK utilities and worker processes. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Hook as useVoteCasting
participant Sign as Signing
participant Proof as Proof Generation
participant Worker as crispWorker
participant SDK as CRISP SDK
User->>Hook: Cast vote with votingRound
activate Hook
Note over Hook: Compute message from round ID
Hook->>Hook: message = "Vote for round {roundId}"
Hook->>Hook: messageHash = hashMessage(message)
Hook->>Sign: signMessageAsync({ message })
activate Sign
Sign-->>Hook: signature
deactivate Sign
Note over Hook: Extract vote data
Hook->>Proof: handleProofGeneration(vote, address, signature, messageHash)
activate Proof
Proof->>Worker: postMessage({ voteId, publicKey, address, signature, messageHash, previousCiphertext })
activate Worker
Worker->>SDK: generateVoteProof({ vote, publicKey, signature, merkleLeaves, balance, messageHash, previousCiphertext })
activate SDK
Note over SDK: Use messageHash for<br/>signature component extraction
SDK->>SDK: extractSignatureComponents(signature, messageHash)
Note over SDK: Use messageHash for<br/>address derivation
SDK->>SDK: getAddressFromSignature(signature, messageHash)
SDK-->>Worker: proof
deactivate SDK
Worker-->>Proof: proof result
deactivate Worker
Proof-->>Hook: encoded proof
deactivate Proof
Hook-->>User: Proof generated & submitted
deactivate Hook
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
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 |
f7646e8 to
a06265d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)
238-254: LGTM! Test correctly updated to include messageHash.The test properly provides
SIGNATURE_MESSAGE_HASHwhich matches the message used for signing.Consider adding a negative test case that verifies proof generation fails when
messageHashdoesn't match the signed message - this would validate the replay protection works correctly.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
examples/CRISP/client/libs/crispWorker.js(2 hunks)examples/CRISP/client/src/context/voteManagement/VoteManagement.types.ts(1 hunks)examples/CRISP/client/src/hooks/voting/useVoteCasting.ts(5 hunks)examples/CRISP/client/src/hooks/wasm/useWebAssembly.tsx(2 hunks)examples/CRISP/packages/crisp-sdk/src/types.ts(2 hunks)examples/CRISP/packages/crisp-sdk/src/utils.ts(2 hunks)examples/CRISP/packages/crisp-sdk/src/vote.ts(2 hunks)examples/CRISP/packages/crisp-sdk/tests/vote.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
examples/CRISP/packages/crisp-sdk/tests/vote.test.ts (1)
examples/CRISP/packages/crisp-sdk/src/constants.ts (1)
SIGNATURE_MESSAGE_HASH(31-31)
examples/CRISP/packages/crisp-sdk/src/vote.ts (1)
examples/CRISP/packages/crisp-sdk/src/utils.ts (2)
extractSignatureComponents(89-118)getAddressFromSignature(120-124)
examples/CRISP/client/src/hooks/voting/useVoteCasting.ts (1)
packages/enclave-sdk/src/greco.ts (1)
generateProof(122-159)
⏰ 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). (8)
- GitHub Check: integration_prebuild
- GitHub Check: rust_integration
- GitHub Check: rust_unit
- GitHub Check: build_enclave_cli
- GitHub Check: test_net
- GitHub Check: test_contracts
- GitHub Check: crisp_unit
- GitHub Check: build_sdk
🔇 Additional comments (14)
examples/CRISP/packages/crisp-sdk/src/vote.ts (3)
106-109: LGTM! Correctly propagates messageHash for signature extraction.The changes properly thread the
messageHashfromproofInputstoextractSignatureComponents, enabling per-round signature verification.
157-157: LGTM! Address derivation now uses the provided messageHash.This ensures the recovered address matches the signer of the round-specific message.
170-181: Verify:generateMaskVoteProofuses default messageHash (constant).
generateMaskVoteProofdoesn't pass amessageHashtogenerateCircuitInputs, so it will fall back toSIGNATURE_MESSAGE_HASH. If mask votes should also use per-round hashes, this needs updating. If mask votes intentionally use a constant signature (sinceMASK_SIGNATUREis used), this is correct.examples/CRISP/packages/crisp-sdk/src/types.ts (2)
179-179: LGTM! Optional messageHash in ProofInputs allows fallback to default.This is appropriate for internal use where
extractSignatureComponentshas a default value.
197-197: LGTM! Required messageHash in VoteProofInputs enforces per-round uniqueness.Making this required at the public API level ensures callers must provide a round-specific hash, addressing the replay protection goal from issue #1090.
examples/CRISP/client/src/hooks/wasm/useWebAssembly.tsx (1)
26-41: LGTM! Worker communication properly includes messageHash.The
messageHashparameter is correctly added to the function signature and forwarded to the worker viapostMessage.examples/CRISP/client/libs/crispWorker.js (1)
14-36: LGTM! Worker correctly propagates messageHash to proof generation.The destructuring and forwarding to
generateVoteProofis correct and aligns with the SDK's updated API.examples/CRISP/client/src/context/voteManagement/VoteManagement.types.ts (1)
40-47: LGTM! Context type correctly updated with messageHash parameter.The signature matches the implementation in
useWebAssembly.tsx.examples/CRISP/packages/crisp-sdk/src/utils.ts (1)
89-117: LGTM! Signature extraction correctly parameterized with messageHash.The default value maintains backward compatibility while enabling per-round hash usage.
examples/CRISP/client/src/hooks/voting/useVoteCasting.ts (5)
9-9: LGTM! Correct import of hashMessage from viem.
70-76: LGTM! Proof generation callback correctly updated with messageHash.The callback signature and forwarding to
generateProofare consistent with the updated types.
111-116: Core fix for issue #1090: Per-round message signing.The message
"Vote for round ${roundState.id}"ensures each round uses a unique signature, preventing replay attacks. ThehashMessageandsignMessageAsynccorrectly use the same message content.
133-133: LGTM! messageHash correctly passed through proof generation flow.
220-220: LGTM!votingRoundadded to dependency array.This ensures
castVoteWithProofis recreated when the voting round changes, which is necessary since it's used inhandleProofGeneration.
c9df76a to
ccca242
Compare
ccca242 to
f9bc042
Compare
f9bc042 to
c0479b3
Compare
fix #1090
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.