Skip to content

Support for recovery hash in Shutter DK #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Aug 20, 2025

Closes #2016

⚠️ ABI BREAKING CHANGES

  • Extra parameter _recoveryCommit in the event CommitCastShutter
  • New storage variable recoveryCommitments in DisputeKitShutter which collides with DisputeKitBase.wNative added recently.

These changes require a full redeploy, not an upgrade.


PR-Codex overview

This PR focuses on enhancing the DisputeKitClassicBase and DisputeKitShutter contracts by improving vote handling, adding new functionality for expected vote hashes, and optimizing configurations.

Detailed summary

  • Added evmVersion and updated optimizer settings in hardhat.config.ts and foundry.toml.
  • Refactored vote handling in DisputeKitClassicBase.sol to use local IDs.
  • Introduced getExpectedVoteHash function to compute expected vote hashes.
  • Modified hashVote to handle justification differently based on the caller.
  • Updated CommitCastShutter event to include _recoveryCommit.
  • Enhanced castCommitShutter to store recovery commitments.
  • Added error handling for empty recovery commitments.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added recovery commitment support for Shutter commits; committing now requires a non-empty recovery commitment and emits it in events.
    • Enhanced hidden-vote verification for more reliable vote validation.
    • Juror-assisted hashing behavior to facilitate secure vote recovery flows.
  • Refactor

    • Streamlined vote-casting logic for improved consistency and reliability.
  • Chores

    • Upgraded EVM target to Cancun and increased optimizer runs for compiled contracts.
    • Bumped Solidity version in Shutter module to ^0.8.28.

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-university failed. Why did it fail? →

Name Link
🔨 Latest commit c32e09c
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/68a646e6c8477700089536f0

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit c32e09c
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68a646e676e9bd0007b410d4
😎 Deploy Preview https://deploy-preview-2100--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit c32e09c
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68a646e6b62d9d000821aff9
😎 Deploy Preview https://deploy-preview-2100--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

Walkthrough

Adds Cancun EVM targeting in Foundry/Hardhat configs. In DisputeKitClassicBase, refactors vote-cast indexing, introduces expected-hash retrieval, and changes hashVote to view. In DisputeKitShutter, implements juror recovery: stores recovery commitments, distinguishes juror vs non-juror reveal paths, updates events, guards empty recovery commit, and adapts hashing.

Changes

Cohort / File(s) Summary
Build configuration (EVM Cancun)
contracts/foundry.toml, contracts/hardhat.config.ts
Set evm_version/evmVersion to "cancun"; increase Foundry optimizer runs to 10000; no runtime logic changes.
Classic DK vote path refactor
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
Derive local IDs for disputes/rounds; add getExpectedVoteHash helper; validate hidden votes via expected vs actual hash; change hashVote from pure to view; minor param doc/name tweaks.
Shutter DK juror recovery feature
contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol
Bump pragma to ^0.8.28; add recoveryCommitments mapping and callerIsJuror transient flag; extend CommitCastShutter event and castCommitShutter to accept/store recovery commit; adjust castVote flow to set/reset callerIsJuror; hashVote now conditional (juror: choice+salt; others: choice+salt+justification); implement getExpectedVoteHash override; add EmptyRecoveryCommit error.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant DK as DisputeKitShutter
  participant Storage as Dispute/Recovery Storage

  rect rgb(245,248,255)
  note over C,DK: Commit phase (Shutter)
  C->>DK: castCommitShutter(dispute, round, voteID, commit, recoveryCommit)
  DK->>Storage: store commit (votes[].commit)
  DK->>Storage: store recoveryCommitments[dispute][round][voteID]
  DK-->>C: CommitCastShutter(..., recoveryCommit)
  end

  rect rgb(245,255,245)
  note over C,DK: Reveal phase
  C->>DK: castVoteShutter(dispute, round, voteID, choice, salt, justification)
  alt Caller is juror
    DK->>DK: callerIsJuror = true
    DK->>DK: actual = hashVote(choice,salt,justif) // choice+salt
    DK->>Storage: expected = recoveryCommitments[...]
  else Auto-reveal (non-juror)
    DK->>DK: callerIsJuror = false
    DK->>DK: actual = hashVote(choice,salt,justif) // choice+salt+justifHash
    DK->>Storage: expected = votes[...].commit
  end
  DK->>DK: compare actual vs expected
  DK-->>C: revert or accept vote
  DK->>DK: reset callerIsJuror
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Assessment against linked issues

