Skip to content

Conversation

jaybuidl
Copy link
Member

@jaybuidl jaybuidl commented Aug 25, 2025

PR-Codex overview

This PR focuses on enhancing the dispute resolution process in the Kleros system by introducing new functionalities to manage court jumps and vote counting after appeals, alongside updates to the hardhat.config.ts and the CHANGELOG.md.

Detailed summary

  • Updated optimizer runs from 10000 to 2000 in hardhat.config.ts.
  • Added functionality in DisputeKitClassicBase.sol for early court jumps and vote counting after appeals.
  • Updated IDisputeKit.sol to include new functions for court jumps and vote management.
  • Refactored court jump logic in KlerosCoreBase.sol to utilize new helper functions.
  • Enhanced getNbVotesAfterAppeal to calculate votes based on appeal status.
  • Updated CHANGELOG.md to reflect new features and fixes.

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

Summary by CodeRabbit

  • New Features

    • Dispute kits can trigger early court jumps and report post-appeal vote counts.
    • Appeal costs now use post-appeal vote counts for more accurate pricing.
  • Refactor

    • Centralized court/jump logic for more consistent, predictable appeal flows and signaling.
  • Chores

    • Reduced Solidity optimizer runs to 2000.
  • Documentation

    • Changelog updated noting added early-jump and post-appeal vote behaviors.

Copy link

netlify bot commented Aug 25, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 057957e
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68ae71d80451100008f62bfe
😎 Deploy Preview https://deploy-preview-2110--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

netlify bot commented Aug 25, 2025

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

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

Copy link
Contributor

coderabbitai bot commented Aug 25, 2025

Walkthrough

Centralizes court and dispute-kit jump logic in KlerosCoreBase with new internal helpers, updates appeal flow and cost calculations to use dispute-kit’s getNbVotesAfterAppeal, adds two IDisputeKit methods with DisputeKitClassicBase implementations, and lowers Hardhat Solidity optimizer runs from 10000 to 2000.

Changes

Cohort / File(s) Summary
Build Config
contracts/hardhat.config.ts
Decrease Solidity optimizer runs from 10000 to 2000 for compiler 0.8.30; no other config changes.
Core Arbitration Flow
contracts/src/arbitration/KlerosCoreBase.sol
Add internal helpers _isCourtJumping and _getCourtAndDisputeKitJumps; refactor appeal, appealCost, and isDisputeKitJumping to use these helpers and the dispute-kit getNbVotesAfterAppeal; emit CourtJump when a jump occurs; adjust extra-round assignment.
Dispute Kit Interface
contracts/src/arbitration/interfaces/IDisputeKit.sol
Add earlyCourtJump(uint256 _coreDisputeID) external view returns (bool) and getNbVotesAfterAppeal(IDisputeKit _previousDisputeKit, uint256 _currentNbVotes) external view returns (uint256) to the interface.
Dispute Kit Classic Implementation
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
Implement earlyCourtJump(uint256) (always returns false) and getNbVotesAfterAppeal(IDisputeKit, uint256) (returns _currentNbVotes * 2 + 1) as pure overrides.
Changelog
contracts/CHANGELOG.md
Add entry noting that dispute kits can force early court jumps and override votes-after-appeal (refs #2110).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant Core as KlerosCoreBase
  participant Court as Court (current)
  participant DK as DisputeKit (current)
  participant PC as Court (parent)
  participant NewDK as DisputeKit (resolved)

  U->>Core: appeal(disputeID)
  Core->>Court: load court params
  Core->>DK: earlyCourtJump(disputeID)
  DK-->>Core: jumpSignal (bool)
  Core->>Core: _isCourtJumping(round, court, disputeID)
  alt Jump required
    Core->>PC: climb to parent court
    Core->>PC: check DK support
    Core->>NewDK: choose DK (fallback to Classic if unsupported)
    Core-->>U: emit CourtJump(newCourtID, newDisputeKitID)
  else No jump
    Note right of Core: remain in current court & DK
  end
  Core->>NewDK: getNbVotesAfterAppeal(prevDK, round.nbVotes)
  NewDK-->>Core: nbVotesAfterAppeal
  Core->>Core: compute appealCost with nbVotesAfterAppeal and court fees
  Core-->>U: create next round, set extraRound.disputeKitID
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

Compatibility: ABI change 🗯

Suggested reviewers

  • unknownunknown1

Poem

Thump-thump, I hop through courts anew,
Votes double, paths decide which view.
A jump, a fall, a classic tune,
Appeals align beneath the moon.
Bunny cheers — logic neat and true. 🐇

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 e12fbb6 and 057957e.

📒 Files selected for processing (5)
  • contracts/CHANGELOG.md (1 hunks)
  • contracts/hardhat.config.ts (1 hunks)
  • contracts/src/arbitration/KlerosCoreBase.sol (4 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1 hunks)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • contracts/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • contracts/hardhat.config.ts
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
  • contracts/src/arbitration/interfaces/IDisputeKit.sol
  • contracts/src/arbitration/KlerosCoreBase.sol
⏰ 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). (10)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: contracts-testing
✨ 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/modular-jump-and-nbvotes

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

