Skip to content

refactor: clean up crisp contracts#1075

Merged
cedoor merged 2 commits into
mainfrom
refactor/crisp-contract
Dec 3, 2025
Merged

refactor: clean up crisp contracts#1075
cedoor merged 2 commits into
mainfrom
refactor/crisp-contract

Conversation

@cedoor

@cedoor cedoor commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Closes #1074


  • Aggregated the E3 mapping into a single RoundData structure.
  • Updated the function that sets the Merkle root; unused parameters are no longer passed to the contract.
  • Commented out Merkle-verification functions, as they are currently feature-flagged.
  • Removed the mock CRISP program since it was unused.

Summary by CodeRabbit

  • Refactor

    • Simplified merkle root API from setRoundData to setMerkleRoot, streamlining parameter requirements and improving usability
    • Reorganized internal state management through consolidated data structures
  • Chores

    • Removed mock contract and mock deployment scripts, consolidating to production-only deployment path
  • Documentation

    • Minor README wording refinements for improved clarity

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

@cedoor cedoor requested a review from 0xjei December 3, 2025 16:12
@vercel

vercel Bot commented Dec 3, 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 Dec 3, 2025 4:12pm
enclave-docs Skipped Skipped Dec 3, 2025 4:12pm

@coderabbitai

coderabbitai Bot commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR refactors the CRISP contract's Merkle root management by replacing the setRoundData method with a simplified setMerkleRoot API that removes token and balance threshold parameters. Mock infrastructure is deleted, and related integrations across Rust bindings, tests, and server components are updated accordingly.

Changes

Cohort / File(s) Summary
Core Contract Refactoring
examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol
Introduces RoundData struct consolidating per-E3 data; replaces multiple mappings with single e3Data mapping; renames verifier references (Verifierrisc0Verifier, HONK_VERIFIER); replaces setRoundData with setMerkleRoot(uint256 e3Id, uint256 _root); updates validate, validateInput, and verify to use new data structures; adds _processVote and _encodeLengthPrefixAndHash internal methods.
Removed Mock Infrastructure
examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockCRISPProgram.sol
File deleted entirely; removes mock contract with RoundData struct, constants, state variables, mappings, constructor, and all public functions including setRoundData, getParamsHash, validate, validateInput, verify.
Deploy Script Updates
examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
Removes conditional logic and MockCRISPProgramFactory import; deploy path now always uses CRISPProgramFactory instead of branching on USE_MOCK_INPUT_VALIDATOR.
Rust/EVM Helpers
examples/CRISP/crates/evm_helpers/src/lib.rs
Renames set_round_data method to set_merkle_root; updates signature from (e3_id: U256, merkle_root: U256, token_address: Address, balance_threshold: U256) to (e3_id: U256, merkle_root: U256); updates internal contract call accordingly.
NPM Script Cleanup
examples/CRISP/package.json, examples/CRISP/packages/crisp-contracts/package.json
Removes mock deployment npm scripts: deploy:contracts:full:mock and deploy:contracts:mock.
Tests & Server Integration
examples/CRISP/packages/crisp-contracts/tests/crisp.contracts.test.ts, examples/CRISP/server/src/server/indexer.rs
Test file updates contract call from setRoundData(e3Id, merkleRoot, nonZeroAddress, 1n) to setMerkleRoot(e3Id, merkleRoot); removes nonZeroAddress export from test utils; server indexer removes balance_threshold conversion and updates contract interaction to set_merkle_root(...) with aligned logging.
Documentation
examples/CRISP/packages/crisp-sdk/README.md
Minor wording: removes definite article "the" before "CRISP server" in description.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • CRISPProgram.sol: Significant structural refactoring with new data model (RoundData struct, consolidated mappings), verifier renaming, API changes across multiple functions, and new internal voting logic requiring careful verification of state management consistency.
  • MockCRISPProgram.sol deletion: Requires verification that no external code depends on this mock contract and that test coverage remains adequate without it.
  • Multi-layer coordination: Heterogeneous changes across Solidity, Rust, TypeScript, and configuration requiring separate reasoning for each integration point.
  • Cross-file dependencies: Updates to evm_helpers, deploy scripts, test utilities, and server indexer must align with contract API changes; inconsistencies could introduce subtle bugs.

Possibly related PRs

Suggested labels

crisp

Suggested reviewers

  • 0xjei
  • ctrlc03
  • hmzakhalid

Poem

🐰 With merkle roots now clearly named,
And mocks removed without shame,
The contract structure cleaned and bright,
We hop towards a leaner flight.
No tokens, thresholds in the way—
Just roots remain! Hooray! Hooray! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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: clean up crisp contracts' is concise and directly reflects the main objective of consolidating data structures and removing unused components in the CRISP contract.
Linked Issues check ✅ Passed The PR successfully implements the general refactoring objectives from #1074: it consolidates E3 mappings into a RoundData structure, simplifies function signatures, and removes unused mock contracts.
Out of Scope Changes check ✅ Passed All changes are aligned with the refactoring objectives. Modifications to evm_helpers, package.json scripts, test utilities, and deployment logic are all supportive of the core contract restructuring.
✨ 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 refactor/crisp-contract

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.

@cedoor cedoor marked this pull request as ready for review December 3, 2025 16:16

@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-contracts/contracts/CRISPProgram.sol (1)

19-25: Well-structured data consolidation.

The RoundData struct effectively consolidates all per-E3 state into a single mapping, improving code organization and clarity.

📜 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 e57d91c and a24e8e7.

📒 Files selected for processing (9)
  • examples/CRISP/crates/evm_helpers/src/lib.rs (2 hunks)
  • examples/CRISP/package.json (0 hunks)
  • examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol (4 hunks)
  • examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockCRISPProgram.sol (0 hunks)
  • examples/CRISP/packages/crisp-contracts/deploy/crisp.ts (2 hunks)
  • examples/CRISP/packages/crisp-contracts/package.json (0 hunks)
  • examples/CRISP/packages/crisp-contracts/tests/crisp.contracts.test.ts (2 hunks)
  • examples/CRISP/packages/crisp-sdk/README.md (1 hunks)
  • examples/CRISP/server/src/server/indexer.rs (2 hunks)
💤 Files with no reviewable changes (3)
  • examples/CRISP/packages/crisp-contracts/package.json
  • examples/CRISP/package.json
  • examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockCRISPProgram.sol
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 996
File: examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol:144-169
Timestamp: 2025-11-12T10:08:30.720Z
Learning: In the CRISP program (examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol), there are plans to move the merkle tree from the Enclave contract to the program contract itself in the future, which would allow direct calls to validateInput to be stored in the merkle tree.
📚 Learning: 2025-11-12T10:08:30.720Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 996
File: examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol:144-169
Timestamp: 2025-11-12T10:08:30.720Z
Learning: In the CRISP program (examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol), there are plans to move the merkle tree from the Enclave contract to the program contract itself in the future, which would allow direct calls to validateInput to be stored in the merkle tree.

Applied to files:

  • examples/CRISP/packages/crisp-contracts/tests/crisp.contracts.test.ts
  • examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
  • examples/CRISP/server/src/server/indexer.rs
  • examples/CRISP/crates/evm_helpers/src/lib.rs
  • examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol
📚 Learning: 2025-10-10T12:56:40.538Z
Learnt from: 0xjei
Repo: gnosisguild/enclave PR: 830
File: templates/default/README.md:123-128
Timestamp: 2025-10-10T12:56:40.538Z
Learning: In the Enclave repository, the hard-coded Hardhat development private key `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` is acceptable in template README files and documentation for local testing/interaction purposes.

Applied to files:

  • examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
