Pre-audit hardening: settlement robustness, term bounds, pinned Kleros interface, docs #9

Merged
Taskuler-bot merged 2 commits from fix/pre-audit-1 into main 2026-11-13 00:58:59 +00:00
Member

Pre-audit hardening of the Market and supporting docs. No deploy, no tag. Base: main @ 856b48c.

Changes

  • Settlement robustness (PayoutLib): the WorkHistory record is now best effort. It is called in try/catch with a fixed 800k gas budget; on failure the payout stands and WorkHistoryRecordFailed(jobId) is emitted. Settlement entry points revert with InsufficientGas (retryable) instead of skipping the record when the caller supplies too little gas. Every settlement path, including rule(), works with the recorder role revoked (tests).
  • Settlement offer cap: rounds is no longer reset; the cap (opening offer + maxCounters) counts every offer on the job, across cancellations and rejections. Withdrawing the final allowed offer escalates, as rejecting it already did.
  • Caller-side term bounds on posting: PostParams gains maxTotal (max bounty + fee + customer deposit), arbitrator (must equal the current arbitrator) and validUntil (inclusive). New errors TermsChanged, Expired.
  • CR2: assignReviewer stays allowed while the job is Open, including after bids. Assignment and every reassignment emit the indexed ReviewerAssigned(jobId, reviewer, fee, reassignment) event, now documented, so bidders and builders can track the reviewer.
  • Kleros interface: src/interfaces/kleros/IArbitrableV2.sol and IArbitratorV2.sol are byte-identical copies of @kleros/kleros-v2-contracts 2.0.0-rc.2, commit 9fa3677c7a837d0d9d579c06eb5c9f224b96f14f (header notes the source and sha256). DisputeRequest is now (arbitrator, arbitratorDisputeID, templateId); DisputeCreated(jobId, disputeId, cost) links disputes to jobs. disputeTemplateUri stays as an informational setting.
  • NatSpec / errors: fixed maxCounters, DisputeOptionsSet and submitDelivery docs; removed unused NotArbitrator. NotReviewer, ReviewWindowClosed and InsufficientGas are raised only in the external libraries; each now has a single declaration in TaskulerMarket (so it is in the Market ABI for revert decoding), referenced from ReviewLib / PayoutLib.
  • Invariant: invariant_NoStuckEscrow now runs on every call: per token, jobHeld must equal exactly what live jobs (by status) and active bids hold, the balance must cover escrow plus claims, and no arbitration prepay may remain.
  • Docs: new docs/KNOWN-ISSUES.md and docs/THREAT-MODEL.md; refreshed docs/AUDIT-SCOPE.md (files, line counts, base commit); SECURITY-NOTES and OPEN-QUESTIONS updated.

ABI changes (frontend)

  • postJob(PostParams) / postProjectJob(PostParams): tuple adds uint256 maxTotal, address arbitrator, uint64 validUntil at the end (selectors change).
  • Event DisputeRequest(address indexed _arbitrator, uint256 indexed _arbitratorDisputeID, uint256 _templateId) (was 5 fields).
  • New event WorkHistoryRecordFailed(uint256 indexed jobId).
  • New errors TermsChanged(), Expired(), InsufficientGas(); removed NotArbitrator().
  • Behaviour: offers after the cap revert SettlementExhausted even after a cancel or reject.

Checks

  • forge test: 211 passed, 0 failed.
  • TaskulerMarket runtime size 22,966 B (limit 24,576).
