Skip to content

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Sep 8, 2025

PR-Codex overview

This PR focuses on updating the handling of answers in the Reveal.tsx file to accommodate invalid disputes and modifying the readArtifacts function in wagmi.config.ts to include a new condition for artifact suffixes based on ArbitratorTypes.

Detailed summary

  • In Reveal.tsx, added logic to initialize candidates with a default answer if answers is empty.
  • Modified the reduce function to use candidates instead of answers.
  • In wagmi.config.ts, updated artifact suffix logic to include ArbitratorTypes.neo.
  • Changed the condition for if statement from checking for vanilla to university.

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

Summary by CodeRabbit

  • Bug Fixes

    • Vote reveal now works when a dispute has no listed answers by presenting a “Refuse To Arbitrate” option, preventing failed reveals and improving juror reliability.
  • Chores

    • Artifact naming/selection logic adjusted to handle an additional arbitrator variant consistently, improving build/deployment behavior for that variant.

@tractorss tractorss requested a review from a team as a code owner September 8, 2025 18:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Walkthrough

Adds a fallback in getSaltAndChoice to use a default “Refuse To Arbitrate” candidate when answers is empty, and adjusts artifact suffix logic in wagmi.config so ArchetypeTypes.neo is treated like vanilla and the artifact-suffix removal only applies to university. (≤50 words)

Changes

Cohort / File(s) Summary of Changes
Voting reveal logic
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx
getSaltAndChoice now builds a candidates array that falls back to a single default “Refuse To Arbitrate” answer (id: "0x0", title/description "Refuse To Arbitrate") when the input answers is empty, then reduces over candidates (without mutating answers) to compute salt and determine choice. Matching logic unchanged.
Wagmi artifact naming
web/wagmi.config.ts
Artifact suffix logic updated so ArchetypeTypes.neo is treated the same as vanilla (empty suffix). The conditional that stripped the suffix for non-vanilla types was narrowed to only ArchetypeTypes.university, leaving other non-vanilla names (e.g., neo) unmodified.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Reveal UI
  participant Func as getSaltAndChoice
  participant Answers as answers[]

  UI->>Func: call getSaltAndChoice(commit, answers, ...)
  alt answers is empty
    Func->>Func: candidates = [{ id: "0x0", title: "Refuse To Arbitrate", description: "Refuse To Arbitrate" }]
    note right of Func #DDEBF7: fallback candidate inserted
  else answers not empty
    Func->>Func: candidates = answers
  end
  Func->>Func: reduce over candidates -> compute salt & compare innerCommit
  Func-->>UI: return { salt, choice }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • alcercu

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly indicates a fix in the web module related to vote reveal for invalid disputes, directly reflecting the primary change in the pull request; it is concise, clearly scoped, and aligns with the developer’s intent without including extraneous detail.
Description Check ✅ Passed The description provides a clear overview of the modifications to Reveal.tsx and wagmi.config.ts, detailing the handling of empty answers with a default candidate and the updated artifact suffix logic, which aligns directly with the changes in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

A rabbit peeks where answers lack,
Plants RTA upon the track.
Salts align, the hashes play,
Reveal returns the rightful way.
🐇✨

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.

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.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/invalid-dispute-vote-reveal

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

@netlify
Copy link

netlify bot commented Sep 8, 2025

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

Name Link
🔨 Latest commit 6bea072
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-testnet-devtools/deploys/68c016674d9efe000823eaab
😎 Deploy Preview https://deploy-preview-2134--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 project configuration.

@netlify
Copy link

netlify bot commented Sep 8, 2025

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

Name Link
🔨 Latest commit 6bea072
🔍 Latest deploy log https://app.netlify.com/projects/kleros-v2-university/deploys/68c016679bdb070008dd3bd7

@netlify
Copy link

netlify bot commented Sep 8, 2025

Deploy Preview for kleros-v2-testnet ready!

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

@netlify
Copy link

netlify bot commented Sep 8, 2025

Deploy Preview for kleros-v2-neo ready!

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

Caution

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

⚠️ Outside diff range comments (1)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (1)

