Skip to content

refactor: remove slot empty endpoint from crisp server#1386

Merged
cedoor merged 2 commits into
mainfrom
refactor/crisp-server-calls
Mar 5, 2026
Merged

refactor: remove slot empty endpoint from crisp server#1386
cedoor merged 2 commits into
mainfrom
refactor/crisp-server-calls

Conversation

@cedoor

@cedoor cedoor commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Closes #1155

Summary by CodeRabbit

  • Breaking Changes

    • Removed the dedicated slot-empty check endpoint; consumers must treat missing ciphertext as empty.
    • Slot index queries now return signed values and indicate empty slots (e.g., -1) instead of reverting.
  • API Updates

    • Ciphertext fetches now return nullable/undefined when absent instead of throwing.
    • SDK now always requests previous ciphertext (removes pre-checks) to preserve request patterns.
  • Tests

    • Updated mocks to cover 404 (not found) responses for previous ciphertext.

@vercel

vercel Bot commented Mar 5, 2026

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
crisp Skipped Skipped Mar 5, 2026 2:17pm
enclave-docs Skipped Skipped Mar 5, 2026 2:17pm

Request Review

@coderabbitai

coderabbitai Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e075e350-1344-445d-b551-2f8e2f24ea66

📥 Commits

Reviewing files that changed from the base of the PR and between e1b4565 and 4bedc82.

📒 Files selected for processing (1)
  • examples/CRISP/server/Dockerfile
✅ Files skipped from review due to trivial changes (1)
  • examples/CRISP/server/Dockerfile

📝 Walkthrough

Walkthrough

This PR removes the separate slot-empty API and changes slot lookup semantics: getSlotIndex now returns a signed integer (-1 indicates empty) and the SDK/server treat missing previous ciphertext as undefined (404) instead of calling an extra emptiness endpoint.

Changes