Pre-audit hardening of the Market and supporting docs. No deploy, no tag. Base: `main` @ `856b48c`. ## Changes - **Settlement robustness (PayoutLib):** the WorkHistory record is now best effort. It is called in `try/catch` with a fixed 800k gas budget; on failure the payout stands and `WorkHistoryRecordFailed(jobId)` is emitted. Settlement entry points revert with `InsufficientGas` (retryable) instead of skipping the record when the caller supplies too little gas. Every settlement path, including `rule()`, works with the recorder role revoked (tests). - **Settlement offer cap:** `rounds` is no longer reset; the cap (opening offer + `maxCounters`) counts every offer on the job, across cancellations and rejections. Withdrawing the final allowed offer escalates, as rejecting it already did. - **Caller-side term bounds on posting:** `PostParams` gains `maxTotal` (max bounty + fee + customer deposit), `arbitrator` (must equal the current arbitrator) and `validUntil` (inclusive). New errors `TermsChanged`, `Expired`. - **CR2:** `assignReviewer` stays allowed while the job is Open, including after bids. Assignment and every reassignment emit the indexed `ReviewerAssigned(jobId, reviewer, fee, reassignment)` event, now documented, so bidders and builders can track the reviewer. - **Kleros interface:** `src/interfaces/kleros/IArbitrableV2.sol` and `IArbitratorV2.sol` are byte-identical copies of `@kleros/kleros-v2-contracts` 2.0.0-rc.2, commit `9fa3677c7a837d0d9d579c06eb5c9f224b96f14f` (header notes the source and sha256). `DisputeRequest` is now `(arbitrator, arbitratorDisputeID, templateId)`; `DisputeCreated(jobId, disputeId, cost)` links disputes to jobs. `disputeTemplateUri` stays as an informational setting. - **NatSpec / errors:** fixed `maxCounters`, `DisputeOptionsSet` and `submitDelivery` docs; removed unused `NotArbitrator`. `NotReviewer`, `ReviewWindowClosed` and `InsufficientGas` are raised only in the external libraries; each now has a single declaration in TaskulerMarket (so it is in the Market ABI for revert decoding), referenced from ReviewLib / PayoutLib. - **Invariant:** `invariant_NoStuckEscrow` now runs on every call: per token, `jobHeld` must equal exactly what live jobs (by status) and active bids hold, the balance must cover escrow plus claims, and no arbitration prepay may remain. - **Docs:** new `docs/KNOWN-ISSUES.md` and `docs/THREAT-MODEL.md`; refreshed `docs/AUDIT-SCOPE.md` (files, line counts, base commit); SECURITY-NOTES and OPEN-QUESTIONS updated. ## ABI changes (frontend) - `postJob(PostParams)` / `postProjectJob(PostParams)`: tuple adds `uint256 maxTotal, address arbitrator, uint64 validUntil` at the end (selectors change). - Event `DisputeRequest(address indexed _arbitrator, uint256 indexed _arbitratorDisputeID, uint256 _templateId)` (was 5 fields). - New event `WorkHistoryRecordFailed(uint256 indexed jobId)`. - New errors `TermsChanged()`, `Expired()`, `InsufficientGas()`; removed `NotArbitrator()`. - Behaviour: offers after the cap revert `SettlementExhausted` even after a cancel or reject. ## Checks - `forge test`: 211 passed, 0 failed. - `TaskulerMarket` runtime size 22,966 B (limit 24,576).
- PayoutLib: WorkHistory record is best effort (try/catch with a fixed gas budget);
  settlement and rule() never depend on it. New event WorkHistoryRecordFailed(jobId)
  and error InsufficientGas.
- Settlement offers: the counter cap counts every offer on a job (cancel/reject no
  longer start a new sequence); withdrawing the final allowed offer escalates.
- postJob/postProjectJob: PostParams gains maxTotal, arbitrator and validUntil
  (caller-side bounds; new errors TermsChanged, Expired).
- assignReviewer: only before the first bid.
- Kleros interfaces pinned byte-identical to @kleros/kleros-v2-contracts 2.0.0-rc.2
  (commit 9fa3677); DisputeRequest now (arbitrator, disputeId, templateId).
- NatSpec fixes; removed unused NotArbitrator; mirrored library errors documented.
- invariant_NoStuckEscrow checks exact per-job escrow and solvency on every call.
- docs: KNOWN-ISSUES.md, THREAT-MODEL.md, refreshed AUDIT-SCOPE.md.
- assignReviewer: allowed while the job is Open, including after bids. Assignment
  and every reassignment emit the indexed ReviewerAssigned(jobId, reviewer, fee,
  reassignment) event; documented.
- NotReviewer, ReviewWindowClosed and InsufficientGas are declared once, in
  TaskulerMarket (so they stay in the Market ABI), and referenced by ReviewLib /
  PayoutLib.
- Tests: bid-then-assign, reassignment event, bidder withdrawal after assignment.
george approved these changes 2026-11-13 00:50:06 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
taskuler/contracts!9
No description provided.