72-78: Guard against undefined result and reset isSending on early return.

getSaltAndChoice can return undefined; destructuring will throw and isSending stays true.

@@
-    const { salt, choice } = isUndefined(storedSaltAndChoice)
-      ? await getSaltAndChoice(signingAccount, generateSigningAccount, saltKey, disputeDetails?.answers ?? [], commit)
-      : JSON.parse(storedSaltAndChoice);
-    if (isUndefined(choice)) return;
+    const result = isUndefined(storedSaltAndChoice)
+      ? await getSaltAndChoice(
+          signingAccount,
+          generateSigningAccount,
+          saltKey,
+          disputeDetails?.answers ?? [],
+          commit
+        )
+      : JSON.parse(storedSaltAndChoice);
+    if (!result || isUndefined(result.choice) || (typeof result.choice === "bigint" && result.choice < 0n)) {
+      setIsSending(false);
+      return;
+    }
+    const { salt, choice } = result;
🧹 Nitpick comments (1)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (1)

150-166: Tiny perf/readability nit: precompute salt as BigInt once.

@@
-  const salt = keccak256(rawSalt);
+  const salt = keccak256(rawSalt);
+  const saltBig = BigInt(salt);
@@
-      const innerCommit = keccak256(encodePacked(["uint256", "uint256"], [BigInt(answer.id), BigInt(salt)]));
+      const innerCommit = keccak256(encodePacked(["uint256", "uint256"], [BigInt(answer.id), saltBig]));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36a2455 and 8b6e1f9.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (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-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: Redirect rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-university
  • 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: hardhat-tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (2)

152-156: Intent LGTM: sensible fallback for invalid disputes.


152-155: Verify Answer.id format with SDK definitions
Inspect the local kleros-sdk workspace’s package.json for its version and review the SDK’s Answer.id declaration (e.g., in kleros-sdk/src/types/Answer.ts or the generated .d.ts files) to confirm whether IDs are decimal strings (“0”, “1”, …) or hex strings (“0x0”, “0x1”, …) and adjust the injected “0x0” accordingly.

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 (2)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (2)

158-167: Prevent sending an invalid choice (-1) when commit doesn’t match any candidate.

Current code can return -1 and proceed to cast, causing an invalid uint256 or a failed tx. Return an undefined choice when not found so the caller short-circuits safely.

-  const { choice } = candidates.reduce<{ found: boolean; choice: bigint }>(
+  const { found, choice } = candidates.reduce<{ found: boolean; choice?: bigint }>(
     (acc, answer) => {
       if (acc.found) return acc;
       const innerCommit = keccak256(encodePacked(["uint256", "uint256"], [BigInt(answer.id), BigInt(salt)]));
       if (innerCommit === commit) {
-        return { found: true, choice: BigInt(answer.id) };
+        return { found: true, choice: BigInt(answer.id) };
       } else return acc;
     },
-    { found: false, choice: BigInt(-1) }
+    { found: false, choice: undefined }
   );
-  return { salt, choice };
+  if (!found) return { salt, choice: undefined };
+  return { salt, choice };

72-91: Always clear isSending; move it to a finally block.

If choice is undefined, handleReveal returns early and leaves isSending stuck true.

   const handleReveal = useCallback(async () => {
-    setIsSending(true);
-    const { salt, choice } = isUndefined(storedSaltAndChoice)
-      ? await getSaltAndChoice(signingAccount, generateSigningAccount, saltKey, disputeDetails?.answers ?? [], commit)
-      : JSON.parse(storedSaltAndChoice);
-    if (isUndefined(choice)) return;
+    setIsSending(true);
+    try {
+      const { salt, choice } = isUndefined(storedSaltAndChoice)
+        ? await getSaltAndChoice(signingAccount, generateSigningAccount, saltKey, disputeDetails?.answers ?? [], commit)
+        : JSON.parse(storedSaltAndChoice);
+      if (isUndefined(choice)) return;
 
       const simulate = isGated ? simulateDisputeKitGatedCastVote : simulateDisputeKitClassicCastVote;
       const { request } = await catchShortMessage(
         simulate(wagmiConfig, {
           args: [parsedDisputeID, parsedVoteIDs, BigInt(choice), BigInt(salt), justification],
         })
       );
       if (request && walletClient && publicClient) {
         await wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then(({ status }) => {
           setIsOpen(status);
         });
       }
-    setIsSending(false);
+    } finally {
+      setIsSending(false);
+    }
   }, [
♻️ Duplicate comments (1)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (1)

152-157: Good fix: derive local candidates without mutating input.

Using a local candidates list avoids side effects on React state/query caches and matches prior feedback.

🧹 Nitpick comments (3)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (3)

152-152: Fix the comment and acronym.

The code no longer mutates answers, and the common acronym is “RTA”.

-  // when dispute is invalid, just add RFA to the answers array
+  // Dispute invalid: derive a local candidates list starting with “Refuse To Arbitrate” (RTA); do not mutate `answers`.

154-155: Drop optional chaining; answers is non-optional here.

Minor cleanup; improves type narrowing.

-    answers?.length > 0
+    answers.length > 0

156-156: Mark fallback as reserved (if supported) and keep the extra field at runtime.

Helps downstream logic/UI distinguish the special option; safe even with the assertion.

-      : [{ id: "0x0", title: "Refuse To Arbitrate", description: "Refuse To Arbitrate" } as Answer];
+      : [{ id: "0x0", title: "Refuse To Arbitrate", description: "Refuse To Arbitrate", reserved: true } as Answer];

If the SDK’s Answer type doesn’t include reserved?: boolean, keep the extra field (runtime only) or omit it.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b6e1f9 and 7a78b27.

📒 Files selected for processing (1)
  • web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
web/src/pages/Cases/CaseDetails/Voting/Classic/Reveal.tsx (1)
web/src/context/NewDisputeContext.tsx (1)
  • Answer (13-18)
⏰ 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-university
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: hardhat-tests
  • GitHub Check: Analyze (javascript)

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 8, 2025
kemuru
kemuru previously approved these changes Sep 9, 2025
@tractorss tractorss dismissed stale reviews from kemuru and coderabbitai[bot] via 6bea072 September 9, 2025 11:58
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 9, 2025

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 (1)
web/wagmi.config.ts (1)

62-65: Guard suffix stripping to avoid accidental empty-suffix slice.

Defensive check ensures we only strip when the suffix is present and actually at the end of the name.

-        if (type === ArbitratorTypes.university) {
-          nameWithoutSuffix = name.slice(0, -artifactSuffix.length);
-          // console.debug(`Using ${nameWithoutSuffix} instead of ${name}`);
-        }
+        if (type === ArbitratorTypes.university && artifactSuffix && name.endsWith(artifactSuffix)) {
+          nameWithoutSuffix = name.slice(0, -artifactSuffix.length);
+          // console.debug(`Using ${nameWithoutSuffix} instead of ${name}`);
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a78b27 and 6bea072.

📒 Files selected for processing (1)
  • web/wagmi.config.ts (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). (14)
  • GitHub Check: Redirect rules - kleros-v2-neo
  • GitHub Check: Header rules - kleros-v2-neo
  • GitHub Check: Pages changed - kleros-v2-neo
  • GitHub Check: Redirect rules - kleros-v2-university
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Redirect rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-university
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Header rules - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-university
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: Pages changed - kleros-v2-testnet
  • GitHub Check: hardhat-tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
web/wagmi.config.ts (1)

20-23: ArbitratorTypes.neo is present and deployments have no “Neo”-suffixed artifacts Verified that ArbitratorTypes.neo exists in the enum and no *Neo.json files are in the deployments directories, so the suffixless handling is correct.

@jaybuidl jaybuidl merged commit 62d5723 into dev Sep 9, 2025
19 of 24 checks passed
@jaybuidl jaybuidl deleted the fix/invalid-dispute-vote-reveal branch September 9, 2025 13:04
jaybuidl added a commit that referenced this pull request Sep 9, 2025
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.

3 participants