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

feat(DisputeKit): add flushing feature #1653

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Jul 17, 2024

PR-Codex overview

The focus of this PR is to enhance the arbitration system by allowing unstaking of ineligible jurors and adding functionality to set stakes for dispute kits.

Detailed summary

  • Introduces setStakeBySortitionModuleOrDK to handle stakes for dispute kits.
  • Adds flush function to unstake ineligible jurors in DisputeKitSybilResistant.
  • Maps dispute kit addresses to indices in KlerosCoreBase.
  • Updates stake setting functions to include dispute kit checks.

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

Summary by CodeRabbit

  • New Features

    • Introduced a new flush function in the DisputeKitSybilResistant contract to automatically un-stake jurors who are ineligible for drawing.
  • Enhancements

    • Implemented a disputeKitIDs mapping in KlerosCoreBase to improve management and access of dispute kits.
    • Renamed the method for setting stakes to reflect its expanded functionality, now accommodating both sortition modules and dispute kits.

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The updates enhance the management of dispute kits within the Kleros arbitration framework by introducing a disputeKitIDs mapping in the KlerosCoreBase contract. Additionally, the DisputeKitSybilResistant contract now features a flush function to efficiently unstake ineligible jurors. These improvements aim to streamline the jury selection process, ensuring that only qualified jurors participate, thus optimizing the overall arbitration system.

Changes

File Path Change Summary
contracts/src/arbitration/KlerosCoreBase.sol Added mapping(IDisputeKit => uint256) public disputeKitIDs for enhanced dispute kit management. Renamed setStakeBySortitionModule to setStakeBySortitionModuleOrDK and updated error handling.
contracts/src/arbitration/SortitionModuleBase.sol Replaced instances of setStakeBySortitionModule with setStakeBySortitionModuleOrDK to reflect updated authorization.
contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol Introduced a flush function to unstake ineligible jurors, improving jury selection efficiency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DisputeKitSybilResistant
    participant KlerosCoreBase

    User ->> DisputeKitSybilResistant: flush(_juror, _courts)
    DisputeKitSybilResistant ->> KlerosCoreBase: check eligibility
    KlerosCoreBase -->> DisputeKitSybilResistant: eligibility status
    DisputeKitSybilResistant ->> KlerosCoreBase: unstake(_juror) if ineligible
Loading

Possibly related issues

Poem

In codes we weave, in bytes we trust,
To keep the jurors fair and just.
Dispute kits now with IDs clear,
And jurors unstaked, we hold dear.
A Sybil's touch, we now resist,
Efficiency in our midst.
With every line, our justice grows,
In blockchain's realm, the fairness shows.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 Jul 17, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 748c9b0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/66a9fb55e8e2450008b3a8e8
😎 Deploy Preview https://deploy-preview-1653--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 Jul 17, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 748c9b0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/66a9fb559fedff000866d709
😎 Deploy Preview https://deploy-preview-1653--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

netlify bot commented Jul 17, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 748c9b0
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/66a9fb55a7dac50008c1b41b
😎 Deploy Preview https://deploy-preview-1653--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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a1dff3b and 9fb2cf1.

