Skip to content
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

fix(KC): remove null dk #1893

Closed
wants to merge 2 commits into from
Closed

fix(KC): remove null dk #1893

wants to merge 2 commits into from

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Feb 13, 2025

PR-Codex overview

This PR focuses on modifying the handling of dispute kits in the Kleros arbitration system, particularly changing default values and references from 1 to 0, indicating a shift in the index of the classic dispute kit and related functionality.

Detailed summary

  • Changed disputeKitID default from 1 to 0 in multiple contracts.
  • Updated supportedDisputeKits in tests from [1] to [0].
  • Adjusted assertions in tests to reflect the new dispute kit index.
  • Modified the handling of NULL_DISPUTE_KIT to remove its usage.
  • Updated comments to reflect changes in dispute kit indexing.

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

Summary by CodeRabbit

  • Refactor
    • Streamlined dispute kit management and court initialization logic by removing redundant validations.
  • Chore
    • Standardized dispute kit indexing by updating default constants.
  • Tests
    • Aligned test configurations and event expectations with the revised dispute kit defaults to ensure consistent behavior.

These improvements enhance the consistency and reliability of the arbitration and court creation features without impacting the overall user experience.

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

This pull request adjusts the dispute kit identification across the contracts and tests. The changes update the supportedDisputeKits parameters (switching from [1] to [0]) in simulation tasks and test cases, while simplifying the internal logic in several contracts by removing checks for zero or null dispute kit indices. Constants have been updated accordingly, and test assertions now reflect the new indexing scheme. These modifications ensure consistency in court creation and dispute kit management across the codebase.

Changes

Files Change Summary
contracts/scripts/simulations/tasks.ts Changed supportedDisputeKits in simulate:create-court task from [1] to [0].
contracts/src/arbitration/{KlerosCoreBase.sol, KlerosCoreRuler.sol, KlerosCoreUniversity.sol} Removed redundant zero/null dispute kit checks and streamlined court creation logic in functions like createCourt and initialize.
contracts/src/libraries/Constants.sol Removed NULL_DISPUTE_KIT and updated DISPUTE_KIT_CLASSIC value from 1 to 0.
contracts/test/arbitration/{draw.ts, index.ts, staking-neo.ts, staking.ts} Updated createCourt parameters and expected event values, changing dispute kit identifiers from [1] to [0].
contracts/test/foundry/KlerosCore.t.sol Modified import path and adjusted dispute kit counts and indices in test assertions and events.

Sequence Diagram(s)

sequenceDiagram
    participant Task as Simulation Task
    participant Core as KlerosCore Contract
    participant Validator as Dispute Kit Validator
    Task->>Core: createCourt(..., [0])
    Core->>Validator: Validate dispute kit (index 0)
    Validator-->>Core: Return validated kit
    Core-->>Task: Court created with dispute kit 0
Loading

Possibly related issues

  • Follow-up: Remove NULL_DISPUTE_KIT references #1814: The changes in the main issue regarding the removal of the NULL_DISPUTE_KIT constant and its implications for dispute kit handling are related to the retrieved issue, which discusses the need to remove references to NULL_DISPUTE_KIT in critical business logic.

Possibly related PRs

Suggested labels

Type: Bug :bug:

Suggested reviewers

  • alcercu

Poem

I'm a hopping rabbit with a tale to tell,
Codes and kits now dance so well.
From [1] to [0], the numbers align,
Simplified checks make the contracts shine.
Bugs scurry away like carrots in flight,
CodeRabbit cheers with a joyful delight!
🥕🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between a14f146 and e7f0d52.