📚 Learning: 2025-09-11T13:09:03.800Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 677
File: packages/enclave-contracts/scripts/deployAndSave/naiveRegistryFilter.ts:30-31
Timestamp: 2025-09-11T13:09:03.800Z
Learning: In Hardhat v3 deployment scripts, use `(await signer.provider?.getNetwork())?.name ?? "localhost"` instead of `hre.globalOptions.network` to reliably get the network name, as `hre.globalOptions.network` can be undefined in some contexts.

Applied to files:

  • examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
📚 Learning: 2025-09-11T13:09:03.800Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 677
File: packages/enclave-contracts/scripts/deployAndSave/naiveRegistryFilter.ts:30-31
Timestamp: 2025-09-11T13:09:03.800Z
Learning: In Hardhat v3, hre.network.name is not available anymore. Use hre.globalOptions.network to get the network name instead.

Applied to files:

  • examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
📚 Learning: 2025-11-05T14:12:57.814Z
Learnt from: ctrlc03
Repo: gnosisguild/enclave PR: 963
File: examples/CRISP/client/package.json:25-25
Timestamp: 2025-11-05T14:12:57.814Z
Learning: In the Enclave/CRISP codebase, `enclave-e3/sdk` and `crisp-e3/sdk` are different packages: `enclave-e3/sdk` is the general Enclave SDK, while `crisp-e3/sdk` is the CRISP-specific SDK. The CRISP client (`examples/CRISP/client`) intentionally depends on `enclave-e3/sdk`, not `crisp-e3/sdk`.

Applied to files:

  • examples/CRISP/packages/crisp-sdk/README.md
⏰ 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). (4)
  • GitHub Check: rust_integration
  • GitHub Check: Build & Push Image
  • GitHub Check: build_enclave_cli
  • GitHub Check: rust_unit
🔇 Additional comments (8)
examples/CRISP/packages/crisp-sdk/README.md (1)

3-4: LGTM!

Minor documentation wording improvement.

examples/CRISP/server/src/server/indexer.rs (1)

145-169: LGTM!

The refactored call to setMerkleRoot correctly aligns with the simplified contract API. The removal of balance_threshold from the contract call is appropriate since it's handled via E3 custom parameters.

examples/CRISP/packages/crisp-contracts/deploy/crisp.ts (1)

66-72: LGTM!

The deployment path is now simplified by consistently using CRISPProgramFactory. The library linking syntax for PoseidonT3 is correct.

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

111-111: LGTM!

Test correctly updated to use the simplified setMerkleRoot API.

examples/CRISP/crates/evm_helpers/src/lib.rs (1)

82-97: LGTM!

The Rust wrapper correctly implements the simplified setMerkleRoot API, matching the updated Solidity contract interface.

examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol (3)

65-75: LGTM!

Constructor properly validates all address parameters against zero addresses and correctly initializes immutable state.


77-85: Verify the one-time merkle root design choice.

The setMerkleRoot function can only be called once per E3 (Line 82 prevents re-setting). While this appears intentional for immutability, confirm this aligns with the expected workflow. If a merkle root needs correction after being set, there's currently no mechanism to update it.

Verify that the one-time setting design meets the intended requirements and consider whether an emergency update mechanism might be needed for operational flexibility.


208-225: LGTM! Clever vote tracking implementation.

The _processVote function uses a well-designed pattern: storing index + 1 allows differentiating between "no vote" (0) and "vote at index 0" (stored as 1). This correctly handles both first votes and re-votes.

Comment thread examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol

@0xjei 0xjei 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

@cedoor cedoor merged commit 4af29b0 into main Dec 3, 2025
28 checks passed
hmzakhalid pushed a commit that referenced this pull request Dec 3, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 9, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 9, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 10, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 10, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 10, 2025
ctrlc03 pushed a commit that referenced this pull request Dec 10, 2025
@github-actions github-actions Bot deleted the refactor/crisp-contract branch December 11, 2025 02:53
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.

General refactoring of the CRISP contract (CRISPProgram)

2 participants