Copy link

netlify bot commented Aug 25, 2025

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

Name Link
🔨 Latest commit 057957e
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68ae71d8ffcbf5000894a557
😎 Deploy Preview https://deploy-preview-2110--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

netlify bot commented Aug 25, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 057957e
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68ae71d83ea027000840ee8a
😎 Deploy Preview https://deploy-preview-2110--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
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

🧹 Nitpick comments (7)
contracts/hardhat.config.ts (1)

34-34: Lowering optimizer runs to 2000: verify gas impact and consider making it configurable.

Reducing runs from 10000 to 2000 generally favors smaller bytecode over runtime gas. Given frequent on-chain interactions for Core/DK, this could increase users’ per-call gas. Suggest: parametrize via env so CI/prod can still use higher runs, while local/dev can use lower runs.

Apply this diff to make it configurable without code churn:

-            runs: 2000,
+            runs: parseInt(process.env.SOLC_RUNS ?? "2000"),

Suggested checks:

  • Compare gas of critical paths (createDispute, draw, passPeriod, appeal, execute) with SOLC_RUNS=10000 vs 2000 on a small scenario set.
  • Ensure no contract exceeds size limits after this change on your largest court graph.
contracts/src/arbitration/interfaces/IDisputeKit.sol (1)

116-120: New earlyCourtJump hook: good extension; document semantics wrt DK-jump vs court-jump.

The naming is clear; consider clarifying in the NatSpec that this hook only influences the court-jump decision. Whether a DK-jump happens is still determined by parent-court support (Core-side). No code change needed.

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

630-635: Make the override virtual to allow Classic derivatives to customize early jump.

If a downstream “Classic-like” DK wants to enable early jumps based on extraData or custom logic, marking this as virtual provides extension flexibility at no cost.