📒 Files selected for processing (11)
  • contracts/scripts/simulations/tasks.ts (1 hunks)
  • contracts/src/arbitration/KlerosCoreBase.sol (3 hunks)
  • contracts/src/arbitration/SortitionModuleBase.sol (1 hunks)
  • contracts/src/arbitration/devtools/KlerosCoreRuler.sol (0 hunks)
  • contracts/src/arbitration/university/KlerosCoreUniversity.sol (3 hunks)
  • contracts/src/libraries/Constants.sol (1 hunks)
  • contracts/test/arbitration/draw.ts (1 hunks)
  • contracts/test/arbitration/index.ts (2 hunks)
  • contracts/test/arbitration/staking-neo.ts (2 hunks)
  • contracts/test/arbitration/staking.ts (2 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (10 hunks)
💤 Files with no reviewable changes (1)
  • contracts/src/arbitration/devtools/KlerosCoreRuler.sol
🚧 Files skipped from review as they are similar to previous changes (8)
  • contracts/test/arbitration/draw.ts
  • contracts/test/arbitration/index.ts
  • contracts/src/libraries/Constants.sol
  • contracts/src/arbitration/KlerosCoreBase.sol
  • contracts/scripts/simulations/tasks.ts
  • contracts/test/arbitration/staking.ts
  • contracts/src/arbitration/SortitionModuleBase.sol
  • contracts/test/arbitration/staking-neo.ts
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing
🔇 Additional comments (14)
contracts/src/arbitration/university/KlerosCoreUniversity.sol (3)

341-341: This change aligns with the PR objective to remove null dispute kit.

The check for _supportedDisputeKits[i] == 0 has been removed, allowing the dispute kit at index 0 to be used. This change is consistent with the updated approach of making index 0 a valid dispute kit ID rather than treating it as a NULL_DISPUTE_KIT.


415-416: Consistent update for dispute kit validation.

Similar to the previous change, this removes the special case check for index 0, enabling it to be a valid dispute kit ID. This maintains consistency with the broader changes being made to the dispute kit handling.


1118-1120: Good fallback to DISPUTE_KIT_CLASSIC when ID is invalid.

This change removes the check for disputeKitID == 0 and only verifies if the ID is out of bounds. If an invalid ID is provided, it now defaults to DISPUTE_KIT_CLASSIC (which is at index 0 after these changes). This simplifies the logic while maintaining safety.

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

20-20: Code path update for KlerosCoreSnapshotProxy import

The import path for KlerosCoreSnapshotProxy has been updated from the snapshot-proxy directory to the arbitration/view directory. This reflects a reorganization of the codebase structure.


159-159: Verified dispute kit array length adjustment

The test now expects just 1 dispute kit after initialization instead of 2, which is consistent with the removal of the null dispute kit (index 0) as described in the PR objectives.


438-441: Dispute kit indexing update properly reflected

The emission of the DisputeKitCreated event and subsequent array length checks have been updated to use index 1 for the new dispute kit (rather than 2), with a total array length of 2 (rather than 3). This correctly aligns with the new indexing scheme after removal of the null dispute kit.


449-449: Support array index updated for new dispute kit

The supported dispute kit array correctly uses index 1 after the removal of the null dispute kit, maintaining test consistency.


528-528: Test case properly updated for dispute kit ID

The bad supported dispute kit array correctly uses ID 1 for the sybil resistant dispute kit, maintaining consistency with the new indexing after removal of the null dispute kit.


547-547: Event emission updated for new dispute kit ID

The DisputeKitEnabled event emission correctly uses the new dispute kit ID of 1, consistent with the removal of the null dispute kit.


706-707: Dispute kit ID constant correctly used

The variable newDkID is properly set to 1, consistent with the new indexing scheme used throughout the tests.


801-806: Extra data encoding and validation updated

The extraDataToCourtIDMinJurorsDisputeKit test properly encodes dispute kit ID 5 and validates it, maintaining consistency with the updated indexing system.


1296-1296: Dispute kit ID correctly set for specialized tests

The test for creating disputes with Ethereum uses dispute kit ID 1 consistently with the new indexing scheme.


2062-2062: Court switching test updated with correct dispute kit ID

The test for dispute kit court switching correctly uses dispute kit ID 1, maintaining consistency with the removal of the null dispute kit.


718-718: Boundary test case properly updated

The out-of-bounds test now correctly uses index 2 as the invalid value after removing the null dispute kit, ensuring that edge cases are properly tested.


🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

netlify bot commented Feb 13, 2025

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

Name Link
🔨 Latest commit e7f0d52
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67d9b264be5bb600082caf8f
😎 Deploy Preview https://deploy-preview-1893--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 site configuration.

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit e7f0d52
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67d9b2645d92740008613381
😎 Deploy Preview https://deploy-preview-1893--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 site configuration.

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit e7f0d52
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67d9b26455622e00085021ad
😎 Deploy Preview https://deploy-preview-1893--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 site 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: 1

🧹 Nitpick comments (1)
contracts/test/foundry/KlerosCore.t.sol (1)

1-2713: Consider adding tests for additional edge cases.

While the test coverage is comprehensive, consider adding tests for:

  1. Concurrent dispute resolution in multiple courts
  2. Mass juror unstaking scenarios
  3. Complex appeal funding patterns with multiple funders
  4. Edge cases around delayed stake execution
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 489ad78 and 43dd2bf.

📒 Files selected for processing (10)
  • contracts/scripts/simulations/tasks.ts (1 hunks)
  • contracts/src/arbitration/KlerosCoreBase.sol (3 hunks)
  • contracts/src/arbitration/devtools/KlerosCoreRuler.sol (0 hunks)
  • contracts/src/arbitration/university/KlerosCoreUniversity.sol (3 hunks)
  • contracts/src/libraries/Constants.sol (1 hunks)
  • contracts/test/arbitration/draw.ts (1 hunks)
  • contracts/test/arbitration/index.ts (2 hunks)
  • contracts/test/arbitration/staking-neo.ts (2 hunks)
  • contracts/test/arbitration/staking.ts (2 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (10 hunks)
💤 Files with no reviewable changes (1)
  • contracts/src/arbitration/devtools/KlerosCoreRuler.sol
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • 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: Redirect rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: contracts-testing
  • GitHub Check: SonarCloud
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (14)
contracts/src/libraries/Constants.sol (1)

12-12: LGTM! Simplified dispute kit indexing.

The change from 1 to 0 for DISPUTE_KIT_CLASSIC and removal of NULL_DISPUTE_KIT simplifies the indexing scheme by eliminating the concept of a null dispute kit.

contracts/test/arbitration/index.ts (1)

19-19: LGTM! Test expectations updated for new dispute kit indexing.

Test assertions have been correctly updated to match the new dispute kit indexing scheme where DISPUTE_KIT_CLASSIC is now 0.

Also applies to: 33-33, 38-38

contracts/test/arbitration/draw.ts (1)

100-100: LGTM! Test setup updated for new dispute kit indexing.

The createCourt call has been correctly updated to use the new dispute kit index.

contracts/test/arbitration/staking.ts (1)

43-43: LGTM! Test setups updated for new dispute kit indexing.

Both createCourt calls have been correctly updated to use the new dispute kit index.

Also applies to: 389-389

contracts/scripts/simulations/tasks.ts (1)

88-88: LGTM!

The update to supportedDisputeKits array aligns with the broader refactoring to remove null dispute kit checks.

contracts/test/arbitration/staking-neo.ts (1)

402-402: LGTM!

The updates to createCourt calls maintain test coverage for the refactored dispute kit functionality.

Also applies to: 737-737

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

346-347: LGTM!

The removal of the zero index check simplifies the dispute kit validation logic while maintaining the core validation that the index is within bounds.


1126-1128: LGTM!

The simplified logic for handling invalid dispute kit IDs maintains the fallback to classic dispute kit while improving code clarity.

contracts/src/arbitration/university/KlerosCoreUniversity.sol (4)

217-219: LGTM! Simplified dispute kit initialization.

The initialization has been streamlined by directly adding the classic dispute kit without a NULL_DISPUTE_KIT placeholder, which aligns with the PR objective.


340-345: LGTM! Simplified dispute kit validation.

The validation has been simplified while maintaining security by:

  1. Preventing out-of-bounds access to dispute kits
  2. Ensuring classic dispute kit support (line 347)

414-418: LGTM! Consistent dispute kit validation.

The validation logic is consistent with createCourt changes and maintains security by:

  1. Preventing out-of-bounds access
  2. Preserving the requirement for classic dispute kit support

1118-1120: LGTM! Consistent extradata validation.

The validation logic is consistent with other changes and maintains safety by defaulting to DISPUTE_KIT_CLASSIC for invalid indices.

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

19-20: LGTM! Import path update reflects better organization.

The import path change from ../../src/snapshot-proxy/KlerosCoreSnapshotProxy.sol to ../../src/arbitration/view/KlerosCoreSnapshotProxy.sol reflects a better organization of the codebase, placing view-related contracts in a dedicated directory.


60-151: LGTM! Comprehensive test setup.

The setUp function provides thorough initialization of all required contracts and test variables, including:

  • Core contracts (KlerosCore, SortitionModule, DisputeKit)
  • Supporting contracts (RNG, PNK, TestERC20)
  • Test accounts with appropriate balances
  • Configuration parameters

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit e7f0d52
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67d9b264be1d4a0008419264
😎 Deploy Preview https://deploy-preview-1893--kleros-v2-university.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 site configuration.

@jaybuidl jaybuidl force-pushed the fix/dk-null-remove branch from a14f146 to e7f0d52 Compare March 18, 2025 17:50
Copy link

codeclimate bot commented Mar 18, 2025

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

View more on Code Climate.

@jaybuidl
Copy link
Member

Putting this PR on hold because it would break the current production deployment after upgrade. It would require some dispute migration logic in the initializer and a fair amount of testing/simulation.

In addition the subgraph refers to the dispute kit classic index at 1 in a number of places.

Overall it's a high risk/low value change.

@jaybuidl jaybuidl closed this Mar 18, 2025
@jaybuidl jaybuidl linked an issue Mar 18, 2025 that may be closed by this pull request
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.

Follow-up: Remove NULL_DISPUTE_KIT references
2 participants