Skip to content

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Sep 24, 2025

PR-Codex overview

This PR introduces a new error handling mechanism in the DisputeKitClassicBase contract to prevent users from committing votes multiple times. It also adds a test case to ensure that the proper error is thrown when a user attempts to commit a vote they have already committed.

Detailed summary

  • Added a check in the castCommit function to revert with AlreadyCommittedThisVote if a vote has already been committed.
  • Updated the test in KlerosCore_Voting.t.sol to verify that committing an already committed vote triggers the expected revert.

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

Summary by CodeRabbit

  • Bug Fixes

    • Prevents duplicate vote commit submissions by rejecting re-commits on already committed votes.
    • Provides a clear error when attempting to commit a vote more than once, improving user feedback and reliability.
  • Tests

    • Added test coverage to verify that duplicate commit attempts are correctly rejected.

Copy link

netlify bot commented Sep 24, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 6b74ebc
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68d4464981ca0a0008386d2c
😎 Deploy Preview https://deploy-preview-2145--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

netlify bot commented Sep 24, 2025

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

Name Link
🔨 Latest commit 6b74ebc
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68d446499b7244000850cab4

Copy link

netlify bot commented Sep 24, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 6b74ebc
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68d4464981e00600097234f1
😎 Deploy Preview https://deploy-preview-2145--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 project configuration.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Walkthrough

Adds a revert guard in DisputeKitClassicBase.castCommit to prevent re-committing already committed votes and declares a new error AlreadyCommittedThisVote(). Updates a Foundry test to assert the revert on double-commit attempts.

Changes

Cohort / File(s) Summary
DisputeKit commit guard
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol
Adds error AlreadyCommittedThisVote() and updates castCommit to revert if a vote’s commit is already set before ownership/assignment checks.
Voting test update
contracts/test/foundry/KlerosCore_Voting.t.sol
Extends test_castCommit to prank as staker and assert revert with DisputeKitClassicBase.AlreadyCommittedThisVote.selector on re-submitting the same commit for the same vote IDs.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Juror
  participant DisputeKit as DisputeKitClassicBase
  participant Storage as Vote Storage

  rect rgb(235, 245, 255)
  note over Juror,DisputeKit: Initial commit
  Juror->>DisputeKit: castCommit(voteIDs[], commit)
  DisputeKit->>Storage: Read votes
  DisputeKit->>Storage: Store commit for each vote
  DisputeKit-->>Juror: Success
  end

  rect rgb(255, 240, 240)
  note over Juror,DisputeKit: Re-commit attempt (changed flow)
  Juror->>DisputeKit: castCommit(same voteIDs[], same commit)
  DisputeKit->>Storage: Read vote.commit
  alt vote.commit != 0
    DisputeKit-->>Juror: revert AlreadyCommittedThisVote()
  else
    DisputeKit->>Storage: Store commit
    DisputeKit-->>Juror: Success
  end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny taps the gavel—thump, thump, neat—
“One commit per carrot!” no repeat.
Tests now squeak, “Revert on try two!”
The ledger nods, “That’ll do.”
With hops of joy and tidy kit,
The votes commit—just once—well writ. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely indicates a fix in the Dispute Kit related to multiple vote commits, aligning with the added guard against double commits while following conventional commit style.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/dk-multiple-commits

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1)

253-257: Update NatSpec to reflect new single-commit semantics

Doc says commits can be overridden, but code now reverts on re-commit. Align the comment with behavior.

Apply:

-    /// @dev It can be called multiple times during the commit period, each call overrides the commits of the previous one.
+    /// @dev Each vote can be committed at most once per round. Attempts to re-commit an already committed vote revert with AlreadyCommittedThisVote().
🧹 Nitpick comments (1)
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1)

277-281: Keep revert semantics predictable and save an sload per iteration

Check ownership before the “already committed” guard to avoid revealing commit status to non-owners and use a local Vote storage reference.

Apply:

-        for (uint256 i = 0; i < _voteIDs.length; i++) {
-            if (round.votes[_voteIDs[i]].commit != bytes32(0)) revert AlreadyCommittedThisVote();
-            if (round.votes[_voteIDs[i]].account != msg.sender) revert JurorHasToOwnTheVote();
-            round.votes[_voteIDs[i]].commit = _commit;
-        }
+        for (uint256 i = 0; i < _voteIDs.length; i++) {
+            Vote storage v = round.votes[_voteIDs[i]];
+            if (v.account != msg.sender) revert JurorHasToOwnTheVote();
+            if (v.commit != bytes32(0)) revert AlreadyCommittedThisVote();
+            v.commit = _commit;
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e827f63 and 6b74ebc.

📒 Files selected for processing (2)
  • contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (2 hunks)
  • contracts/test/foundry/KlerosCore_Voting.t.sol (1 hunks)
⏰ 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). (14)
  • 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-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-testnet-devtools
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Analyze (javascript)
  • GitHub Check: hardhat-tests
  • GitHub Check: Pages changed - kleros-v2-testnet-devtools
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
🔇 Additional comments (2)
contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol (1)

763-764: LGTM: new error improves clarity

Error declaration is appropriate and non-breaking for storage.

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

100-103: LGTM: asserts double-commit reverts as intended

Test correctly guards against re-commit attempts.

Consider adding one more check to ensure atomicity on mixed arrays (one already committed, one fresh) reverts and does not partially commit the fresh vote ID.

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