-    function earlyCourtJump(uint256 /* _coreDisputeID */) external pure override returns (bool) {
+    function earlyCourtJump(uint256 /* _coreDisputeID */) external pure virtual override returns (bool) {
         return false;
     }

636-642: Same here: make vote-scaling policy overrideable by Classic derivatives.

This keeps ClassicBase extensible if a sub-variant wants a different growth rule (e.g., cap or non-linear).

-    function getNbVotesAfterAppeal(uint256 _currentNbVotes) external pure override returns (uint256) {
+    function getNbVotesAfterAppeal(uint256 _currentNbVotes) external pure virtual override returns (uint256) {
         return (_currentNbVotes * 2) + 1;
     }
contracts/src/arbitration/KlerosCoreBase.sol (3)

645-651: Event round index for CourtJump: confirm whether it should reference “from” or “to” round.

You push extraRound before emitting CourtJump and pass dispute.rounds.length - 1 as _roundID (the new round). If analytics/indexers expect the jump event to reference the round being concluded (old round), this will be off by one after the push.

If the intended semantics are “the round that starts after the jump,” keep as-is but document it. If the intent is “the round that triggered the jump,” consider:

-            emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.courtID, newCourtID);
+            // Emit index of the round that triggered the jump (previous last round).
+            emit CourtJump(_disputeID, dispute.rounds.length - 2, dispute.courtID, newCourtID);

Either way, aligning the event’s _roundID semantics with docs/tests will save downstream headaches.


924-939: appealCost: correct usage of DK-defined nbVotesAfterAppeal; simplify branching.

Logic is sound and now respects DK vote-growth policy and possible early court-jumps. You can reduce duplication to one multiplication site for readability.

-        (, uint256 newDisputeKitID, bool courtJump, ) = _getCourtAndDisputeKitJumps(dispute, round, court, _disputeID);
-
-        uint256 nbVotesAfterAppeal = disputeKits[newDisputeKitID].getNbVotesAfterAppeal(round.nbVotes);
-
-        if (courtJump) {
-            // Jump to parent court.
-            if (dispute.courtID == GENERAL_COURT) {
-                // TODO: Handle the forking when appealed in General court.
-                cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent court.
-            } else {
-                cost = courts[court.parent].feeForJuror * nbVotesAfterAppeal;
-            }
-        } else {
-            // Stay in current court.
-            cost = court.feeForJuror * nbVotesAfterAppeal;
-        }
+        (, uint256 newDisputeKitID, bool courtJump, ) = _getCourtAndDisputeKitJumps(dispute, round, court, _disputeID);
+        uint256 nbVotesAfterAppeal = disputeKits[newDisputeKitID].getNbVotesAfterAppeal(round.nbVotes);
+        if (courtJump && dispute.courtID == GENERAL_COURT) {
+            // TODO: Handle the forking when appealed in General court.
+            return NON_PAYABLE_AMOUNT;
+        }
+        Court storage feeCourt = courtJump ? courts[court.parent] : court;
+        cost = feeCourt.feeForJuror * nbVotesAfterAppeal;

Note: The NON_PAYABLE_AMOUNT pattern will cause downstream DK math to revert on overflow (expected), effectively blocking funding in General Court — just ensure tests assert this path.


1047-1081: New helpers centralize jump decisions: good. Consider minor doc tweaks and boundary tests.

  • The >= comparison matches the comment in Court (“The appeal after the one that reaches this number of jurors will go to the parent”) — boundary is correct.
  • Please add in-line NatSpec to _isCourtJumping to state that the early jump is DK-signaled and may occur even if juror threshold not met.
  • Add tests for:
    • nbVotes == jurorsForCourtJump triggers jump on next appeal.
    • nbVotes == jurorsForCourtJump - 1 with earlyCourtJump=false does not jump.
    • earlyCourtJump=true causes jump irrespective of threshold.
    • isDisputeKitJumping returns false when parent supports current DK, true otherwise.

I can draft Hardhat tests covering these scenarios if helpful.

📜 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 9618a6f and 45cf8b4.

📒 Files selected for processing (4)
  • contracts/hardhat.config.ts (1 hunks)
  • contracts/src/arbitration/KlerosCoreBase.sol (4 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1 hunks)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol (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). (11)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: contracts-testing
🔇 Additional comments (2)
contracts/src/arbitration/interfaces/IDisputeKit.sol (1)

121-125: Breaking IDisputeKit change verified – all internal DKs updated

  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol implements both
    earlyCourtJump(...)
    getNbVotesAfterAppeal(...)
  • No other contract … is IDisputeKit declarations are missing these methods.

Please ensure any downstream packages or external DK implementations are also updated to include these interface methods to avoid compilation breaks.

contracts/src/arbitration/KlerosCoreBase.sol (1)

1027-1033: isDisputeKitJumping now delegates to _isCourtJumping: LGTM.

This correctly distinguishes “court jump needed?” from “DK switch needed?” and preserves the existing parent-support check.

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 25, 2025
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: 1

🧹 Nitpick comments (1)
contracts/src/arbitration/interfaces/IDisputeKit.sol (1)

116-120: Clarify “early court jump” trigger semantics and tighten NatSpec

The name/docs can be read as “is the dispute currently jumping,” whereas Core likely queries this to decide “should the next appeal transition jump to parent.” Make the trigger point explicit so DKs implement deterministically.

Apply this doc-only diff for precision:

-    /// @dev Returns true if the dispute is jumping to a parent court.
-    /// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
-    /// @return Whether the dispute is jumping to a parent court or not.
+    /// @dev Indicates whether this Dispute Kit requests Kleros Core to jump to the parent court
+    ///      on the next round/appeal transition of the given dispute.
+    /// @param _coreDisputeID The ID of the dispute in Kleros Core (not in the Dispute Kit).
+    /// @return shouldJump True if Core must perform a parent-court jump at the next appeal transition.
+    /// @notice Must be a pure/read-only decision based on the dispute’s state; no storage writes.
+    /// @dev Implementations SHOULD be deterministic and not depend on block.timestamp or randomness.

Optionally consider renaming to shouldEarlyCourtJump for self-documenting intent. Low priority since this is a draft and call sites are confined to Core.

Please confirm KlerosCoreBase calls this exactly once per appeal transition (before computing costs/nbVotes) to avoid inconsistent cost derivations when the value could change mid-flow.

📜 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 45cf8b4 and e12fbb6.

📒 Files selected for processing (3)
  • contracts/src/arbitration/KlerosCoreBase.sol (4 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1 hunks)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
  • contracts/src/arbitration/KlerosCoreBase.sol
⏰ 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: SonarCloud
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 27, 2025
@jaybuidl jaybuidl marked this pull request as ready for review August 27, 2025 02:47
@jaybuidl jaybuidl force-pushed the feat/modular-jump-and-nbvotes branch from 285c04b to 057957e Compare August 27, 2025 02:47
Copy link

@jaybuidl jaybuidl merged commit 057957e into dev Aug 27, 2025
15 of 20 checks passed
@jaybuidl jaybuidl deleted the feat/modular-jump-and-nbvotes branch August 27, 2025 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant