Skip to content

fix(DisputeKit): check that dispute belongs to DK #2039

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

Merged
merged 2 commits into from
Jul 15, 2025
Merged

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Jul 9, 2025

PR-Codex overview

This PR focuses on enhancing the functionality of the DisputeKitClassicBase contract by introducing a mechanism to track the active status of dispute kits for core dispute IDs, along with minor improvements to comments and logic.

Detailed summary

  • Added mapping(uint256 coreDisputeID => bool) public coreDisputeIDToActive; to track active dispute kits.
  • Initialized coreDisputeIDToActive[_coreDisputeID] to true upon dispute creation.
  • Added checks using require(coreDisputeIDToActive[_coreDisputeID]) in several functions to ensure the dispute kit is active.
  • Updated comments for clarity.
  • Added a test function test_castVote_differentDK() to verify the functionality of the new dispute kit tracking.

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

Summary by CodeRabbit

  • New Features

    • Improved dispute validation to prevent actions on inactive disputes by adding explicit active state tracking.
    • Enhanced tracking of dispute data for better reliability when handling multiple dispute kits.
  • Tests

    • Added comprehensive test coverage for scenarios involving multiple dispute kits, ensuring correct dispute mapping and validation.
    • Improved assertion messages and added checks for dispute data consistency.

@unknownunknown1 unknownunknown1 requested a review from jaybuidl as a code owner July 9, 2025 07:12
Copy link

netlify bot commented Jul 9, 2025

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

Name Link
🔨 Latest commit 85f01b6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/6876bc0c5f92cf0008c620e0
😎 Deploy Preview https://deploy-preview-2039--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 Jul 9, 2025

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

Name Link
🔨 Latest commit 85f01b6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/6876bc0cee2b4f000849270f

Copy link

netlify bot commented Jul 9, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 85f01b6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/6876bc0c8b534a0008b0b918
😎 Deploy Preview https://deploy-preview-2039--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 bot commented Jul 9, 2025

Walkthrough

A new public mapping was added to track whether a dispute kit is active for a given core dispute ID. Functions that operate on disputes now validate this active status before proceeding. Tests were added to verify correct behavior when multiple dispute kits coexist and to ensure proper vote casting restrictions.

Changes

File(s) Change Summary
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol Added coreDisputeIDToActive mapping; updated dispute-related functions to require disputes be active; initialized jumped flag.
contracts/test/foundry/KlerosCore.t.sol Added test verifying coreDisputeIDToActive mapping; introduced test_castVote_differentDK to test dispute handling across dispute kits.

Suggested reviewers

  • unknownunknown1

Poem

🐇 A hop, a skip, a mapping new,
Tracks disputes both old and true.
Active flags keep order tight,
Votes cast only when it's right.
In courts of code, justice takes flight—
Rabbits cheer, all systems bright! 🌿✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac93ef and 85f01b6.

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

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
🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

codeclimate bot commented Jul 9, 2025

Code Climate has analyzed commit 5ac93ef and detected 0 issues on this pull request.

View more on Code Climate.

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 (3)
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (2)

256-256: Consider the order of validation checks.

The require statement correctly prevents operations on unmapped disputes. However, the notJumped modifier executes before this check and could access disputes[0] for unmapped disputes, potentially causing misleading error messages.

Consider moving this check before the modifier execution or adding it to the modifier itself:

