Skip to content

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Oct 6, 2025

PR-Codex overview

This PR focuses on enhancing the dispute handling in the DisputeKitClassicBase contract, specifically addressing scenarios where disputes jump between different dispute kits. It includes new logic for managing local dispute IDs and supports testing for recurring dispute kit appeals.

Detailed summary

  • Modified dispute creation logic to handle jumping between dispute kits.
  • Introduced checks for active dispute kits to retrieve local dispute IDs.
  • Updated the Dispute structure initialization based on dispute kit jumps.
  • Added a new test function test_appeal_recurringDK to validate dispute kit jumping behavior.
  • Established relationships between multiple courts and dispute kits in tests.
  • Implemented assertions to verify dispute state and transitions during appeals.

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

Summary by CodeRabbit

  • Bug Fixes

    • Prevents creation of duplicate disputes when re-entering an already-active core dispute.
    • Resets dispute state on re-entry (clearing jump state), improving reliability during appeals and dispute-kit jumps.
  • Tests

    • Added a comprehensive end-to-end test for recurring dispute-kit and court jumps across multiple rounds.
    • Validates transitions, funding, draws, votes, appeals, execution, and reward withdrawals across repeated jumps.

Copy link

netlify bot commented Oct 6, 2025

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

Name Link
🔨 Latest commit 3d197d6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68e6c88a894be20008530518

Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Walkthrough

Updates DisputeKitClassicBase.createDispute to reuse an existing active local dispute for a given coreDisputeID (resetting dispute.jumped) instead of always creating a new one. Adds a Foundry test exercising recurring dispute-kit and court jumps across multiple rounds and appeal flows.

Changes

Cohort / File(s) Summary
Dispute kit core logic
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
Modified createDispute to check coreDisputeIDToActive; if active, reuse coreDisputeIDToLocal[_coreDisputeID] and reset dispute.jumped; otherwise create new local dispute and initialize coreDisputeIDToLocal and coreDisputeIDToActive. Removed redundant mapping assignments.
Appeals tests
contracts/test/foundry/KlerosCore_Appeals.t.sol
Added test_appeal_recurringDK() to validate multi-round, inter-court/dispute-kit jumps (dk3↔dk2), funding and appeal flows, draw/vote behavior during jumps, and reward/withdrawal sequences across rounds.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Core as KlerosCore
  participant DK as DisputeKitClassicBase
  participant Map as Mappings

  Core->>DK: createDispute(_coreDisputeID, _numberOfChoices, _extraData)
  DK->>Map: coreDisputeIDToActive[_coreDisputeID]?
  alt Active dispute exists
    DK->>Map: localID = coreDisputeIDToLocal[_coreDisputeID]
    DK->>DK: load dispute(localID)
    DK->>DK: dispute.jumped = false
    DK-->>Core: return localID
  else No active dispute
    DK->>DK: create new local dispute (init numberOfChoices, extraData)
    DK->>Map: coreDisputeIDToLocal[_coreDisputeID] = newID
    DK->>Map: coreDisputeIDToActive[_coreDisputeID] = true
    DK-->>Core: return newID
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Suggested labels

Type: Bug :bug:, Package: Contracts

Poem

A rabbit hops through courts of three,
One burrow reused, no duplicate tree.
Jump flags settle, rounds march on,
Appeals skip, then finish at dawn.
I twitch my whiskers — code is neat, hooray! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the key change of enabling recurring dispute kit (DK) handling and aligns directly with the updates in dispute creation logic and tests for cross-DK jumps. It is specific, concise, and focused on the main feature introduced in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/recurring-dk-test

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.

Copy link

netlify bot commented Oct 6, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 3d197d6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68e6c88a05fec800085348ec
😎 Deploy Preview https://deploy-preview-2159--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 Oct 6, 2025

Deploy Preview for kleros-v2-neo ready!

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 6, 2025
Copy link

sonarqubecloud bot commented Oct 8, 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: 0

🧹 Nitpick comments (4)
contracts/test/foundry/KlerosCore_Appeals.t.sol (4)

609-619: Pin event emitters to avoid false positives

Tie expected logs to their emitters to ensure they come from the intended contracts.

Apply this diff:

-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.CourtJump(disputeID, 1, courtID3, courtID2);
-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.DisputeKitJump(disputeID, 1, dkID3, dkID2);
-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(disputeKit2));
         emit DisputeKitClassicBase.DisputeCreation(disputeID, 2, newExtraData);
-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.AppealDecision(disputeID, arbitrable);
-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.NewPeriod(disputeID, KlerosCore.Period.evidence);

685-691: Also pin emitters on the second jump (and consider asserting NewPeriod)

Use specific emitters here as well; optionally assert NewPeriod(evidence) like in the first jump.

-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.CourtJump(disputeID, 2, courtID2, GENERAL_COURT);
-        vm.expectEmit(true, true, true, true);
+        vm.expectEmit(address(core));
         emit KlerosCore.DisputeKitJump(disputeID, 2, dkID2, dkID3);
+        vm.expectEmit(address(core));
+        emit KlerosCore.NewPeriod(disputeID, KlerosCore.Period.evidence);

605-606: Avoid magic funding amounts; compute from appealCost and multipliers

Hard-coded values (0.63, 0.42, 1.35, 0.9 ether) will drift if fees/multipliers change. Derive from core.appealCost(disputeID).

Example:

-        disputeKit3.fundAppeal{value: 0.63 ether}(disputeID, 1);
+        uint256 ac1 = core.appealCost(disputeID);
+        uint256 lose1 = ac1 + (ac1 * 20000) / Constants.MULTIPLIER_DIVISOR;
+        disputeKit3.fundAppeal{value: lose1}(disputeID, 1);
...
-        disputeKit3.fundAppeal{value: 0.42 ether}(disputeID, 2);
+        uint256 win1 = ac1 + (ac1 * 10000) / Constants.MULTIPLIER_DIVISOR;
+        disputeKit3.fundAppeal{value: win1}(disputeID, 2);
...
-        disputeKit2.fundAppeal{value: 1.35 ether}(disputeID, 1);
+        uint256 ac2 = core.appealCost(disputeID);
+        uint256 lose2 = ac2 + (ac2 * 20000) / Constants.MULTIPLIER_DIVISOR;
+        disputeKit2.fundAppeal{value: lose2}(disputeID, 1);
...
-        disputeKit2.fundAppeal{value: 0.9 ether}(disputeID, 2);
+        uint256 win2 = ac2 + (ac2 * 10000) / Constants.MULTIPLIER_DIVISOR;
+        disputeKit2.fundAppeal{value: win2}(disputeID, 2);

Note: If multipliers are accessible via getters, prefer them over literals.

Also applies to: 620-621, 683-684, 690-691


758-766: Optional: assert total rounds after the second jump

Quick sanity on core-side tracking.

         core.executeRuling(disputeID); // winning choice is 2
+        assertEq(core.getNumberOfRounds(disputeID), 3, "Should have 3 rounds after two appeals");
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 514a047 and 3d197d6.

📒 Files selected for processing (1)
  • contracts/test/foundry/KlerosCore_Appeals.t.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). (14)
  • 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: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Analyze (javascript)
  • GitHub Check: hardhat-tests
🔇 Additional comments (1)
contracts/test/foundry/KlerosCore_Appeals.t.sol (1)

470-793: Thorough recurring DK/court jump scenario — looks solid

Covers re-entry semantics, round mapping, jump gating, events, and withdrawals end-to-end. No blockers.

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.

Contracts: Possible bug when a dispute jumps back to a previously used Dispute Kit

2 participants