Cohort / File(s) Summary
Contract & EVM bindings
examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol, examples/CRISP/crates/evm_helpers/src/lib.rs
getSlotIndex changed from unsigned to signed return (int40 / int256) so empty slots map to -1; removed isSlotEmptyByAddress. Rust binding updated to return Option<u64> and use I256.
SDK constants & state
examples/CRISP/packages/crisp-sdk/src/constants.ts, examples/CRISP/packages/crisp-sdk/src/state.ts, examples/CRISP/packages/crisp-sdk/README.md
Removed CRISP_SERVER_IS_SLOT_EMPTY_ENDPOINT and getIsSlotEmpty export. getPreviousCiphertext signature changed to `Uint8Array
SDK logic & tests
examples/CRISP/packages/crisp-sdk/src/sdk.ts, examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
Vote proof functions now unconditionally call getPreviousCiphertext() (no emptiness check). Tests updated to mock 404/200 responses. Added doc note that previous ciphertext isn't used in proof but is fetched to hide vote type.
Server models & routes
examples/CRISP/server/src/server/models.rs, examples/CRISP/server/src/server/routes/state.rs
Removed IsSlotEmptyRequest/IsSlotEmptyResponse types and the /isSlotEmpty route. handle_get_previous_ciphertext updated to handle Option<u64> and return 404 when index is None.
Misc (build)
examples/CRISP/server/Dockerfile
Bumped ARG RUST_VERSION from 1.86.0 to 1.88.0 in Dockerfile.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client SDK
    participant Server as CRISP Server
    participant Contract as CRISPProgram Contract

    rect rgba(100,150,200,0.5)
    Note over Client,Contract: Previous Flow (with isSlotEmpty)
    Client->>Server: isSlotEmpty(e3Id, address)
    Server->>Contract: getSlotIndex(e3Id, address)
    Contract-->>Server: uint40 (reverts if empty)
    Server-->>Client: {is_empty: bool}
    alt slot not empty
        Client->>Server: getPreviousCiphertext(e3Id, address)
        Server->>Contract: getSlotIndex(e3Id, address)
        Contract-->>Server: uint40
        Server-->>Client: Uint8Array
    end
    end

    rect rgba(150,200,100,0.5)
    Note over Client,Contract: New Flow (direct call)
    Client->>Server: getPreviousCiphertext(e3Id, address)
    Server->>Contract: getSlotIndex(e3Id, address)
    Contract-->>Server: int40 (-1 if empty)
    alt slot exists
        Server-->>Client: Uint8Array
    else slot empty
        Server-->>Client: 404 / undefined
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ctrlc03
  • 0xjei

Poem

🐰 One less hop to check the nest,
The slot now answers -1 at rest.
No extra call, the path is lean,
Ciphertext shows if a vote has been seen.
🥕 Hooray — the code runs clean!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the primary change: removing the slot empty endpoint from the CRISP server and SDK, which aligns with the main objective of eliminating unnecessary isSlotEmpty calls.
Linked Issues check ✅ Passed The PR successfully addresses all requirements from issue #1155: eliminates isSlotEmpty calls [multiple files], makes getPreviousCiphertext return undefined for empty slots, and adds documentation to generateVoteProof explaining why it still calls the server API.
Out of Scope Changes check ✅ Passed The Rust version bump in Dockerfile (1.86.0 to 1.88.0) is justified by the commit message as fixing a cargo-chef compatibility issue. While supporting, this change is tangentially related to the primary refactoring objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/crisp-server-calls

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.

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

25-25: Align ABI return width: Solidity declares int40, binding declares int256.

The contract's getSlotIndex function returns int40 (line 244 in CRISPProgram.sol), but the Rust binding declares int256 (line 25). This works via ABI sign-extension, but explicitly matching the return type widths or documenting the intentional widening will reduce maintenance risk and improve code clarity.

The negative sentinel handling (lines 143–147) correctly interprets negative values as empty slots, so the current implementation is functionally sound.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/CRISP/crates/evm_helpers/src/lib.rs` at line 25, The generated
binding for function getSlotIndex currently declares the return as int256 while
the Solidity contract (CRISPProgram.sol) returns int40; update the ABI/binding
declaration for getSlotIndex to match the contract's return width (int40) so the
binding signature and generated types align, or if you intentionally widen to
256 bits, add a clear comment in the binding next to getSlotIndex explaining the
deliberate sign-extension widening and why negative sentinel handling remains
valid (refer to getSlotIndex and the sentinel logic in CRISPProgram.sol).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@examples/CRISP/crates/evm_helpers/src/lib.rs`:
- Line 25: The generated binding for function getSlotIndex currently declares
the return as int256 while the Solidity contract (CRISPProgram.sol) returns
int40; update the ABI/binding declaration for getSlotIndex to match the
contract's return width (int40) so the binding signature and generated types
align, or if you intentionally widen to 256 bits, add a clear comment in the
binding next to getSlotIndex explaining the deliberate sign-extension widening
and why negative sentinel handling remains valid (refer to getSlotIndex and the
sentinel logic in CRISPProgram.sol).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d7442819-5132-4dc3-b415-5a61de12a527

📥 Commits

Reviewing files that changed from the base of the PR and between c7167ec and e1b4565.

📒 Files selected for processing (9)
  • examples/CRISP/crates/evm_helpers/src/lib.rs
  • examples/CRISP/packages/crisp-contracts/contracts/CRISPProgram.sol
  • examples/CRISP/packages/crisp-sdk/README.md
  • examples/CRISP/packages/crisp-sdk/src/constants.ts
  • examples/CRISP/packages/crisp-sdk/src/sdk.ts
  • examples/CRISP/packages/crisp-sdk/src/state.ts
  • examples/CRISP/packages/crisp-sdk/tests/vote.test.ts
  • examples/CRISP/server/src/server/models.rs
  • examples/CRISP/server/src/server/routes/state.rs
💤 Files with no reviewable changes (2)
  • examples/CRISP/packages/crisp-sdk/src/constants.ts
  • examples/CRISP/server/src/server/models.rs

@cedoor cedoor requested a review from ctrlc03 March 5, 2026 13:01
@cedoor cedoor changed the title refactor: remove is slot empty endpoint from crisp server refactor: remove slot empty endpoint from crisp server Mar 5, 2026
- cargo-chef v0.1.77 requires Rust 1.88
- Resolves Docker build failure at cargo install step

Made-with: Cursor
@vercel vercel Bot temporarily deployed to Preview – enclave-docs March 5, 2026 14:17 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp March 5, 2026 14:17 Inactive
@cedoor cedoor enabled auto-merge (squash) March 5, 2026 14:41

@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.

Thanks

@cedoor cedoor merged commit c1b2bba into main Mar 5, 2026
28 checks passed
@ctrlc03 ctrlc03 deleted the refactor/crisp-server-calls branch March 5, 2026 15:02
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.

Remove number of calls to the server in the CRISP sdk class

2 participants