function castCommit(
    uint256 _coreDisputeID,
    uint256[] calldata _voteIDs,
    bytes32 _commit
-) external notJumped(_coreDisputeID) {
+) external {
    (, , KlerosCore.Period period, , ) = core.disputes(_coreDisputeID);
    require(period == KlerosCoreBase.Period.commit, "The dispute should be in Commit period.");
    require(_commit != bytes32(0), "Empty commit.");
    require(coreDisputeIDToDisputeLength[_coreDisputeID] != 0, "No local dispute for core ID");
+    require(!disputes[coreDisputeIDToLocal[_coreDisputeID]].jumped, "Dispute jumped to a parent DK!");

286-286: Same modifier order issue as castCommit.

The require statement is correctly placed for validation, but the notJumped modifier could execute on unmapped disputes before this check.

Apply the same fix as suggested for castCommit to ensure proper error handling order.

contracts/test/foundry/KlerosCore.t.sol (1)

2832-2924: Comprehensive test validates dispute kit isolation

This test function effectively validates the new dispute kit validation functionality by:

  1. Creating and registering a new dispute kit
  2. Testing that different dispute kits maintain separate mappings for core dispute IDs
  3. Verifying that the coreDisputeIDToDisputeLength mapping correctly tracks dispute counts
  4. Ensuring that cross-dispute kit operations fail with appropriate error messages
  5. Confirming that voting works correctly within the proper dispute kit

The test logic is sound and follows good testing practices with proper setup, execution, and assertion phases.

A few observations for consideration:

  • The test creates 3 disputes but primarily focuses on dispute ID 2 - consider adding assertions for the other dispute IDs for more comprehensive coverage
  • The test assumes specific dispute IDs (0, 1, 2) which could be made more robust by using variables or dynamic lookups
  • Consider adding a test case for the boundary condition where coreDisputeIDToDisputeLength returns 0 for non-existent disputes

These are minor suggestions and don't affect the core functionality being tested.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 70e4b7c and 5ac93ef.

📒 Files selected for processing (2)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (6 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: web/src/hooks/queries/usePopulatedDisputeData.ts:58-61
Timestamp: 2024-10-14T13:58:25.708Z
Learning: In `web/src/hooks/queries/usePopulatedDisputeData.ts`, the query and subsequent logic only execute when `disputeData.dispute?.arbitrableChainId` and `disputeData.dispute?.externalDisputeId` are defined, so `initialContext` properties based on these values are safe to use without additional null checks.
Learnt from: tractorss
PR: kleros/kleros-v2#1982
File: web/src/pages/Resolver/Landing/index.tsx:62-62
Timestamp: 2025-05-15T06:50:40.859Z
Learning: In the Landing component, it's safe to pass `dispute?.dispute?.arbitrated.id as 0x${string}` to `usePopulatedDisputeData` without additional null checks because the hook internally handles undefined parameters through its `isEnabled` flag and won't execute the query unless all required data is available.
Learnt from: kemuru
PR: kleros/kleros-v2#1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-07T06:18:23.427Z
Learning: In the `kleros-v2` codebase, the property `totalResolvedDisputes` should remain and should not be renamed to `totalResolvedVotes`.
Learnt from: kemuru
PR: kleros/kleros-v2#1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-08T16:23:56.291Z
Learning: In the `kleros-v2` codebase, the property `totalResolvedDisputes` should remain and should not be renamed to `totalResolvedVotes`.
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: kleros-sdk/src/utils/getDispute.ts:38-40
Timestamp: 2024-10-21T10:32:16.970Z
Learning: The variables 'arbitrableChainID' and 'externalDisputeID' are required by the context to have uppercase 'ID', so they should remain unchanged even if the corresponding source properties use 'Id'.
Learnt from: kemuru
PR: kleros/kleros-v2#1774
File: web/src/components/CasesDisplay/index.tsx:61-61
Timestamp: 2024-12-06T13:04:50.495Z
Learning: In `web/src/components/CasesDisplay/index.tsx`, the variables `numberDisputes` and `numberClosedDisputes` can sometimes be `NaN`, and should default to `0` using logical OR (`||`) to prevent display issues in the `StatsAndFilters` component.
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (6)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: kleros-sdk/src/utils/getDispute.ts:38-40
Timestamp: 2024-10-21T10:32:16.970Z
Learning: The variables 'arbitrableChainID' and 'externalDisputeID' are required by the context to have uppercase 'ID', so they should remain unchanged even if the corresponding source properties use 'Id'.
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1703
File: web/src/hooks/queries/usePopulatedDisputeData.ts:58-61
Timestamp: 2024-10-14T13:58:25.708Z
Learning: In `web/src/hooks/queries/usePopulatedDisputeData.ts`, the query and subsequent logic only execute when `disputeData.dispute?.arbitrableChainId` and `disputeData.dispute?.externalDisputeId` are defined, so `initialContext` properties based on these values are safe to use without additional null checks.
Learnt from: kemuru
PR: kleros/kleros-v2#1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-07T06:18:23.427Z
Learning: In the `kleros-v2` codebase, the property `totalResolvedDisputes` should remain and should not be renamed to `totalResolvedVotes`.
Learnt from: kemuru
PR: kleros/kleros-v2#1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-08T16:23:56.291Z
Learning: In the `kleros-v2` codebase, the property `totalResolvedDisputes` should remain and should not be renamed to `totalResolvedVotes`.
Learnt from: tractorss
PR: kleros/kleros-v2#1982
File: web/src/pages/Resolver/Landing/index.tsx:62-62
Timestamp: 2025-05-15T06:50:40.859Z
Learning: In the Landing component, it's safe to pass `dispute?.dispute?.arbitrated.id as 0x${string}` to `usePopulatedDisputeData` without additional null checks because the hook internally handles undefined parameters through its `isEnabled` flag and won't execute the query unless all required data is available.
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1839
File: web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx:141-149
Timestamp: 2025-01-17T11:11:32.535Z
Learning: In the Kleros v2 codebase, using -1 as an initial value for choice tracking is preferred over undefined on the client-side to explicitly indicate that no option has been selected. This value is only used internally and never reaches the contract.
contracts/test/foundry/KlerosCore.t.sol (5)

undefined

<retrieved_learning>
Learnt from: kemuru
PR: #1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-08T16:23:56.291Z
Learning: In the kleros-v2 codebase, the property totalResolvedDisputes should remain and should not be renamed to totalResolvedVotes.
</retrieved_learning>

<retrieved_learning>
Learnt from: kemuru
PR: #1702
File: web/src/pages/Home/TopJurors/JurorCard/index.tsx:10-11
Timestamp: 2024-10-07T06:18:23.427Z
Learning: In the kleros-v2 codebase, the property totalResolvedDisputes should remain and should not be renamed to totalResolvedVotes.
</retrieved_learning>

<retrieved_learning>
Learnt from: Harman-singh-waraich
PR: #1703
File: web/src/hooks/queries/usePopulatedDisputeData.ts:58-61
Timestamp: 2024-10-14T13:58:25.708Z
Learning: In web/src/hooks/queries/usePopulatedDisputeData.ts, the query and subsequent logic only execute when disputeData.dispute?.arbitrableChainId and disputeData.dispute?.externalDisputeId are defined, so initialContext properties based on these values are safe to use without additional null checks.
</retrieved_learning>

<retrieved_learning>
Learnt from: tractorss
PR: #1982
File: web/src/pages/Resolver/Landing/index.tsx:62-62
Timestamp: 2025-05-15T06:50:40.859Z
Learning: In the Landing component, it's safe to pass dispute?.dispute?.arbitrated.id as 0x${string} to usePopulatedDisputeData without additional null checks because the hook internally handles undefined parameters through its isEnabled flag and won't execute the query unless all required data is available.
</retrieved_learning>

<retrieved_learning>
Learnt from: Harman-singh-waraich
PR: #1839
File: web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx:141-149
Timestamp: 2025-01-17T11:11:32.535Z
Learning: In the Kleros v2 codebase, using -1 as an initial value for choice tracking is preferred over undefined on the client-side to explicitly indicate that no option has been selected. This value is only used internally and never reaches the contract.
</retrieved_learning>

⏰ 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
  • 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
  • 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: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (4)

67-67: Well-designed mapping to track dispute ownership.

The new mapping effectively distinguishes between mapped and unmapped disputes by storing localDisputeID + 1, ensuring the value is never 0 for valid disputes.


209-209: Correct initialization of dispute length mapping.

Setting the mapping to localDisputeID + 1 ensures it's never 0 for valid disputes, allowing the require checks to properly distinguish between mapped and unmapped disputes.


333-333: Correct placement of dispute validation.

The require statement is properly placed and this function doesn't have the modifier order issue since the check happens early in the function body.


413-413: Proper validation for withdrawal function.

The require statement correctly ensures only disputes belonging to this dispute kit can have their fees withdrawn.

contracts/test/foundry/KlerosCore.t.sol (2)

1396-1396: LGTM: Assertion verifies dispute length mapping

The assertion correctly checks that the coreDisputeIDToDisputeLength mapping returns 1 for dispute ID 0, which aligns with the new functionality to track dispute lengths by core dispute ID.


1787-1787: LGTM: Assertion message correction

The assertion message correctly expects choice value "2" instead of "empty", which aligns with the test logic where the choice is set to 2 on line 1764.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 9, 2025
Copy link

netlify bot commented Jul 9, 2025

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

Name Link
🔨 Latest commit 85f01b6
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/6876bc0c017762000860956f

Copy link

@jaybuidl jaybuidl merged commit e99f3e6 into dev Jul 15, 2025
14 of 25 checks passed
@jaybuidl jaybuidl deleted the fix/dk-vote-bug branch July 15, 2025 20:43
@jaybuidl jaybuidl mentioned this pull request Jul 15, 2025
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.

2 participants