Objective Addressed Explanation
Distinguish castVote by caller: juror recovery vs auto-reveal (#2016)
Juror recovery: verify only {vote + salt} (#2016)
Auto-reveal (non-juror): verify {vote + justification + salt} (#2016)
Store two hashes: with and without justification (Shutter DK) (#2016)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Add evm_version = "cancun" and optimizer_runs=10000 (contracts/foundry.toml, multiple lines) Build config change unrelated to Shutter juror recovery behavior.
Add evmVersion: "cancun" to Solidity compiler settings (contracts/hardhat.config.ts, multiple lines) Build config change not tied to the specified Shutter DK feature.

Suggested labels

Type: Feature🗿, Package: Contracts

Poem

I twitch my whiskers, thump with cheer,
New hashes hop—both far and near.
Jurors recall their vote, not prose,
While auto-reveals sniff every rose.
Cancun winds rustle config leaves—
And Shutter’s warren safely weaves. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/shutter-recovery-hash

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jaybuidl jaybuidl added Type: Feature🗿 Package: Contracts Court smart contracts Compatibility: ABI change 🗯 Smart contract ABI is changing. labels Aug 20, 2025
@jaybuidl jaybuidl changed the title feat: support for recovery hash in Shutter DK Support for recovery hash in Shutter DK Aug 20, 2025
Copy link

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit c32e09c
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68a646e64a2d7e0008985460
😎 Deploy Preview https://deploy-preview-2100--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol (1)

117-133: Guard against empty _voteIDs to avoid OOB revert and preserve intended error semantics

castVoteShutter reads _voteIDs[0] before delegating to _castVote. If _voteIDs is empty, this will revert with an OOB panic instead of EmptyVoteIDs. Add an explicit length check first.

Apply this diff:

-        Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];
+        if (_voteIDs.length == 0) revert EmptyVoteIDs();
+        Dispute storage dispute = disputes[coreDisputeIDToLocal[_coreDisputeID]];

Optionally, restore callerIsJuror after the call using a save/restore pattern to be future-proof against nested flows:

-        callerIsJuror = juror == msg.sender;
-        // `_castVote()` ensures that all the `_voteIDs` do belong to `juror`
-        _castVote(_coreDisputeID, _voteIDs, _choice, _salt, _justification, juror);
-        callerIsJuror = false;
+        bool prev = callerIsJuror;
+        callerIsJuror = (juror == msg.sender);
+        // `_castVote()` ensures that all the `_voteIDs` do belong to `juror`
+        _castVote(_coreDisputeID, _voteIDs, _choice, _salt, _justification, juror);
+        callerIsJuror = prev;
🧹 Nitpick comments (3)
contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol (3)

28-29: Using transient storage for caller role — correct for Cancun

Transient bool callerIsJuror is appropriate for request-scoped switching of hashing behavior and avoids persistent state. With both toolchains set to Cancun, this should work as intended.

Consider a brief NatSpec note near the declaration clarifying that it influences hashVote() behavior during castVoteShutter only.


103-115: Write recoveryCommitments only after ownership/period checks to avoid wasted gas on revert

You populate recoveryCommitments before calling _castCommit. Although a revert in _castCommit will roll back these writes, the SSTORE gas is still consumed in the failing path. Move the writes after _castCommit to avoid unnecessary gas burn on invalid calls.

Apply this diff:

-        if (_recoveryCommit == bytes32(0)) revert EmptyRecoveryCommit();
-
-        uint256 localDisputeID = coreDisputeIDToLocal[_coreDisputeID];
-        Dispute storage dispute = disputes[localDisputeID];
-        uint256 localRoundID = dispute.rounds.length - 1;
-        for (uint256 i = 0; i < _voteIDs.length; i++) {
-            recoveryCommitments[localDisputeID][localRoundID][_voteIDs[i]] = _recoveryCommit;
-        }
-
-        // `_castCommit()` ensures that the caller owns the vote
-        _castCommit(_coreDisputeID, _voteIDs, _commit);
+        if (_recoveryCommit == bytes32(0)) revert EmptyRecoveryCommit();
+
+        // `_castCommit()` ensures that the caller owns the vote and we are in commit period.
+        _castCommit(_coreDisputeID, _voteIDs, _commit);
+
+        uint256 localDisputeID = coreDisputeIDToLocal[_coreDisputeID];
+        Dispute storage dispute = disputes[localDisputeID];
+        uint256 localRoundID = dispute.rounds.length - 1;
+        for (uint256 i = 0; i < _voteIDs.length; i++) {
+            recoveryCommitments[localDisputeID][localRoundID][_voteIDs[i]] = _recoveryCommit;
+        }

150-159: Context-sensitive hashVote: confirm off-chain commit derivation matches client libraries

hashVote now depends on callerIsJuror:

  • juror path: keccak(abi.encodePacked(choice, salt))
  • non-juror path: keccak(abi.encode(choice, salt, keccak256(bytes(justification))))

This is fine for on-chain verification, but it changes expectations for off-chain commitment generation. Please confirm that the Shutter client/wallet libraries compute:

  • commit (with justification) as keccak(abi.encode(choice, salt, keccak256(bytes(justification))))
  • recoveryCommit (without justification) as keccak(abi.encodePacked(choice, salt))

If prior versions used abi.encodePacked for the justification-including commit, this is an ABI-breaking change for commit preimages.

I can scan your SDKs/examples to ensure these formulas match. Want me to run a targeted repo search?

Consider adding a NatSpec note here stating the context-dependent behavior to prevent integrator confusion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9895c7c and c32e09c.

📒 Files selected for processing (4)
  • contracts/foundry.toml (1 hunks)
  • contracts/hardhat.config.ts (1 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (3 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol (6 hunks)
⏰ 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). (15)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
  • GitHub Check: Pages changed - kleros-v2-university
🔇 Additional comments (10)
contracts/foundry.toml (1)

4-7: Aligning Cancun EVM target and raising optimizer runs — LGTM

Setting evm_version = "cancun" and bumping optimizer_runs to 10000 aligns Foundry with the Solidity 0.8.30 toolchain and the Hardhat config in this PR. This is required for transient storage (EIP-1153) used in Shutter. No action needed.

If you want an extra safety check for deterministic bytecode across toolchains, run a quick cross-build compare in CI (Foundry vs Hardhat) on a small sample contract to catch accidental setting drift.

contracts/hardhat.config.ts (1)

31-36: Hardhat now targeting Cancun — consistent with Foundry

Adding evmVersion: "cancun" keeps Hardhat in sync with Foundry and enables compilation of transient storage (used by DisputeKitShutter). Optimizer runs = 10000 also match Foundry. Looks good.

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (4)

317-332: Hidden-vote validation now routed through an overrideable expected-hash — solid hook point

Switching to localDisputeID/localRoundID and comparing hashVote(...) against getExpectedVoteHash(...) cleanly decouples “how to compute/where to fetch expected commits” from the base flow. This enables Shutter’s dual-hash scheme without touching core logic. Nice separation of concerns.


491-494: hashVote mutability change (pure → view) to allow overrides — OK

The base implementation remains keccak(choice, salt). Documenting the unused justification parameter in the signature is helpful for overrides. No issues.


715-727: New internal hook getExpectedVoteHash — good extensibility point

Providing a virtual getter for the expected hash is the right way to support alternative commitment schemes (e.g., recovery commitments in Shutter). No concerns.


737-737: Minor arg name anonymization to reduce stack footprint — fine

Renaming the Round parameter to an unused placeholder is harmless and helps with “stack too deep” pressure in downstream overrides.

contracts/src/arbitration/dispute-kits/DisputeKitShutter.sol (4)

21-23: New recoveryCommitments storage — acknowledge storage layout break

Adding recoveryCommitments is a storage-layout change versus previously deployed versions. Given the PR explicitly plans a full redeploy (not upgrade), this is acceptable. Ensure all deployment scripts and on-chain addresses reflect the redeploy plan to avoid proxy upgrades on old storage layouts.

Do you want a quick checklist PR comment for “full redeploy” steps (addresses, permit lists, court params, governor handoff, etc.)?


38-46: CommitCastShutter ABI change: _recoveryCommit added

Event shape change is ABI-breaking as noted. Make sure indexation choices match consumer needs: you kept _commit indexed and left _recoveryCommit non-indexed (reasonable since topics are limited). Communicate this to indexers/SDKs.

If downstream infra filters on the old event signature, flag them to update to the new one.


167-176: getExpectedVoteHash override correctly switches between commit and recoveryCommit

This matches the intended flows:

  • juror caller: validate against recoveryCommitments
  • non-juror caller: validate against stored commit

Looks correct.


182-183: EmptyRecoveryCommit error — good explicit revert

Clear error improves debuggability at commit time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compatibility: ABI change 🗯 Smart contract ABI is changing. Package: Contracts Court smart contracts Type: Feature🗿
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hidden votes recovery: allow juror to reveal without justification verification (Shutter DK only)
1 participant