Skip to content

feat(DK): pass commit and appeal quicker #1955

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 3 commits into from
Apr 15, 2025
Merged

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Apr 14, 2025

PR-Codex overview

This PR focuses on enhancing the appeal process in the KlerosCoreBase contract by adding checks for appeal funding and modifying voting mechanisms in dispute kits.

Detailed summary

  • Added a check in KlerosCoreBase to ensure appeal funding is completed before moving to the execution period.
  • Introduced isAppealFunded function in IDisputeKit to verify if appeal funding is finished.
  • Updated areVotesAllCast in DisputeKitClassicBase to account for hidden votes.
  • Implemented appeal funding logic in isAppealFunded to check if the appeal period has ended.
  • Added tests in KlerosCoreTest for quick passing of periods during voting and appeal phases.

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

Summary by CodeRabbit

  • New Features

    • Enhanced the dispute resolution process by verifying both the timing and appeal funding conditions before transitioning between phases.
    • Refined vote counting to better handle different voting scenarios, ensuring smoother phase transitions.
    • Added a check to determine if appeal funding is finished, improving dispute funding status visibility.
  • Tests

    • Introduced new tests simulating rapid voting and appeal period transitions.
    • Updated existing tests to confirm proper phase changes and event emissions.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

This pull request enhances the arbitration contracts by tightening the appeal period conditions. In the KlerosCoreBase contract, the passPeriod function now checks both the elapsed time and the appeal funding status before allowing a period change. The DisputeKitClassicBase contract is updated to adjust the vote counting logic to account for hidden votes, and it introduces the isAppealFunded function to determine if appeal funding is finished prematurely. The IDisputeKit interface is expanded with this new function, and tests in KlerosCore.t.sol are added and updated to simulate quick period transitions and validate the new error conditions.

Changes

File(s) Change Summary
contracts/src/arbitration/KlerosCoreBase.sol Enhanced passPeriod to check both elapsed time and appeal funding status; reverts with AppealPeriodNotPassed if conditions fail.
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol Updated areVotesAllCast to handle hidden votes; added new isAppealFunded function to determine if appeal funding is finished prematurely.
contracts/src/arbitration/interfaces/IDisputeKit.sol Added isAppealFunded function to interface to expose appeal funding status.
contracts/test/foundry/KlerosCore.t.sol Added tests test_castVote_quickPassPeriod and test_appeal_quickPassPeriod for quick period transitions; updated test_castVote with a revert check for premature period passing.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant KlerosCore as KlerosCoreBase
    participant DisputeKit

    Caller->>KlerosCore: call passPeriod(disputeID)
    KlerosCore->>KlerosCore: check elapsed appeal period time
    KlerosCore->>DisputeKit: call isAppealFunded(disputeID)
    DisputeKit-->>KlerosCore: return appeal funding status (bool)
    alt Appeal period not passed and appeal not funded
        KlerosCore->>Caller: revert AppealPeriodNotPassed
    else Conditions met
        KlerosCore->>Caller: transition period and emit NewPeriod event
    end
Loading

Poem

Oh, I hop through lines of code so bright,
Checking periods by day and night,
With funding checks in every twist,
My rabbit eyes just cannot miss.
In tests and logic, I leap with glee –
Hooray for changes from CodeRabbit Inc.!
🐇💻


📜 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 61da2b8 and 5f8e25c.

📒 Files selected for processing (3)
  • contracts/src/arbitration/KlerosCoreBase.sol (1 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1 hunks)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol
  • contracts/src/arbitration/KlerosCoreBase.sol
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: contracts-testing

🪧 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 Apr 14, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 5f8e25c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/67fe9af6575dac0008bc7dc3
😎 Deploy Preview https://deploy-preview-1955--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 Apr 14, 2025

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

Name Link
🔨 Latest commit 5f8e25c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/67fe9af66428f9000850be2f

Copy link

netlify bot commented Apr 14, 2025

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

Name Link
🔨 Latest commit 5f8e25c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/67fe9af6402fab0008499015

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 (1)

534-546: Good implementation of appeal funding check logic.

The implementation of appealFundingIsFinished correctly:

  1. Retrieves the appeal period's start and end times
  2. Checks for funded choices
  3. Determines if funding is finished based on elapsed time and the absence of any funded choices

The time check uses LOSER_APPEAL_PERIOD_MULTIPLIER (5000 basis points = 50%) to allow for quicker transitions after half the appeal period has elapsed if no funding has occurred.

