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

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

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Jul 9, 2025

PR-Codex overview

This PR introduces a new mapping in the DisputeKitClassicBase contract to track the length of disputes associated with core dispute IDs. It enhances dispute handling by ensuring that local disputes are correctly linked to core disputes, adding necessary checks and updating related functions.

Detailed summary

  • Added coreDisputeIDToDisputeLength mapping to track dispute lengths.
  • Updated the DisputeKitClassicBase contract to set dispute lengths after local disputes are created.
  • Added checks to ensure local disputes exist before proceeding in various functions.
  • Enhanced tests in KlerosCoreTest to verify the new dispute length functionality.

✨ 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 non-existent disputes by adding explicit checks for valid dispute IDs.
    • 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 5ac93ef
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/686e164b7254ae0008b6e700
😎 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 5ac93ef
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/686e164b536f4d00089afe9d

Copy link

netlify bot commented Jul 9, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 5ac93ef
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/686e164bb77c85000879f887
😎 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 introduced in the dispute kit contract to record the length of the disputes array when a core dispute ID is mapped, ensuring accurate validation of dispute existence. Several functions now require this mapping to be set before proceeding. The test suite was expanded to verify these behaviors across multiple dispute kits.

Changes

File(s) Change Summary
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol Added coreDisputeIDToDisputeLength mapping; updated functions to require mapping is set before access.
contracts/test/foundry/KlerosCore.t.sol Added comprehensive test for dispute creation and voting across multiple dispute kits; minor assertions.

Suggested labels

Type: Bug :bug:, Package: Contracts

Suggested reviewers

  • jaybuidl
  • kemuru

Poem

In the warren of disputes, a mapping appears,
Guarding the burrows from accidental careers.
Each kit knows its own, with lengths set just right,
While tests hop through phases, both day and night.
No more lost bunnies in the zero-th warren—
The code is secure, and justice is sworn in! 🐇🛡️


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

sonarqubecloud bot commented Jul 9, 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 (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.

Copy link

netlify bot commented Jul 9, 2025

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

Name Link
🔨 Latest commit 5ac93ef
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/686e164b3b66b40008808a59

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.

1 participant