Skip to content

Conversation

unknownunknown1
Copy link
Contributor

@unknownunknown1 unknownunknown1 commented Sep 23, 2025

PR-Codex overview

This PR introduces enhancements to the ArbitrableExample contract by adding functionality to manage the number of ruling options in disputes and includes tests for various scenarios related to disputes, voting, and stakes in the Kleros arbitration system.

Detailed summary

  • Added numberOfRulingOptions variable to ArbitrableExample.
  • Implemented changeNumberOfRulingOptions function to update ruling options.
  • Removed local numberOfRulingOptions declarations in createDispute functions.
  • Introduced fuzz tests for creating disputes, casting votes, and executing rulings.
  • Enhanced existing tests to verify functionalities related to disputes and appeals.

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

Summary by CodeRabbit

  • New Features

    • Ruling options are now configurable at runtime (default remains 2). Dispute creation and appeal flows consistently use the configured value. Governance can update the number of ruling options.
  • Tests

    • Extensive fuzz tests added across appeals, disputes, drawing, execution, staking, and voting to validate variable ruling options, funding, iterations, and stake scenarios.
    • Improved assertion messages and coverage for end-to-end flows, balances, and juror state transitions.

Copy link

netlify bot commented Sep 23, 2025

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 6752cad
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-neo/deploys/68d2e0f65519900008cd5900
😎 Deploy Preview https://deploy-preview-2144--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

netlify bot commented Sep 23, 2025

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 6752cad
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet/deploys/68d2e0f6eae3a40007cc4d35
😎 Deploy Preview https://deploy-preview-2144--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 23, 2025

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

Name Link
🔨 Latest commit 6752cad
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68d2e0f675f2c700080c1ed4

Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Introduces a configurable numberOfRulingOptions state in ArbitrableExample with a governance setter, replacing hard-coded values in dispute creation. Adds multiple fuzz tests across appeals, disputes, drawing, execution, staking, and voting to exercise variable ruling options, amounts, iterations, and balances. Minor assertion text tweak. Possible duplicate tests in execution.

Changes

Cohort / File(s) Summary
Arbitrable config
contracts/src/arbitration/arbitrables/ArbitrableExample.sol
Adds uint256 public numberOfRulingOptions = 2; replaces literals with state usage; introduces changeNumberOfRulingOptions(uint256) restricted to owner.
Appeals fuzzing
contracts/test/foundry/KlerosCore_Appeals.t.sol
Adds fuzz tests for appeals: variable ruling options/choices and variable appeal funding amounts; covers dispute creation, voting, funding, assertions.
Disputes fuzzing
contracts/test/foundry/KlerosCore_Disputes.t.sol
Adds fuzz test for dispute creation with variable msg.value; updates one assertion message string; progresses through full lifecycle with parameterized fees/votes.
Drawing fuzzing
contracts/test/foundry/KlerosCore_Drawing.t.sol
Adds two fuzz tests for draw iterations and juror counts; asserts drawIterations, nbVotes, locked/staked balances, and disputesWithoutJurors.
Execution fuzzing
contracts/test/foundry/KlerosCore_Execution.t.sol
Adds two fuzz tests for execution repartitions vs iterations and juror counts; verifies balances post-execution; duplicate copies of the added tests appear in file.
Staking fuzzing
contracts/test/foundry/KlerosCore_Staking.t.sol
Imports console; adds fuzz tests for staking sequences, cross-court staking, and delayed stakes; adjusts time warps (minStakingTime → maxDrawingTime in places).
Voting fuzzing and imports
contracts/test/foundry/KlerosCore_Voting.t.sol
Extends import to include IArbitratorV2 and IArbitrableV2; adds fuzz test for casting votes with variable ruling options and choices; end-to-end ruling path.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Owner
  actor User
  participant Arbitrable as ArbitrableExample
  participant Core as KlerosCore (Arbitrator)
  participant Jurors

  Owner->>Arbitrable: changeNumberOfRulingOptions(n)
  note right of Arbitrable: Stores n in numberOfRulingOptions

  User->>Arbitrable: createDispute(...)
  Arbitrable->>Core: createDispute(numberOfRulingOptions)
  Core-->>Arbitrable: disputeID

  Core->>Jurors: Draw and notify
  Jurors->>Core: Cast votes (1..n)
  User->>Core: (optional) Fund appeal(s)
  Core->>Jurors: Appeal rounds (as needed)
  Core-->>Arbitrable: Ruling (1..n)
  Arbitrable-->>User: Enforce ruling
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

Type: Feature🗿, Compatibility: ABI change 🗯, Package: Contracts

Suggested reviewers

  • jaybuidl
  • kemuru

Poem

A hare taps keys with gentle hops,
Swaps hard-coded twos for toggled props.
Jurors draw, appeals unfurl,
Stakes and votes in fuzzy whirl.
With n options set by paw,
The warren codifies the law. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly captures the main purpose of the changes—introducing fuzzing tests—using a concise “feat:” prefix without listing specific files or details, making the primary enhancement immediately apparent.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/fuzzing-test

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

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

150-193: Bound fuzzed value instead of assuming; reduces discarded runs and flakiness.

Use bound to keep runs in-range deterministically.

Apply this diff:

-        // Cap it to 10 eth, so the number of jurors is not astronomical.
-        vm.assume(disputeValue >= arbitrationCost && disputeValue <= 10 ether);
-        vm.deal(disputer, 10 ether);
+        // Cap it to 10 eth, so the number of jurors is not astronomical.
+        disputeValue = bound(disputeValue, arbitrationCost, 10 ether);
+        vm.deal(disputer, 10 ether);
contracts/test/foundry/KlerosCore_Appeals.t.sol (1)