However, consider expanding this implementation to also handle the case where only one side has funded. Currently, it only returns true when no choices are funded at all, but there could be scenarios where only the winning side funded and it's clear the losing side won't fund.

function appealFundingIsFinished(uint256 _coreDisputeID) external view override returns (bool) {
    (uint256 appealPeriodStart, uint256 appealPeriodEnd) = core.appealPeriod(_coreDisputeID);

    uint256[] memory fundedChoices = getFundedChoices(_coreDisputeID);
-   return (fundedChoices.length == 0 &&
+   // If no choices are funded, check if loser's time window has passed
+   return ((fundedChoices.length == 0 &&
        block.timestamp - appealPeriodStart >=
-       ((appealPeriodEnd - appealPeriodStart) * LOSER_APPEAL_PERIOD_MULTIPLIER) / ONE_BASIS_POINT);
+       ((appealPeriodEnd - appealPeriodStart) * LOSER_APPEAL_PERIOD_MULTIPLIER) / ONE_BASIS_POINT)
+       // OR if only one choice is funded and loser's time window has passed
+       || (fundedChoices.length == 1 &&
+           block.timestamp - appealPeriodStart >=
+           ((appealPeriodEnd - appealPeriodStart) * LOSER_APPEAL_PERIOD_MULTIPLIER) / ONE_BASIS_POINT));
}
contracts/test/foundry/KlerosCore.t.sol (2)

1880-1936: Test for quick period transition when all committed votes are cast

This test verifies a new feature where the voting period can be passed to appeal phase when all committed votes are cast, even if not all jurors have voted. This aligns with the PR objective of passing periods quicker.

Consider adding an additional test for the edge case where some votes are committed but not cast, to ensure the period cannot be passed in that scenario.


2248-2280: Test for quick appeal period transition

This test validates that the appeal period can be passed to execution without waiting for the full duration, meeting the PR objective of accelerating period transitions.

Consider adding a test for the edge case where an appeal is funded on one side but not the other, to ensure the behavior is correct in that scenario as well.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 74142c1 and 481bd7d.

📒 Files selected for processing (4)
  • contracts/src/arbitration/KlerosCoreBase.sol (1 hunks)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1 hunks)
  • contracts/src/arbitration/interfaces/IDisputeKit.sol (1 hunks)
  • contracts/test/foundry/KlerosCore.t.sol (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-neo
  • 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: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: contracts-testing
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (5)
contracts/src/arbitration/interfaces/IDisputeKit.sol (1)

95-98: Good addition of the appealFundingIsFinished method to the interface.

This new method provides a clean way to check if appeal funding is completed prematurely. The documentation clearly explains its purpose and parameters.

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

578-581: Good enhancement to the appeal period check logic.

This modification to the passPeriod function now checks both time elapsed AND appeal funding status before preventing a period change. This allows for quicker transitions through the appeal period when funding won't be completed.

The logical operator changed from a simple time check to a more complex condition that enables skipping the remaining appeal period when appropriate.

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (2)

520-521: Good documentation clarification.

Adding this note helps clarify that the function is intended for direct use by the core contract rather than off-chain usage, which is important context for maintainers.


527-531: Good improvement to vote counting logic to handle hidden votes.

The function now correctly differentiates between hidden and non-hidden votes when determining if all votes have been cast. For hidden votes, it checks against totalCommitted, while for non-hidden votes, it uses votes.length.

This will lead to more accurate vote counting, especially in courts with different voting visibility settings.

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

1804-1805: Test ensures voting period can't be passed prematurely

Good addition to verify that the contract correctly prevents passing the period before all voting conditions are met.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 14, 2025
Copy link

netlify bot commented Apr 14, 2025

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

Name Link
🔨 Latest commit 5f8e25c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/67fe9af60006590008e0f4c1
😎 Deploy Preview https://deploy-preview-1955--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.

@jaybuidl jaybuidl added Type: Feature🗿 Package: Contracts Court smart contracts Compatibility: ABI change 🗯 Smart contract ABI is changing. labels Apr 14, 2025
Copy link

codeclimate bot commented Apr 15, 2025

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

View more on Code Climate.

Copy link

@jaybuidl jaybuidl merged commit d574ce8 into dev Apr 15, 2025
17 of 26 checks passed
@jaybuidl jaybuidl deleted the feat/dispute-period-quick-pass branch May 19, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compatibility: ABI change 🗯 Smart contract ABI is changing. Package: Contracts Court smart contracts Type: Feature🗿
Projects
None yet
2 participants