Skip to content

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 hashing, adding recovery commitments, and optimizing the Solidity compiler settings. It also updates error handling and introduces new functions for better vote management.

Detailed summary

  • Added evmVersion configuration to hardhat.config.ts.
  • Updated foundry.toml with new optimizer settings.
  • Refactored vote handling in DisputeKitClassicBase to use local IDs.
  • Introduced getExpectedVoteHash function for retrieving vote hashes.
  • Updated hashVote function to handle justification differently.
  • Added recoveryCommitments mapping in DisputeKitShutter.
  • Enhanced castCommitShutter to handle recovery commitments.
  • Modified CommitCastShutter event to include recovery commitment.
  • Updated hashVote in DisputeKitShutter to differentiate juror calls.
  • Introduced EmptyRecoveryCommit error for better error handling.

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

Summary by CodeRabbit

  • New Features

    • Recovery-commitment support for Shutter commits; commits now require a non-empty recovery commitment and include it in events.
    • Juror-assisted hashing mode to support secure vote recovery flows.
    • Enhanced hidden-vote verification with expected-hash checking for stronger vote validation.
  • Refactor

    • Streamlined vote-casting indexing and lookup for consistency and reliability.
  • Chores

    • Upgraded EVM target to Cancun and increased optimizer runs; bumped Solidity pragma in Shutter.

Copy link

netlify bot commented Aug 20, 2025

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

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

Copy link

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit f494977
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68a766e2f5b98d0008300e63
😎 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 f494977
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68a766e2c4e38000082bf780
😎 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

Implements juror recovery for Shutter dispute kit (store recovery commits, allow juror reveal without justification, conditional hashing), refactors Classic DK vote-hash lookup and hashVote mutability, and updates build configs to target EVM "cancun" with higher optimizer runs.

Changes

Cohort / File(s) Summary
Build configuration (EVM Cancun)
contracts/foundry.toml, contracts/hardhat.config.ts
Set Foundry evm_version / Hardhat evmVersion to "cancun"; increase Foundry optimizer runs to 10000; remove certain via-ir/compiler profile entries. No runtime logic changes.
Classic DK vote-path refactor
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
Use localDisputeID/localRoundID indexing; add getExpectedVoteHash helper; validate hidden votes by comparing actual vs expected hash; change hashVote from pure to view; minor parameter renames/doc tidy.
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; add EmptyRecoveryCommit error; set/reset callerIsJuror around reveal; make hashVote conditional (juror: hash(choice+salt); non-juror: hash(choice+salt+justificationHash)); add getExpectedVoteHash override.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant DK as DisputeKitShutter
  participant S as Storage

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

  rect rgb(245,255,245)
  note over C,DK: Reveal phase
  C->>DK: castVoteShutter(dispute,round,voteID,choice,salt,justif)
  alt Caller is juror
    DK->>DK: callerIsJuror = true
    DK->>DK: actual = hashVote(choice,salt,justif)    %% returns hash(choice+salt)
    DK->>S: expected = recoveryCommitments[...]
  else Auto-reveal (non-juror)
    DK->>DK: callerIsJuror = false
    DK->>DK: actual = hashVote(choice,salt,justif)    %% returns hash(choice+salt+justifHash)
    DK->>S: expected = votes[...].commit
  end
  DK->>DK: compare actual vs expected -> accept or revert
  DK->>DK: callerIsJuror = false
  DK-->>C: result
  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) Build/config change unrelated to Shutter juror recovery objectives.
Add evmVersion: "cancun" in compiler settings (contracts/hardhat.config.ts) Build/config change not part of the linked issue requirements.

Possibly related PRs

Suggested reviewers

  • unknownunknown1

Poem

I twitch my whiskers, hop to see,
Two hashes kept — one for them, one for me.
Jurors may whisper salt, not prose,
Reveals succeed where memory grows.
Cancun winds hum through build and tree. 🐇✨

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.


📜 Recent 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 c32e09c and f494977.

📒 Files selected for processing (1)
  • contracts/foundry.toml (1 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). (12)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Analyze (javascript)
  • GitHub Check: SonarCloud
  • GitHub Check: contracts-testing
🔇 Additional comments (2)
contracts/foundry.toml (2)

7-8: Consider splitting Foundry profiles to balance optimization and compile speed

To keep high optimization for production while speeding up local tests and CI builds, introduce separate profiles with tailored optimizer runs:

• Default (prod-like)
• evm_version = “cancun”
• via_ir = true
• optimizer = true
• optimizer_runs = 10000

• Tests (fast iteration)
• evm_version = “cancun”
• via_ir = true
• optimizer = true
• optimizer_runs = 500

• CI (balanced speed/realism)
• evm_version = “cancun”
• via_ir = true
• optimizer = true
• optimizer_runs = 800

Suggested contracts/foundry.toml snippet:

 [profile.default]
 solc = "0.8.30"
 evm_version = "cancun"
 via_ir = true
 optimizer = true
-optimizer_runs = 10000
+optimizer_runs = 10000

+[profile.tests]
+# Faster local testing while preserving Cancun/via-IR
+evm_version = "cancun"
+via_ir = true
+optimizer = true
+optimizer_runs = 500

+[profile.ci]
+# Balance between speed and realism in CI
+evm_version = "cancun"
+via_ir = true
+optimizer = true
+optimizer_runs = 800

Then verify compile times and code sizes locally:

#!/bin/bash
set -euo pipefail

echo "== Default profile (prod-like) =="
time forge build --sizes

echo "== Tests profile (fast) =="
time forge build --sizes --profile tests

echo "== CI profile (balanced) =="
time forge build --sizes --profile ci

Please run these commands in your environment (Forge isn’t available in the sandbox here) and ensure no contracts approach the 24 KB size limit before merging.


4-4: Confirmed EVM Version Consistency: No older forks pinned

  • contracts/foundry.toml sets evm_version = "cancun"
  • contracts/hardhat.config.ts uses evmVersion: "cancun"
  • No occurrences of hardfork, --fork, or other EVM-version overrides were found in scripts, configs, or CI workflows
  • The only anvil --fork-url usage is in DEVNET_REDEPLOY.md—ensure your local Anvil (and any CI Anvil tasks) are at a version that supports Cancun/Dencun
  • Cannot run forge build --sizes in this sandbox; please execute it locally to detect any Cancun-only opcodes or size regressions
  • Manually verify that all target networks (Mainnet, Arbitrum, Gnosis, Sepolia, etc.) have upgraded to Cancun/Dencun and that no CI or deploy pipelines pin older forks
✨ Finishing Touches
🧪 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

netlify bot commented Aug 20, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit f494977
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68a766e20752d700080eed5c
😎 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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 20, 2025
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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