569-628: Prefer bound over assume for appealValue.

Keeps runs within limits and reduces discarded cases.

Apply this diff:

-        vm.assume(appealValue <= 10 ether);
-        vm.deal(crowdfunder1, 10 ether);
+        appealValue = bound(appealValue, 0, 10 ether);
+        vm.deal(crowdfunder1, 10 ether);
contracts/test/foundry/KlerosCore_Staking.t.sol (4)

10-10: Remove unused console import.

Apply this diff:

-import {console} from "forge-std/console.sol";

446-501: Use bound to constrain stake amounts; avoids discarded fuzz runs.

Apply this diff:

-        vm.assume(firstStake >= minStake && firstStake <= stakerSupply);
-        vm.assume(secondStake >= minStake && secondStake <= stakerSupply);
+        firstStake = bound(firstStake, minStake, stakerSupply);
+        secondStake = bound(secondStake, minStake, stakerSupply);

502-579: Bound stake amounts for the second court scenario as well.

Apply this diff:

-        vm.assume(firstStake >= minStake && firstStake <= stakerSupply / 2); // Split the supply into two because courts are different now
-        vm.assume(secondStake >= minStake && secondStake <= stakerSupply / 2);
+        firstStake = bound(firstStake, minStake, stakerSupply / 2); // Split the supply into two because courts are different now
+        secondStake = bound(secondStake, minStake, stakerSupply / 2);

580-620: Constrain iterations to realistic bounds to speed up fuzzing.

Only up to 4 delayed stakes exist here.

Apply this diff:

-        // Test with large numbers but do not trigger possible overflow
-        vm.assume(iterations < 2 ** 128);
+        // Keep within a practical bound; there are only 4 delayed stakes in this test.
+        iterations = bound(iterations, 0, 8);
contracts/test/foundry/KlerosCore_Drawing.t.sol (2)

125-164: Bound iterations to avoid pathological values and OOG risk.

Apply this diff:

-        core.draw(disputeID, iterations);
+        iterations = bound(iterations, 0, DEFAULT_NB_OF_JURORS * 8);
+        core.draw(disputeID, iterations);

165-209: Prefer bound over assume; also constrain iterations relative to jurors.

Apply this diff:

-        // Cap it to 10 eth, so the number of jurors is not astronomical.
-        vm.assume(disputeValue >= arbitrationCost && disputeValue <= 10 ether);
-        vm.deal(disputer, 10 ether);
+        // Cap it to 10 eth, so the number of jurors is not astronomical.
+        disputeValue = bound(disputeValue, arbitrationCost, 10 ether);
+        vm.deal(disputer, 10 ether);
@@
-        core.draw(disputeID, iterations);
+        iterations = bound(iterations, 0, (disputeValue / feeForJuror) * 8);
+        core.draw(disputeID, iterations);
contracts/test/foundry/KlerosCore_Execution.t.sol (2)

752-789: Constrain iterations to a sane range for execute().

Prevents excessive loop requests and speeds up fuzzing.

Apply this diff:

-        core.execute(disputeID, roundID, iterations);
+        iterations = bound(iterations, 0, DEFAULT_NB_OF_JURORS * 16);
+        core.execute(disputeID, roundID, iterations);

790-850: Bound disputeValue and iterations; keep iterations relative to juror count.

Apply this diff:

-        // Cap it to 10 eth, so the number of jurors is not astronomical.
-        vm.assume(disputeValue >= arbitrationCost && disputeValue <= 10 ether);
-        vm.deal(disputer, 10 ether);
+        // Cap it to 10 eth, so the number of jurors is not astronomical.
+        disputeValue = bound(disputeValue, arbitrationCost, 10 ether);
+        vm.deal(disputer, 10 ether);
@@
-        core.execute(disputeID, roundID, iterations);
+        iterations = bound(iterations, 0, nbJurors * 16);
+        core.execute(disputeID, roundID, iterations);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e96a87 and 6752cad.

📒 Files selected for processing (7)
  • contracts/src/arbitration/arbitrables/ArbitrableExample.sol (2 hunks)
  • contracts/test/foundry/KlerosCore_Appeals.t.sol (1 hunks)
  • contracts/test/foundry/KlerosCore_Disputes.t.sol (2 hunks)
  • contracts/test/foundry/KlerosCore_Drawing.t.sol (1 hunks)
  • contracts/test/foundry/KlerosCore_Execution.t.sol (1 hunks)
  • contracts/test/foundry/KlerosCore_Staking.t.sol (3 hunks)
  • contracts/test/foundry/KlerosCore_Voting.t.sol (2 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). (11)
  • 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: Analyze (javascript)
  • GitHub Check: hardhat-tests
🔇 Additional comments (3)
contracts/src/arbitration/arbitrables/ArbitrableExample.sol (1)

43-44: Good move: centralize ruling options in storage.

This reduces duplication and aligns dispute creation with runtime configuration.

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

97-97: Assertion message tweak is fine.

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

5-5: Import consolidation LGTM.

@jaybuidl jaybuidl linked an issue Sep 30, 2025 that may be closed by this pull request
@jaybuidl jaybuidl changed the title feat: fuzzing tests feat: stateless fuzzing tests Sep 30, 2025
@jaybuidl jaybuidl merged commit 835d45b into dev Sep 30, 2025
15 of 20 checks passed
@jaybuidl jaybuidl deleted the feat/fuzzing-test branch September 30, 2025 17:12
@jaybuidl jaybuidl added the Package: Contracts Court smart contracts label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Package: Contracts Court smart contracts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contracts: Stateless Fuzz tests

2 participants