BuilderBonus: Safe-only timelocked Market repoint #16

Merged
Taskuler-bot merged 5 commits from feat/bonus-migration into main 2026-11-13 22:09:03 +00:00
Member

Stacked on #15 (base feat/circuit-breaker). Decided 2026-11-13: BuilderBonus must be able to move to a new Market when the Market is redeployed, before launch. No deployment in this PR.

Design: repoint in place (chosen) vs a new BuilderBonus per Market

  • Chosen: a mutable market changed by a Safe-only timelocked repoint. All program state stays in one contract: per-period builder and customer counts, cancel bars (barredUntil), exclusions, minBounty, reservedCount, awarded, totalOwed and the TSKR budget. A repoint changes only the pointer, so it can't reset any cap or bar.
  • Rejected: a new BuilderBonus per Market. Mappings can't be copied on-chain, so per-period counts, bars and exclusions would start empty (caps reset), the old program's returnExcess would strand the budget for unused slots. Any copy or offset scheme adds a privileged one-off import path, which is a larger surface than a pointer change.
  • Slots are keyed by (Market, jobId) (slots[market][jobId]). Job ids restart on every Market, so this avoids collisions. reserve(jobId) only takes jobs from the current Market; finalize, withdraw, expire and cancelAward take the slot's Market, so slots reserved before a repoint settle against the Market that reserved them. Honest in-flight bonuses are kept and a job can't be counted twice.