Files selected for processing (2)
  • contracts/src/arbitration/KlerosCoreBase.sol (4 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol (1 hunks)
Additional comments not posted (2)
contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol (1)

468-481: Security and Logic Review for the flush Function

  1. Security Check on Proof of Humanity: The function first checks if the juror is eligible by calling _proofOfHumanity. If the juror is eligible, the function exits without taking any action, which is a good security practice to prevent unnecessary or harmful state changes.

  2. Loop Over Courts: The function iterates over an array of court IDs. For each court, it checks if the Dispute Kit is supported using core.isSupported. This is crucial to ensure that the operation is only performed in relevant contexts.

  3. Setting Stake to Zero: If the checks pass, core.setStakeBySortitionModule is called to set the juror's stake to zero for the given court. This effectively unstakes the juror, which is the intended functionality of this function.

  4. Potential Gas Optimization: Consider limiting the length of the _courts array to prevent excessive gas costs due to a large number of iterations.

  5. Error Handling: Proper error messages are provided in the require statements, which is good for debugging and user feedback.

Overall, the function appears secure and logically sound, but consider adding a limit to the _courts array size to manage potential gas issues.

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

104-104: Review of New Mapping and Related Changes in KlerosCoreBase.sol

  1. Mapping Declaration: The new mapping disputeKitIDs is declared to map IDisputeKit to uint256. This is a foundational change that supports the management of multiple dispute kits.

  2. Initialization of Mapping: The mapping is initialized in the _initialize function with the classic dispute kit. This is a critical setup step ensuring that the system starts with a known state.

  3. Addition of New Dispute Kits: The function addNewDisputeKit adds new entries to the disputeKitIDs mapping. This function is crucial for the system's extensibility, allowing new dispute kits to be registered and managed.

  4. Security and Best Practices: The changes include appropriate checks and error handling. The use of the onlyByGovernor modifier ensures that only authorized users can make changes, which is important for maintaining the integrity of the system.

Overall, the changes are well-implemented and follow best practices for contract development in Solidity.

Also applies to: 220-220, 321-321

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 17, 2024
@jaybuidl jaybuidl linked an issue Jul 24, 2024 that may be closed by this pull request
Copy link

sonarcloud bot commented Jul 31, 2024

Copy link

codeclimate bot commented Jul 31, 2024

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

View more on Code Climate.

@unknownunknown1 unknownunknown1 marked this pull request as ready for review July 31, 2024 08:54
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

Outside diff range, codebase verification and nitpick comments (1)
contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol (1)

468-480: LGTM! Consider adding comments for clarity.

The flush function is well-implemented and ensures that only ineligible jurors are unstaked from supported courts.

For better readability, consider adding comments to explain the purpose of each major step in the function.

+    // Check if the juror is eligible
    require(!_proofOfHumanity(_juror), "The juror is eligible");
    uint256 disputeKitID = core.disputeKitIDs(this);
+    // Iterate over the provided courts
    for (uint256 i = 0; i < _courts.length; i++) {
        uint96 courtID = _courts[i];
+        // Ensure the court supports this dispute kit
        require(core.isSupported(courtID, disputeKitID), "DK not supported by court");
        core.setStakeBySortitionModuleOrDK(_juror, courtID, 0, false);
    }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fb2cf1 and 748c9b0.

Files selected for processing (3)
  • contracts/src/arbitration/KlerosCoreBase.sol (5 hunks)
  • contracts/src/arbitration/SortitionModuleBase.sol (2 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol (1 hunks)
Additional comments not posted (5)
contracts/src/arbitration/SortitionModuleBase.sol (2)

Line range hint 209-213:
LGTM! Verify the new method.

The change from setStakeBySortitionModule to setStakeBySortitionModuleOrDK is approved.

Ensure the new method setStakeBySortitionModuleOrDK is correctly implemented and handles all necessary logic.

Verification successful

The new method setStakeBySortitionModuleOrDK is correctly implemented.

The function verifies the caller and then delegates the stake setting to _setStake, ensuring the necessary logic is handled.

  • contracts/src/arbitration/KlerosCoreBase.sol
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `setStakeBySortitionModuleOrDK`.

# Test: Search for the function implementation. Expect: Correct implementation handling all necessary logic.
rg --type solidity 'function setStakeBySortitionModuleOrDK'

Length of output: 94


Script:

#!/bin/bash
# Description: Verify the implementation of `setStakeBySortitionModuleOrDK`.

# Test: Search for the function implementation. Expect: Correct implementation handling all necessary logic.
rg 'function setStakeBySortitionModuleOrDK'

Length of output: 134


Script:

#!/bin/bash
# Description: Extract the implementation of `setStakeBySortitionModuleOrDK` from `contracts/src/arbitration/KlerosCoreBase.sol`.

# Extract the function definition and its body.
rg -A 20 'function setStakeBySortitionModuleOrDK' contracts/src/arbitration/KlerosCoreBase.sol

Length of output: 882


436-438: LGTM! Verify the new method.

The change from setStakeBySortitionModule to setStakeBySortitionModuleOrDK is approved.

Ensure the new method setStakeBySortitionModuleOrDK is correctly implemented and handles all necessary logic.

Verification successful

LGTM! Verify the new method.

The change from setStakeBySortitionModule to setStakeBySortitionModuleOrDK is approved. The new method setStakeBySortitionModuleOrDK is correctly implemented and handles all necessary logic.

  • Verified in contracts/src/arbitration/KlerosCoreBase.sol
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `setStakeBySortitionModuleOrDK`.

# Test: Search for the function implementation. Expect: Correct implementation handling all necessary logic.
rg --type solidity 'function setStakeBySortitionModuleOrDK'

Length of output: 94


Script:

#!/bin/bash
# Description: Verify the implementation of `setStakeBySortitionModuleOrDK`.

# Test: Search for the function implementation using ast-grep. Expect: Correct implementation handling all necessary logic.
ast-grep --lang solidity --pattern 'function setStakeBySortitionModuleOrDK($_, $_, $_, $_) { $$$ }'

Length of output: 218


Script:

#!/bin/bash
# Description: Verify the implementation of `setStakeBySortitionModuleOrDK`.

# Test: Search for the function implementation using grep. Expect: Correct implementation handling all necessary logic.
grep -r 'function setStakeBySortitionModuleOrDK' .

Length of output: 143


Script:

#!/bin/bash
# Description: Extract the full implementation of `setStakeBySortitionModuleOrDK`.

# Test: Print the implementation of the function from the file.
awk '/function setStakeBySortitionModuleOrDK/,/}/' ./contracts/src/arbitration/KlerosCoreBase.sol

Length of output: 509

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

1151-1151: LGTM!

The updated error name accurately describes the condition being checked.


321-323: LGTM! Verify the correct usage of the disputeKitIDs mapping.

The addition of the disputeKitIDs mapping enhances the functionality by mapping dispute kit addresses to their respective indices.

Ensure that there are no potential issues with duplicate entries or incorrect updates to the mapping.


474-486: LGTM! Verify the correct usage of the setStakeBySortitionModuleOrDK function.

The updated function name and logic are appropriate for the expanded functionality.

Ensure that all calls to this function are correctly updated and that the condition works as expected.

Verification successful

LGTM! The usage of the setStakeBySortitionModuleOrDK function is correct and consistent across the codebase.

The function is being called with appropriate parameters in various contexts, ensuring the expanded functionality is utilized as intended.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of the `setStakeBySortitionModuleOrDK` function.

# Test: Search for the usage of `setStakeBySortitionModuleOrDK`. Expect: Correct and consistent usage.
rg --type solidity -A 5 $'setStakeBySortitionModuleOrDK'

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the correct usage of the `setStakeBySortitionModuleOrDK` function.

# Locate all Solidity files and search for the usage of `setStakeBySortitionModuleOrDK`.
fd -e sol -x rg 'setStakeBySortitionModuleOrDK' {}

Length of output: 308


Script:

#!/bin/bash
# Description: Verify the correct usage of the `setStakeBySortitionModuleOrDK` function.

# Locate all Solidity files and search for the usage of `setStakeBySortitionModuleOrDK` with additional context.
fd -e sol -x rg -A 10 -B 10 'setStakeBySortitionModuleOrDK' {}

Length of output: 4505

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.

Allow Dispute Kits to unstake ineligible jurors
1 participant