Repository navigation
fix(contracts): commit–reveal SlashJudge challenges to stop reward front-running (#854) - #901
Conversation
…ont-running (#854) SlashJudge disclosed all slashable evidence in the challenge calldata, so a mempool watcher could copy a pending honest challenge, resubmit it as their own msg.sender, and capture the 50% challenger reward (the honest tx then reverting EvidenceAlreadyUsed). The bond round-trips, so only the reward was at risk — but that reward is the entire incentive for off-path witnesses, so the vector hollowed out the enforcement layer. Make every challenge a two-phase commit–reveal: - commitChallenge(commitment) stores an opaque keccak256(abi.encode(evidenceHash, salt, msg.sender)); a stored slot older than REVEAL_WINDOW may be overwritten so an offline/paused challenger is never wedged on a (salt, evidence) pair. - the three submit*Challenge functions gain a salt arg and now reveal: _resolve reconstructs the caller's commitment, enforces MIN_REVEAL_DELAY (1 min) ≤ age ≤ REVEAL_WINDOW (1 day), deletes it, then slashes as before (CEI preserved, nonReentrant). Binding msg.sender means a copy of the reveal finds no commitment; the maturation gate plus usedEvidenceHash close the same-block race. _verifyPair folds in the offense predicate and returns only evidenceHash (and _checkRegistered moves to the callers) to stay within the stack limit now that salt rides along — via_ir is off. Amends ADR 014 with the decision record (the missing-decision label), updates the frozen ISlashJudge selectors, and regenerates the affected gas-snapshot entries. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 27487769134 |
Contracts coverageLine coverage: 89.92% (1856/2064 lines) |
There was a problem hiding this comment.
Code Review
This pull request implements a two-phase commit-reveal mechanism for the SlashJudge contract to mitigate challenge front-running and protect the 50% challenger reward from MEV-extraction, as described in ADR 014. It introduces a commitChallenge function to register opaque commitments binding the challenger's address, and updates the three challenge functions (submitPhantomChallenge, submitRateChallenge, and submitBlacklistChallenge) to require a salt parameter to reveal and resolve matured commitments. Comprehensive unit and integration tests have been added to verify the new flow, including delays, expiry, duplicate commits, and race conditions. There are no review comments, so no additional feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Implements a commit–reveal flow for SlashJudge challenges to prevent mempool copycats from stealing the 50% challenger reward by front-running the reveal transaction, while keeping slash semantics and bond handling unchanged at reveal time.
Changes:
- Added
commitChallenge(bytes32)and a per-commitment timestamp mapping, plus fixedMIN_REVEAL_DELAY/REVEAL_WINDOWenforcement in_resolve. - Extended all
submit*Challengefunctions with a trailingbytes32 saltand updated internal verification flow to accommodate the new reveal step. - Updated Solidity tests, ABI freeze assertions, gas snapshot, and ADR 014 to reflect the new commit–reveal workflow.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/src/SlashJudge.sol | Adds commitment storage + time bounds and enforces commit–reveal during challenge resolution. |
| contracts/src/interfaces/ISlashJudge.sol | ABI update: adds commitChallenge and salt to all challenge submission functions. |
| contracts/test/SlashJudge.t.sol | Migrates tests to commit→mature→reveal and adds coverage for new failure modes and edge cases. |
| contracts/test/CapacityBondRegionE2E.t.sol | Updates E2E slash path to perform commit–reveal before the blacklist challenge reveal. |
| contracts/test/InterfaceFreeze.t.sol | Re-pins selectors to intentionally reflect the ABI break (salt args + commitChallenge). |
| contracts/.gas-snapshot | Refreshes gas baselines for affected test suites. |
| adr/014-on-chain-verification.md | Documents the front-running vector and the commit–reveal mitigation + parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… stale "submit time" (PR #901 review) Copilot review on #901: - SlashJudge natspec/comment wrote the commitment as keccak256(evidenceHash, salt, …) without abi.encode, which could lead an off-chain implementer to use abi.encodePacked and fail reveals with NoCommitment — align to the exact keccak256(abi.encode(...)) the contract computes. - ADR 014 Bond Handling still said the slash executes "at submit time"; it now executes at reveal time (the submit*Challenge call, after commitChallenge). Comment/doc-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ond Handling; clarify commitChallenge intent (PR #901 re-review) Second-round pr-review-toolkit pass on #901 surfaced doc-rot the first ADR 014 edit missed: three ADRs cite "ADR 014 §Bond Handling" and still said the slash executes "synchronously/immediately at submit time" — now reveal time under commit–reveal. Fixed in adr/003-payments.md, adr/028-slashing-appeals.md, and adr/appendix-operator-key-rotation.md. Also added two NatSpec clarifications to SlashJudge (no behavior change): - commitChallenge is permissionless/unbonded by design and keyed by the opaque commitment, not msg.sender — guards a future maintainer from "fixing" it in a way that breaks salt-rotation recovery or is mistaken for a missing bond check. - note that NoCommitment also surfaces on a mismatched salt/evidence (reveal-side debugging hint). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What & why
Closes #854 (MEDIUM, security).
SlashJudgedisclosed all slashable evidence (probeResponseData,streamResponseData, the operatorslash_sigs) in the challenge calldata. A mempool watcher could copy a pending honest challenge, resubmit it with their own address asmsg.sender, and capture the 50% challenger reward — the honest witness's tx then revertingEvidenceAlreadyUsed, wasting gas. The challenge bond round-trips, so only the reward was at risk, but that reward is the entire incentive for off-path witnesses, so the vector quietly hollowed out the enforcement layer. ADR 014/028 did not acknowledge it.Approach
Two-phase commit–reveal, with the reward bound to the committer:
commitChallenge(bytes32 commitment)stores an opaquekeccak256(abi.encode(evidenceHash, salt, msg.sender))againstblock.timestamp. Moves no funds. A slot older thanREVEAL_WINDOWmay be overwritten, so a stalled or pause-interrupted challenger is never permanently wedged on a(salt, evidence)pair.submit*Challengefunctions gain asaltarg and now reveal:_resolvereconstructskeccak256(abi.encode(evidenceHash, salt, msg.sender)), requires a stored commitment aged ≥MIN_REVEAL_DELAY(1 min) and ≤REVEAL_WINDOW(1 day), deletes it, then slashes exactly as before. CEI preserved (state effects before the externalsafeTransferFrom/slash), all undernonReentrant.Why it closes the vector: the commit is an opaque hash (front-running it reveals nothing); at reveal the evidence is public but the commitment binds
msg.sender, so a copy under a different sender finds no commitment (NoCommitment). A copycat can't pre-commit (evidenceHash is unknown until reveal) and can't commit-then-reveal in time (MIN_REVEAL_DELAY), by which point the honest reveal has consumedusedEvidenceHash. Holds regardless of sequencer trust (Arbitrum FCFS today; Timeboost / decentralized sequencing later). Security does not rely on salt secrecy._verifyPairfolds in the offense predicate and returns onlyevidenceHash(and_checkRegisteredmoves to the callers) to stay within the stack limit now thatsaltrides along —via_iris off.Decision record
This was a
missing-decisionissue. ADR 014 is amended with a "Challenge front-running mitigation (commit–reveal)" section documenting the vector, mechanism, the fixedMIN_REVEAL_DELAY/REVEAL_WINDOWparams, the Arbitrum L2 context, and accepted residuals (gas-bounded commit spam; two-tx + maturation UX). Cross-references ADR 028.Scope
Contracts-only — no Rust/ABI bindings call the challenge functions. The
ISlashJudgeABI break (addedsalt+commitChallenge) is deliberately re-pinned inInterfaceFreeze.t.sol. EIP-170 pressure is onCapacityBond, notSlashJudge(runtime 14,305 B, ample headroom).Tests
SlashJudge.t.solmigrated to commit→mature→reveal, plus new cases:NoCommitment,RevealTooEarly,CommitmentExpired,CommitmentExists, wrong-challenger reveal, blind-race first-reveal-wins, consumed/overwritten-on-expiry commitment, exact window boundaries,ChallengeCommittedemission, and salt-participation.CapacityBondRegionE2E.t.soldrives the realCapacityBond.slashthrough the new flow.Verification
forge fmt --check✓ ·FOUNDRY_PROFILE=ci forge build --sizes --deny warnings✓forge test— 553 passed, 0 failedslitherexit 0 (no medium+) ·aderyn0 high ·pre-commit(solhint, markdownlint, ADR hygiene, cargo deny) ✓.gas-snapshotregenerated; diff scoped to the affected suitesReviewed via the pr-review-toolkit (code, tests, silent-failure, comments) and a Solidity-security pass — findings addressed (notably the expired-commitment overwrite and ADR causality/enforcement wording).
🤖 Generated with Claude Code