Repoint

  • scheduleRepoint(newMarket): owner only; the target must be a contract that answers jobCount() with one word and must differ from the current Market; one pending repoint at a time (an expired one doesn't block). Emits RepointScheduled(from, to, eta).
  • executeRepoint(): owner only, from eta (REPOINT_DELAY = 48 hours) until eta + REPOINT_WINDOW (7 days), then RepointExpired. Re-checks the target. Emits MarketRepointed(from, to).
  • cancelRepoint(): owner only, any time while one is scheduled. Emits RepointCancelled(to).
  • The constructor applies the same target check and emits MarketRepointed(0, market).
  • Unchanged: 2,000 TSKR per bonus, 10 per builder and 3 per customer per period, the 14-day Safe-cancellable claim delay, MIN_FEE_BPS 200, the 1,000 USDC minBounty, and the 2-period bar on both parties after a cancel.
  • The target check stops an EOA, a Safe or a wrong token address, not a hostile contract. The per-address caps do not bind a hostile target, because it can name fresh addresses for every job. The next section covers what bounds it and how to recover.

Budget: funded pool plus a 10M lifetime ceiling (DECIDED 2026-11-13)

  • The fixed 5,000 count and the global slot counter are gone.
  • Lifetime ceiling (George, 2:51 PM CT): MAX_TOTAL = 10M TSKR, with totalPaid and lifetimeCommitted() = totalPaid + committed().
    • reserve reverts LifetimeCapReached if the new earmark would take it above the ceiling.
    • It counts from reservation and award, so finalize never hits it.
    • A withdrawal moves TSKR from owed to paid without freeing headroom.
    • A cancel, void, expiry or release frees exactly its 2,000: that TSKR returns to the pool unpaid, and the slot can never pay.
    • So TSKR ever paid out can't exceed 10M.
  • Each reservation earmarks its 2,000 TSKR: reservedCount, committed() = totalOwed + reservedCount * BONUS, available() = balance - committed (floored at 0).
  • reserve requires available() >= BONUS (NotFunded), so a reserved job's finalize never fails for lack of funds.
  • Releases, voids, cancels and expiries all return their TSKR to the pool. A cancel keeps both parties' period counts used and bars both for 2 periods.
  • returnExcess sends only available(), and only to the allocation vault.
  • No carry-over of unused per-period allowance.

Claim deadline and expiry

  • The unlock step and the claimable aggregate are removed. withdraw(market, jobIds): builder only (NotBuilder), all or nothing, per award.
  • Each award can be claimed from claimableAt until claimableAt + 180 days plus the builder's observed held time (exclusive). Before that window: TooEarly.
  • Batch skipping: withdraw skips ids that can never pay, and reverts NothingToWithdraw if nothing is paid. Skipped ids:
    • claimed, expired, cancelled, voided or released ids
    • ids past the deadline
    • ids not matured at their Market's revocation
  • Still reverts the whole call:
    • NotBuilder (someone else's id, or an unknown one)
    • BadStatus (a reservation only)
    • TooEarly
    • any hold (AccountHeld / HoldCheckFailed), so a hold always blocks every payout.
  • So an expire front-run can't fail a builder's batch, and a duplicate id is paid once.
  • expire(market, jobIds): anyone can call it. It skips ids that can't expire yet. It sets Expired, takes BONUS off totalOwed and emits BonusExpired. Period counts stay used and nobody is barred.
  • Expiry is exact per award, and awards nobody touched expire too, because there is no unlock step. claimWindow(market, jobId) returns (start, deadline).
  • Held builders (L-5; George, 2:51 PM CT):
    • expire runs the same fail-closed hold check for the award's builder (held, revert or garbage on any Market not ignored) and skips the id, so a held builder's award is never expired.
    • A per-builder hold clock (holdClock) is driven by the permissionless pokeHold(builder); expire and withdraw drive it too. It starts when a hold is first observed (HoldObserved) and stops when the hold is observed cleared (HoldCleared(builder, heldFor)).
    • The held seconds extend the deadline of the builder's outstanding awards. heldBaseline stores the credit at award time, so holds before an award don't count.
    • A hold nobody observed while it lasted isn't credited, but one still in place at the deadline always blocks expiry. Keepers poke on Market HoldPlaced / HoldRenewed / HoldLifted and at each until.
    • Gas: one isHeld call (at most 50,000) per Market ever current, per due id, and per id of a builder whose clock is running. The InsufficientGas guard applies.

Hostile or stuck Market: revocation (M-1, L-3, L-4)

  • revokeMarket(m) (owner only, final, instant). It works on any Market that was ever current, including the current one, and records revokedAt. After it:
    • reserve reverts RevokedMarket() if m is current.
    • Awards with claimableAt <= revokedAt still pay until their 180-day deadline.
    • Unmatured awards (claimableAt > revokedAt) can't be withdrawn (RevokedMarket). Only the Safe can void them, with voidAwards(m, ids), which skips other ids.
    • Anyone can free reserved, never-awarded slots with finalize(m, id) (voids without calling m) or releaseSlots(m, ids) (Reserved slots only, other ids skipped).
    • Voiding returns the TSKR to the pool, restores the named builder's and customer's period counts and bars nobody (the Market may have named real people). It emits SlotVoided.
    • A revoked Market can't be scheduled again.
  • cancelAwards(m, ids, reason): owner-only batch cancel with the 2-period bars. An empty reason reverts; ids that aren't pending awards inside the 14 days are skipped, not reverted. The runbook has the Safe cancel flagged awards before revoking.

Per-Market period cap (timelocked increases)

  • marketPeriodCap defaults to 250 reservations and 250 awards per Market per 30-day period. It can be set from 1 to 5,000 (MAX_MARKET_PERIOD_CAP).
  • setMarketPeriodCap(cap):
    • A decrease applies at once and cancels any pending increase (MarketPeriodCapIncreaseCancelled).
    • An increase is scheduled (pendingCap, pendingCapEta, MarketPeriodCapIncreaseScheduled).
    • The same value reverts BadCap.
  • executeMarketPeriodCap() runs from 48 hours after scheduling until 7 days after that (TooEarly / RepointExpired). cancelMarketPeriodCap() cancels a pending increase. A new schedule replaces the old one and restarts the delay.
  • A finalize over the cap reverts MarketPeriodCapReached; it can be retried next period.

Withdraw hold checks: fail closed (L-1, L-2)

  • withdraw calls isHeld (50,000 gas each) on every Market that was ever current, revoked or not.
    • true reverts AccountHeld(account).
    • A revert, out-of-gas, empty or malformed answer reverts HoldCheckFailed(market). The skip-and-event behaviour is removed.
    • The InsufficientGas() guard is kept, so the caller must forward enough gas for each check.
    • Holds on the previous Market keep applying after a repoint (L-1).
  • Per-Market ignore flag (Safe only):
    • scheduleIgnoreHolds(m) (IgnoreHoldsScheduled(m, eta)), then executeIgnoreHolds(m) from 48 hours to 7 days after (HoldsIgnoredSet(m, true)).
    • cancelIgnoreHolds(m) (IgnoreHoldsCancelled). An unexecuted schedule expires.
    • honourHolds(m) clears the flag and any pending schedule at once (HoldsIgnoredSet(m, false)).
    • The runbook says to re-place real holds on the current Market before ignoring an old one.

ABI changes (BuilderBonus, vs main)

  • Repoint functions: scheduleRepoint(address) 0x36f3b04c, executeRepoint() 0x89c8f6d0, cancelRepoint() 0x196cfe2a, pendingMarket() 0xe70f15eb, pendingMarketEta() 0xe47c081a, REPOINT_DELAY() 0xe3e6e243, REPOINT_WINDOW() 0x7384dc06. market() is now a storage variable.
  • Changed signatures (Market first): finalize(address,uint256) 0x0553e156, cancelAward(address,uint256,string) 0x67cec78d, slots(address,uint256) 0xb5f95d9b, qualifies(address,uint256,Job) 0xb73e4204. reserve(uint256) is unchanged.
  • Pool and expiry:
    • withdraw(address,uint256[]) 0x8293744b and expire(address,uint256[]) 0x6fee75aa
    • views claimWindow(address,uint256) 0x027e5c46, committed() 0x9b6b9664, available() 0x48a0d754, reservedCount() 0xc38f7617, CLAIM_WINDOW() 0x9f34fc80
  • Revocation, cap and holds:
    • revokeMarket(address) 0x29527b82, releaseSlots(address,uint256[]) 0xc178e524, voidAwards(address,uint256[]) 0x3f96408c, cancelAwards(address,uint256[],string) 0x919e49e0
    • cap: setMarketPeriodCap(uint256) 0x92f5bf77, executeMarketPeriodCap() 0xc3a8db8a, cancelMarketPeriodCap() 0x37a53dac, pendingCap() 0x200ad79c, pendingCapEta() 0x65621dc5
    • hold flag: scheduleIgnoreHolds(address) 0x7bc6be3b, executeIgnoreHolds(address) 0x79f651a8, cancelIgnoreHolds(address) 0x54df62c5, honourHolds(address) 0x498f0368
    • other views: marketPeriodCap() 0xf431f3ad, marketPeriod(address,uint256) 0x6db3fb58, marketState(address) 0xa7a9a62c (known, revoked, holdsIgnored, revokedAt, ignoreHoldsEta), markets(uint256) 0xb1283e77, marketsLength() 0xa5402544, DEFAULT_MARKET_PERIOD_CAP() 0x3cd5bc0b, MAX_MARKET_PERIOD_CAP() 0xe7206f84, HOLD_CHECK_GAS() 0xb7b9e33e
  • Removed: error ClaimExpired() (past-deadline ids are skipped now), withdraw() 0x3ccfd60b, unlock(address,uint256) 0x7eee288d, claimable(address) 0x402914f5, slotsUsed() 0xbee2d1cf, MAX_BONUSES() 0x88023256; event BonusUnlocked and error CapReached().
  • Events (topic0):
    • SlotReserved(uint256 indexed jobId, address indexed builder, uint256 indexed period, uint256 reservedCount, address market) 0x1911f691a9a4766962588fb14bcce650bae92d9a25a8869cc824064f6d3b26e9. Its 4th field is now the earmarked reservation count, not slots used.
    • BonusAwarded(... address indexed market, uint256 amount, uint256 awarded, uint64 claimableAt) 0x01021a989f04d43e7cd1eb76cb40037dafc4d84d7d7b6d4c0b8dff11e2466a90
    • BonusCancelled(...) 0xd4d838bf34f94c61dad05f2d5d83a2ebc6a2c6c979f23a736d958708f462ceb9
    • SlotReleased(...) 0x83e3981d6ea372aa363d0ca739f3831b5c7eaa1da23df45f0b8c0b9c401c1b57
    • New:
      • BonusClaimed(uint256 indexed jobId, address indexed builder, address indexed market, uint256 amount) 0xf957dcd5d8e121c35d1be9e62b9e9b9a01e2bd4088b0358745836a2809f5d62f
      • BonusExpired(...) 0x9b40822509ce8549f5979de7f8d513461d9f2359335be1564578a5705d5705c4
      • RepointScheduled 0xcf0d8c2cec18428c57ea056f7768ae93fa7d9950f767b54be022d23a9881d53a
      • RepointCancelled 0x38583e2bc13a49188425acd641a802373dc0fdebd4120858b6a1b0bf8b8d1cd0
      • MarketRepointed 0xdc87b3539265de7805d26cb20f770a3009bab8e3608eaeb3ac15feece65af3a8
      • MarketRevoked(address indexed) 0x773e25ce1a503d1493ecf52f9b9b5cf4ae9ea2ba1dd06ffc052feac43ea0a013
      • SlotVoided 0x1037a3de4085d54a686f9833ac1a984ff83733bdf76ee2d787e3929e23107035
      • MarketPeriodCapSet(uint256) 0xa48057cfd44812b421bbf99e7074b1bbcafc74eef7304fe42a6ba8a0b805f436
      • MarketPeriodCapIncreaseScheduled(uint256,uint64) 0x6f90721656d2d051a59a65530e146d70bcca3a54b88cf53ff347651d514c3015
      • MarketPeriodCapIncreaseCancelled(uint256) 0xd03c3f65f7e4449b2da250aa5050b0434bfaef705e5e99c1d066c998769bebb5
      • IgnoreHoldsScheduled(address indexed,uint64) 0x1a8bcb24cb2d40ea8cfdb6ce6d92ada3354241cf985d6c42d2ac81e882816d62
      • IgnoreHoldsCancelled(address indexed) 0xf03c657948f07477e2f3661a9005813ee490542e7c0bdea36529f163778387e3
      • HoldsIgnoredSet(address indexed,bool) 0xcb08c9fdfaf2cc058ac62ab8741e1ed89bc52b8758686a6ec718023eb79ea70d
      • HoldObserved(address indexed builder) 0xcb725322f71f7b6df17f15b2b5aa08631d40ac673142b181ba455da4038c40ed
      • HoldCleared(address indexed builder, uint256 heldFor) 0xf4b8699323f3ce580372a8fd4934bd4ce95db85feaf1cf53c7042cf82b616b04
    • Removed since bb06199: event HoldCheckFailed(address,address) 0x2d8223d4…. It is now an error, HoldCheckFailed(address) 0x66af4bf0.
  • Lifetime ceiling and hold clock: MAX_TOTAL() 0xcd60fe35 (same selector as before, now the lifetime TSKR ceiling), totalPaid() 0xe7b0f666, lifetimeCommitted() 0x183a5e82, pokeHold(address) 0x300c0699, holdClock(address) 0x73428ab3 (since, credit), heldBaseline(address,uint256) 0x9771078c; error LifetimeCapReached() 0x5537755e.
  • New errors: BadMarket(), RepointPending(), NoRepoint(), RepointExpired(), RevokedMarket(), MarketPeriodCapReached(), BadCap(), InsufficientGas(), NotBuilder(), NotPending(), HoldCheckFailed(address).
  • abis/arbitrum-sepolia is not changed: it describes the deployed contracts.

Tests

  • test/BonusRepoint.t.sol (18): schedule/execute/cancel/expiry with boundaries, access, target checks, carry-over of counts, bars, exclusions and budget, old-Market slots settle in place, and a hostile Market bounded by the caps and the pool.
  • test/BonusRevoke.t.sol (20):
    • Hostile Market end to end: the cap binds; strangers can release reservations but can't void awards (voidAwards reverts for non-owners); the Safe voids the unmatured ones; nobody is barred.
    • Revocation timing: an award that matures exactly at revokedAt still pays and still expires; an unmatured one can't be withdrawn.
    • finalize voids on a revoked Market; a stuck Market's reservations can be released permissionlessly; cancelAwards skips mixed ids (matured, withdrawn, cancelled, reserved, unknown).
    • Holds: a reverting, garbage, OOG or empty hold check blocks withdraw, also after revoke; a revoked Market's real hold blocks.
    • Ignore flag: works only after 48 hours, inside the window and only for the owner, then unblocks; it can be cancelled and expires; honourHolds is instant.
    • Cap: the increase delay, window, cancel and expiry; an instant decrease drops a pending increase.
    • Also the gas guard and L-1.
  • New test/BonusPool.t.sol (18):
    • The pool exhausts and refills via cancel, release, void and expiry; earmarked reservations always award.
    • There is no count cap (a 5,001st award).
    • Deadline boundaries; expiry of untouched awards, batch expiry, and expiry after repoint and revoke; the deadline keeps running under a hold.
    • Per-award all-or-nothing withdraw, no carry-over, and a hostile Market bounded by the cap and the pool.
  • Updated test/BuilderBonus.t.sol and test/invariant/BonusInvariant.t.sol (accounting: withdrawn + expired + owed == awarded; runs start at 4,990 awarded to cross the former 5,000).
  • New test/BonusLifetime.t.sol (14):
    • L-5: a held builder at the deadline isn't expired, also when nobody poked before; the remaining window is restored by the held time (exact boundaries); withdraw closes a cleared hold; credit counts only after the award; unobserved holds aren't credited; a broken Market's answer counts as held until the ignore flag excludes it; expire needs gas.
    • MAX_TOTAL: paid, owed and earmarked count toward it; a withdrawal frees nothing; cancel, void, expiry and release free headroom.
    • The remaining revert branches.
  • Withdraw skipping (test/BonusPool.t.sol, test/BonusRevoke.t.sol): expired, swept-ahead, claimed, cancelled, released, past-deadline and duplicate ids are skipped; NotBuilder, unknown, reserved, TooEarly and holds still revert; on a revoked Market an unmatured id is skipped while the matured one pays.
  • The invariant suite adds invariant_LifetimeCap.
  • Full forge test with the fork RPC set: 342 passed, 0 failed, 0 skipped.
  • forge coverage --ir-minimum on BuilderBonus: 100% branches (83/83), 100% functions, 99.3% statements and 99.0% lines. The 3 lines reported as unhit are mapping artifacts of --ir-minimum; the tests exercise them: the instant cap decrease, cancelMarketPeriodCap, and withdraw closing a cleared hold clock.

Size

BuilderBonus runtime is 14,479 B (10,097 B under the limit). TaskulerMarket is unchanged at 24,146 B (430 B margin).

Docs

  • README, SECURITY-NOTES, KNOWN-ISSUES KI-14, THREAT-MODEL, AUDIT-SCOPE (total 3163/2079), OPEN-QUESTIONS 21 and 23a (decided 2026-11-13: instant revoke of the current Market with revokedAt, cap default 250 with timelocked increases, 48-hour repoint delay, pool as the only limit, 180-day deadline, fail-closed holds with a timelocked ignore flag; 2:01 PM decisions confirmed by George directly; 2:51 PM: L-5 hold clock and the 10M lifetime ceiling).
  • VERSIONED-REDEPLOY-RUNBOOK: repoint steps; revoke procedure (cancel flagged awards first, then revoke, release reservations, Safe voids unmatured awards); fail-closed holds and the ignore-holds procedure (re-place holds first, schedule, check, execute, cancel or expiry, instant honourHolds); cap increase timelock; monitoring of the new events; the Safe runs voidAwards on a revoked Market's unmatured awards right after the revoke; the keeper calls pokeHold on Market hold events and at each until.
  • Merged feat/circuit-breaker (e04d98e) in, with no force push.
  • Note: the deployed Sepolia BuilderBonus (0x229a…) has an immutable market and the old ABI, so Sepolia needs a fresh BuilderBonus and a deploy PR after this merges.
Stacked on #15 (base `feat/circuit-breaker`). Decided 2026-11-13: BuilderBonus must be able to move to a new Market when the Market is redeployed, before launch. No deployment in this PR. ## Design: repoint in place (chosen) vs a new BuilderBonus per Market - **Chosen: a mutable `market` changed by a Safe-only timelocked repoint.** All program state stays in one contract: per-period builder and customer counts, cancel bars (`barredUntil`), exclusions, `minBounty`, `reservedCount`, `awarded`, `totalOwed` and the TSKR budget. A repoint changes only the pointer, so it can't reset any cap or bar. - **Rejected: a new BuilderBonus per Market.** Mappings can't be copied on-chain, so per-period counts, bars and exclusions would start empty (caps reset), the old program's `returnExcess` would strand the budget for unused slots. Any copy or offset scheme adds a privileged one-off import path, which is a larger surface than a pointer change. - **Slots are keyed by (Market, jobId)** (`slots[market][jobId]`). Job ids restart on every Market, so this avoids collisions. `reserve(jobId)` only takes jobs from the current Market; `finalize`, `withdraw`, `expire` and `cancelAward` take the slot's Market, so slots reserved before a repoint settle against the Market that reserved them. Honest in-flight bonuses are kept and a job can't be counted twice. ## Repoint - `scheduleRepoint(newMarket)`: owner only; the target must be a contract that answers `jobCount()` with one word and must differ from the current Market; one pending repoint at a time (an expired one doesn't block). Emits `RepointScheduled(from, to, eta)`. - `executeRepoint()`: owner only, from `eta` (`REPOINT_DELAY` = 48 hours) until `eta + REPOINT_WINDOW` (7 days), then `RepointExpired`. Re-checks the target. Emits `MarketRepointed(from, to)`. - `cancelRepoint()`: owner only, any time while one is scheduled. Emits `RepointCancelled(to)`. - The constructor applies the same target check and emits `MarketRepointed(0, market)`. - Unchanged: 2,000 TSKR per bonus, 10 per builder and 3 per customer per period, the 14-day Safe-cancellable claim delay, `MIN_FEE_BPS` 200, the 1,000 USDC `minBounty`, and the 2-period bar on both parties after a cancel. - The target check stops an EOA, a Safe or a wrong token address, not a hostile contract. The per-address caps do not bind a hostile target, because it can name fresh addresses for every job. The next section covers what bounds it and how to recover. ## Budget: funded pool plus a 10M lifetime ceiling (DECIDED 2026-11-13) - The fixed 5,000 count and the global slot counter are gone. - Lifetime ceiling (George, 2:51 PM CT): `MAX_TOTAL` = 10M TSKR, with `totalPaid` and `lifetimeCommitted() = totalPaid + committed()`. - `reserve` reverts `LifetimeCapReached` if the new earmark would take it above the ceiling. - It counts from reservation and award, so `finalize` never hits it. - A withdrawal moves TSKR from owed to paid without freeing headroom. - A cancel, void, expiry or release frees exactly its 2,000: that TSKR returns to the pool unpaid, and the slot can never pay. - So TSKR ever paid out can't exceed 10M. - Each reservation earmarks its 2,000 TSKR: `reservedCount`, `committed() = totalOwed + reservedCount * BONUS`, `available() = balance - committed` (floored at 0). - `reserve` requires `available() >= BONUS` (`NotFunded`), so a reserved job's `finalize` never fails for lack of funds. - Releases, voids, cancels and expiries all return their TSKR to the pool. A cancel keeps both parties' period counts used and bars both for 2 periods. - `returnExcess` sends only `available()`, and only to the allocation vault. - No carry-over of unused per-period allowance. ## Claim deadline and expiry - The unlock step and the `claimable` aggregate are removed. `withdraw(market, jobIds)`: builder only (`NotBuilder`), all or nothing, per award. - Each award can be claimed from `claimableAt` until `claimableAt + 180 days` plus the builder's observed held time (exclusive). Before that window: `TooEarly`. - **Batch skipping:** `withdraw` skips ids that can never pay, and reverts `NothingToWithdraw` if nothing is paid. Skipped ids: - claimed, expired, cancelled, voided or released ids - ids past the deadline - ids not matured at their Market's revocation - **Still reverts the whole call:** - `NotBuilder` (someone else's id, or an unknown one) - `BadStatus` (a reservation only) - `TooEarly` - any hold (`AccountHeld` / `HoldCheckFailed`), so a hold always blocks every payout. - So an `expire` front-run can't fail a builder's batch, and a duplicate id is paid once. - `expire(market, jobIds)`: anyone can call it. It skips ids that can't expire yet. It sets `Expired`, takes `BONUS` off `totalOwed` and emits `BonusExpired`. Period counts stay used and nobody is barred. - Expiry is exact per award, and awards nobody touched expire too, because there is no unlock step. `claimWindow(market, jobId)` returns (start, deadline). - **Held builders (L-5; George, 2:51 PM CT):** - `expire` runs the same fail-closed hold check for the award's builder (held, revert or garbage on any Market not ignored) and skips the id, so a held builder's award is never expired. - A per-builder hold clock (`holdClock`) is driven by the permissionless `pokeHold(builder)`; `expire` and `withdraw` drive it too. It starts when a hold is first observed (`HoldObserved`) and stops when the hold is observed cleared (`HoldCleared(builder, heldFor)`). - The held seconds extend the deadline of the builder's outstanding awards. `heldBaseline` stores the credit at award time, so holds before an award don't count. - A hold nobody observed while it lasted isn't credited, but one still in place at the deadline always blocks expiry. Keepers poke on Market `HoldPlaced` / `HoldRenewed` / `HoldLifted` and at each `until`. - Gas: one `isHeld` call (at most 50,000) per Market ever current, per due id, and per id of a builder whose clock is running. The `InsufficientGas` guard applies. ## Hostile or stuck Market: revocation (M-1, L-3, L-4) - **`revokeMarket(m)`** (owner only, final, instant). It works on any Market that was ever current, including the current one, and records `revokedAt`. After it: - `reserve` reverts `RevokedMarket()` if `m` is current. - Awards with `claimableAt <= revokedAt` still pay until their 180-day deadline. - Unmatured awards (`claimableAt > revokedAt`) can't be withdrawn (`RevokedMarket`). **Only the Safe** can void them, with `voidAwards(m, ids)`, which skips other ids. - Anyone can free reserved, never-awarded slots with `finalize(m, id)` (voids without calling `m`) or `releaseSlots(m, ids)` (Reserved slots only, other ids skipped). - Voiding returns the TSKR to the pool, restores the named builder's and customer's period counts and bars nobody (the Market may have named real people). It emits `SlotVoided`. - A revoked Market can't be scheduled again. - **`cancelAwards(m, ids, reason)`**: owner-only batch cancel with the 2-period bars. An empty reason reverts; ids that aren't pending awards inside the 14 days are skipped, not reverted. The runbook has the Safe cancel flagged awards before revoking. ## Per-Market period cap (timelocked increases) - `marketPeriodCap` defaults to 250 reservations and 250 awards per Market per 30-day period. It can be set from 1 to 5,000 (`MAX_MARKET_PERIOD_CAP`). - `setMarketPeriodCap(cap)`: - A decrease applies at once and cancels any pending increase (`MarketPeriodCapIncreaseCancelled`). - An increase is scheduled (`pendingCap`, `pendingCapEta`, `MarketPeriodCapIncreaseScheduled`). - The same value reverts `BadCap`. - `executeMarketPeriodCap()` runs from 48 hours after scheduling until 7 days after that (`TooEarly` / `RepointExpired`). `cancelMarketPeriodCap()` cancels a pending increase. A new schedule replaces the old one and restarts the delay. - A finalize over the cap reverts `MarketPeriodCapReached`; it can be retried next period. ## Withdraw hold checks: fail closed (L-1, L-2) - `withdraw` calls `isHeld` (50,000 gas each) on every Market that was ever current, **revoked or not**. - `true` reverts `AccountHeld(account)`. - A revert, out-of-gas, empty or malformed answer reverts `HoldCheckFailed(market)`. The skip-and-event behaviour is removed. - The `InsufficientGas()` guard is kept, so the caller must forward enough gas for each check. - Holds on the previous Market keep applying after a repoint (L-1). - **Per-Market ignore flag (Safe only):** - `scheduleIgnoreHolds(m)` (`IgnoreHoldsScheduled(m, eta)`), then `executeIgnoreHolds(m)` from 48 hours to 7 days after (`HoldsIgnoredSet(m, true)`). - `cancelIgnoreHolds(m)` (`IgnoreHoldsCancelled`). An unexecuted schedule expires. - `honourHolds(m)` clears the flag and any pending schedule at once (`HoldsIgnoredSet(m, false)`). - The runbook says to re-place real holds on the current Market before ignoring an old one. ## ABI changes (BuilderBonus, vs `main`) - Repoint functions: `scheduleRepoint(address)` `0x36f3b04c`, `executeRepoint()` `0x89c8f6d0`, `cancelRepoint()` `0x196cfe2a`, `pendingMarket()` `0xe70f15eb`, `pendingMarketEta()` `0xe47c081a`, `REPOINT_DELAY()` `0xe3e6e243`, `REPOINT_WINDOW()` `0x7384dc06`. `market()` is now a storage variable. - Changed signatures (Market first): `finalize(address,uint256)` `0x0553e156`, `cancelAward(address,uint256,string)` `0x67cec78d`, `slots(address,uint256)` `0xb5f95d9b`, `qualifies(address,uint256,Job)` `0xb73e4204`. `reserve(uint256)` is unchanged. - Pool and expiry: - `withdraw(address,uint256[])` `0x8293744b` and `expire(address,uint256[])` `0x6fee75aa` - views `claimWindow(address,uint256)` `0x027e5c46`, `committed()` `0x9b6b9664`, `available()` `0x48a0d754`, `reservedCount()` `0xc38f7617`, `CLAIM_WINDOW()` `0x9f34fc80` - Revocation, cap and holds: - `revokeMarket(address)` `0x29527b82`, `releaseSlots(address,uint256[])` `0xc178e524`, `voidAwards(address,uint256[])` `0x3f96408c`, `cancelAwards(address,uint256[],string)` `0x919e49e0` - cap: `setMarketPeriodCap(uint256)` `0x92f5bf77`, `executeMarketPeriodCap()` `0xc3a8db8a`, `cancelMarketPeriodCap()` `0x37a53dac`, `pendingCap()` `0x200ad79c`, `pendingCapEta()` `0x65621dc5` - hold flag: `scheduleIgnoreHolds(address)` `0x7bc6be3b`, `executeIgnoreHolds(address)` `0x79f651a8`, `cancelIgnoreHolds(address)` `0x54df62c5`, `honourHolds(address)` `0x498f0368` - other views: `marketPeriodCap()` `0xf431f3ad`, `marketPeriod(address,uint256)` `0x6db3fb58`, `marketState(address)` `0xa7a9a62c` (known, revoked, holdsIgnored, revokedAt, ignoreHoldsEta), `markets(uint256)` `0xb1283e77`, `marketsLength()` `0xa5402544`, `DEFAULT_MARKET_PERIOD_CAP()` `0x3cd5bc0b`, `MAX_MARKET_PERIOD_CAP()` `0xe7206f84`, `HOLD_CHECK_GAS()` `0xb7b9e33e` - Removed: error `ClaimExpired()` (past-deadline ids are skipped now), `withdraw()` `0x3ccfd60b`, `unlock(address,uint256)` `0x7eee288d`, `claimable(address)` `0x402914f5`, `slotsUsed()` `0xbee2d1cf`, `MAX_BONUSES()` `0x88023256`; event `BonusUnlocked` and error `CapReached()`. - Events (topic0): - `SlotReserved(uint256 indexed jobId, address indexed builder, uint256 indexed period, uint256 reservedCount, address market)` `0x1911f691a9a4766962588fb14bcce650bae92d9a25a8869cc824064f6d3b26e9`. Its 4th field is now the earmarked reservation count, not slots used. - `BonusAwarded(... address indexed market, uint256 amount, uint256 awarded, uint64 claimableAt)` `0x01021a989f04d43e7cd1eb76cb40037dafc4d84d7d7b6d4c0b8dff11e2466a90` - `BonusCancelled(...)` `0xd4d838bf34f94c61dad05f2d5d83a2ebc6a2c6c979f23a736d958708f462ceb9` - `SlotReleased(...)` `0x83e3981d6ea372aa363d0ca739f3831b5c7eaa1da23df45f0b8c0b9c401c1b57` - New: - `BonusClaimed(uint256 indexed jobId, address indexed builder, address indexed market, uint256 amount)` `0xf957dcd5d8e121c35d1be9e62b9e9b9a01e2bd4088b0358745836a2809f5d62f` - `BonusExpired(...)` `0x9b40822509ce8549f5979de7f8d513461d9f2359335be1564578a5705d5705c4` - `RepointScheduled` `0xcf0d8c2cec18428c57ea056f7768ae93fa7d9950f767b54be022d23a9881d53a` - `RepointCancelled` `0x38583e2bc13a49188425acd641a802373dc0fdebd4120858b6a1b0bf8b8d1cd0` - `MarketRepointed` `0xdc87b3539265de7805d26cb20f770a3009bab8e3608eaeb3ac15feece65af3a8` - `MarketRevoked(address indexed)` `0x773e25ce1a503d1493ecf52f9b9b5cf4ae9ea2ba1dd06ffc052feac43ea0a013` - `SlotVoided` `0x1037a3de4085d54a686f9833ac1a984ff83733bdf76ee2d787e3929e23107035` - `MarketPeriodCapSet(uint256)` `0xa48057cfd44812b421bbf99e7074b1bbcafc74eef7304fe42a6ba8a0b805f436` - `MarketPeriodCapIncreaseScheduled(uint256,uint64)` `0x6f90721656d2d051a59a65530e146d70bcca3a54b88cf53ff347651d514c3015` - `MarketPeriodCapIncreaseCancelled(uint256)` `0xd03c3f65f7e4449b2da250aa5050b0434bfaef705e5e99c1d066c998769bebb5` - `IgnoreHoldsScheduled(address indexed,uint64)` `0x1a8bcb24cb2d40ea8cfdb6ce6d92ada3354241cf985d6c42d2ac81e882816d62` - `IgnoreHoldsCancelled(address indexed)` `0xf03c657948f07477e2f3661a9005813ee490542e7c0bdea36529f163778387e3` - `HoldsIgnoredSet(address indexed,bool)` `0xcb08c9fdfaf2cc058ac62ab8741e1ed89bc52b8758686a6ec718023eb79ea70d` - `HoldObserved(address indexed builder)` `0xcb725322f71f7b6df17f15b2b5aa08631d40ac673142b181ba455da4038c40ed` - `HoldCleared(address indexed builder, uint256 heldFor)` `0xf4b8699323f3ce580372a8fd4934bd4ce95db85feaf1cf53c7042cf82b616b04` - Removed since `bb06199`: event `HoldCheckFailed(address,address)` `0x2d8223d4…`. It is now an error, `HoldCheckFailed(address)` `0x66af4bf0`. - Lifetime ceiling and hold clock: `MAX_TOTAL()` `0xcd60fe35` (same selector as before, now the lifetime TSKR ceiling), `totalPaid()` `0xe7b0f666`, `lifetimeCommitted()` `0x183a5e82`, `pokeHold(address)` `0x300c0699`, `holdClock(address)` `0x73428ab3` (since, credit), `heldBaseline(address,uint256)` `0x9771078c`; error `LifetimeCapReached()` `0x5537755e`. - New errors: `BadMarket()`, `RepointPending()`, `NoRepoint()`, `RepointExpired()`, `RevokedMarket()`, `MarketPeriodCapReached()`, `BadCap()`, `InsufficientGas()`, `NotBuilder()`, `NotPending()`, `HoldCheckFailed(address)`. - `abis/arbitrum-sepolia` is not changed: it describes the deployed contracts. ## Tests - `test/BonusRepoint.t.sol` (18): schedule/execute/cancel/expiry with boundaries, access, target checks, carry-over of counts, bars, exclusions and budget, old-Market slots settle in place, and a hostile Market bounded by the caps and the pool. - `test/BonusRevoke.t.sol` (20): - Hostile Market end to end: the cap binds; strangers can release reservations but can't void awards (`voidAwards` reverts for non-owners); the Safe voids the unmatured ones; nobody is barred. - Revocation timing: an award that matures exactly at `revokedAt` still pays and still expires; an unmatured one can't be withdrawn. - `finalize` voids on a revoked Market; a stuck Market's reservations can be released permissionlessly; `cancelAwards` skips mixed ids (matured, withdrawn, cancelled, reserved, unknown). - Holds: a reverting, garbage, OOG or empty hold check blocks `withdraw`, also after revoke; a revoked Market's real hold blocks. - Ignore flag: works only after 48 hours, inside the window and only for the owner, then unblocks; it can be cancelled and expires; `honourHolds` is instant. - Cap: the increase delay, window, cancel and expiry; an instant decrease drops a pending increase. - Also the gas guard and L-1. - New `test/BonusPool.t.sol` (18): - The pool exhausts and refills via cancel, release, void and expiry; earmarked reservations always award. - There is no count cap (a 5,001st award). - Deadline boundaries; expiry of untouched awards, batch expiry, and expiry after repoint and revoke; the deadline keeps running under a hold. - Per-award all-or-nothing withdraw, no carry-over, and a hostile Market bounded by the cap and the pool. - Updated `test/BuilderBonus.t.sol` and `test/invariant/BonusInvariant.t.sol` (accounting: withdrawn + expired + owed == awarded; runs start at 4,990 awarded to cross the former 5,000). - New `test/BonusLifetime.t.sol` (14): - L-5: a held builder at the deadline isn't expired, also when nobody poked before; the remaining window is restored by the held time (exact boundaries); withdraw closes a cleared hold; credit counts only after the award; unobserved holds aren't credited; a broken Market's answer counts as held until the ignore flag excludes it; `expire` needs gas. - `MAX_TOTAL`: paid, owed and earmarked count toward it; a withdrawal frees nothing; cancel, void, expiry and release free headroom. - The remaining revert branches. - Withdraw skipping (`test/BonusPool.t.sol`, `test/BonusRevoke.t.sol`): expired, swept-ahead, claimed, cancelled, released, past-deadline and duplicate ids are skipped; `NotBuilder`, unknown, reserved, `TooEarly` and holds still revert; on a revoked Market an unmatured id is skipped while the matured one pays. - The invariant suite adds `invariant_LifetimeCap`. - Full `forge test` with the fork RPC set: **342 passed, 0 failed, 0 skipped**. - `forge coverage --ir-minimum` on BuilderBonus: **100% branches (83/83)**, 100% functions, 99.3% statements and 99.0% lines. The 3 lines reported as unhit are mapping artifacts of `--ir-minimum`; the tests exercise them: the instant cap decrease, `cancelMarketPeriodCap`, and withdraw closing a cleared hold clock. ## Size BuilderBonus runtime is 14,479 B (10,097 B under the limit). TaskulerMarket is unchanged at 24,146 B (430 B margin). ## Docs - README, SECURITY-NOTES, KNOWN-ISSUES KI-14, THREAT-MODEL, AUDIT-SCOPE (total 3163/2079), OPEN-QUESTIONS 21 and 23a (decided 2026-11-13: instant revoke of the current Market with `revokedAt`, cap default 250 with timelocked increases, 48-hour repoint delay, pool as the only limit, 180-day deadline, fail-closed holds with a timelocked ignore flag; 2:01 PM decisions confirmed by George directly; 2:51 PM: L-5 hold clock and the 10M lifetime ceiling). - VERSIONED-REDEPLOY-RUNBOOK: repoint steps; revoke procedure (cancel flagged awards first, then revoke, release reservations, Safe voids unmatured awards); fail-closed holds and the ignore-holds procedure (re-place holds first, schedule, check, execute, cancel or expiry, instant `honourHolds`); cap increase timelock; monitoring of the new events; the Safe runs `voidAwards` on a revoked Market's unmatured awards right after the revoke; the keeper calls `pokeHold` on Market hold events and at each `until`. - Merged `feat/circuit-breaker` (e04d98e) in, with no force push. - Note: the deployed Sepolia BuilderBonus (0x229a…) has an immutable `market` and the old ABI, so Sepolia needs a fresh BuilderBonus and a deploy PR after this merges.
- Remove the fixed bonus count; the funded pool is the only total limit. Reservations
  earmark their bonus (reservedCount, committed(), available()); returnExcess sends only
  the uncommitted pool.
- Per-award withdraw(market, jobIds) inside [claimableAt, claimableAt + 180 days);
  permissionless expire(market, jobIds) returns unclaimed awards to the pool.
- revokeMarket records revokedAt. Awards matured by then still pay; the Safe voids
  unmatured awards with voidAwards; releaseSlots frees reservations only; cancelAwards
  skips ids that are not cancellable.
- Hold checks fail closed on every Market ever current. A timelocked per-Market flag
  (48 hours, 7-day window, cancellable) lets the Safe ignore a Market's answers; clearing
  it is immediate.
- marketPeriodCap increases are timelocked (48 hours, 7-day window); decreases are
  immediate and drop a pending increase. No carry-over of unused allowance.
- Tests (new BonusPool suite, revoke/hold/cap cases) and docs.
- MAX_TOTAL (10M TSKR) caps TSKR paid, owed and earmarked (totalPaid,
  lifetimeCommitted()); reserve reverts LifetimeCapReached above it. Undone awards
  free their headroom since their TSKR returns to the pool unpaid.
- expire applies the fail-closed hold check to the award's builder and skips held
  builders. A per-builder hold clock (pokeHold, also driven by expire and withdraw)
  adds observed held time to the builder's claim deadlines.
- withdraw skips ids that can never pay (settled, past the deadline, unmatured on a
  revoked Market) and reverts only if nothing is paid; NotBuilder, BadStatus for a
  reservation, TooEarly and holds still revert the whole call.
- Tests for the above and the remaining revert branches; docs and runbook updates.
george approved these changes 2026-11-13 22:07:04 +00:00
Taskuler-bot changed target branch from feat/circuit-breaker to main 2026-11-13 22:08:55 +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!16
No description provided.