fix(zk): Constrain usernameHash input in MerkleUpdateProof#222
fix(zk): Constrain usernameHash input in MerkleUpdateProof#222sheyman546 wants to merge 1 commit intoAlien-Protocol:mainfrom
Conversation
- Replace unconstrained usernameHash input with username[32] array - Instantiate UsernameHash() component internally for proper hash computation - Update test suite to work with new constrained input format - Prevent arbitrary field element injection into Merkle tree registry Fixes Alien-Protocol#174 - Security vulnerability Finding F-02
|
@sheyman546 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughThis PR implements the security fix for Finding F-02 by replacing an unconstrained Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
zk/circuits/merkle/merkle_update_proof.circom (1)
72-72:⚠️ Potential issue | 🔴 CriticalCritical: Multiple main components causing compilation failure.
The compilation is failing with
error[P1002]: Multiple main components. The codebase contains 7 separate files defining acomponent main:
- zk/circuits/username_merkle.circom
- zk/circuits/merkle_update.circom
- zk/circuits/username_hash.circom
- zk/circuits/merkle/username_leaf_main.circom
- zk/circuits/merkle/merkle_update_proof.circom
- zk/circuits/merkle/merkle_non_inclusion.circom
- zk/circuits/merkle/merkle_inclusion.circom
This is a project-level structural issue. Circom compilation expects either:
- Each circuit compiled independently (separate build steps)
- A single entry point file with one main that imports and uses templates from other files
Resolve by updating the build configuration to compile circuits separately or restructuring to have a single aggregated entry point with auxiliary templates.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@zk/circuits/merkle/merkle_update_proof.circom` at line 72, Multiple files define a top-level "component main" causing Circom error[P1002]; choose one fix: either (A) create a single aggregator entrypoint that defines the sole "component main" and imports templates from the listed files (zk/circuits/username_merkle.circom, merkle_update.circom, username_hash.circom, merkle/username_leaf_main.circom, merkle/merkle_update_proof.circom, merkle/merkle_non_inclusion.circom, merkle/merkle_inclusion.circom) and remove or convert their local "component main" declarations into named templates, or (B) update the build pipeline to compile each circuit file independently (one circom compile per file) and delete extra "component main" declarations from files that should be libraries; ensure only the chosen file/template retains "component main" so only one entrypoint exists during compilation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@zk/circuits/merkle/merkle_update_proof.circom`:
- Line 72: Multiple files define a top-level "component main" causing Circom
error[P1002]; choose one fix: either (A) create a single aggregator entrypoint
that defines the sole "component main" and imports templates from the listed
files (zk/circuits/username_merkle.circom, merkle_update.circom,
username_hash.circom, merkle/username_leaf_main.circom,
merkle/merkle_update_proof.circom, merkle/merkle_non_inclusion.circom,
merkle/merkle_inclusion.circom) and remove or convert their local "component
main" declarations into named templates, or (B) update the build pipeline to
compile each circuit file independently (one circom compile per file) and delete
extra "component main" declarations from files that should be libraries; ensure
only the chosen file/template retains "component main" so only one entrypoint
exists during compilation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e1c0d50e-1c9c-4504-89a9-578802cfeb48
📒 Files selected for processing (3)
SECURITY_FIX_SUMMARY.mdzk/circuits/merkle/merkle_update_proof.circomzk/tests/test_update_proof.js
|
Hello @sheyman546 , fix this |
Fixes #174 - Security vulnerability Finding F-02
closes #174
Summary by CodeRabbit
Release Notes
Bug Fixes
Breaking Changes
usernameHashinput parameter has been replaced with ausername[32]array format.