Repository navigation
feat(contracts): enforce + govern the capacity-bond curve on-chain (#770) - #774
Conversation
) Implements the ADR 026 § Capacity-bond curve coupling `activeBond ≥ bond_required(Mbps) = k × Mbps^α` on-chain, closing the design-vs-implementation gap in #770 where k/α were documented as governance-tunable but were neither stored, enforced, nor settable (bond(amount) accepted any amount > 0). - BondMath.bondRequired(mbps, k, αWad): fixed-point k × Mbps^α via solady FixedPointMathLib.powWad, as a public (linked-library) function so the pow math stays out of CapacityBond's runtime size. - CapacityBond: kConstant/alphaWad storage (defaults 12.6e18 / 1.2e18), bondRequired(mbps) view, enforcement at declareMbps / requestUnbond / registerNode (slash paths intentionally exempt — auto-eject below minBond/2 handles under-curve operators), and setK / setAlpha (GOVERNANCE_ROLE) with α ∈ [1.0, 1.8] and the 1 Gbps-tier bond bounded to [10K, 200K TOKEN] against the live α. - EIP-170: the curve surface pushed CapacityBond past 24,576 B, so the slash-escrow finality state machine (mint, finalize / markAppealOpen / settleUpheld / settleGranted, and the multi-slash zero-out recompute) moved into a linked SlashEscrowLib operating on storage refs; CapacityBond keeps the thin role-gated/reentrancy/pause wrappers and owns the value-typed escrowedTotal/slashCounter. CapacityBond is now 24,230 B (346 B margin, up from 110 B baseline); behavior is unchanged (full SlashAppeal + CapacityBond suites green). - ADR 026 / 016 record the shipped enforcement + governance; ADR 016 gains the DecdnGovernor self-setter row (setVoteCapBps / setAgeRampMonths) and corrects the age_ramp_months attribution (DecdnGovernor, not CapacityBond). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 26784945803 |
Contracts coverageLine coverage: 87.76% (1735/1977 lines) |
Slash-escrow finality + mint now run via DELEGATECALL into the linked SlashEscrowLib, and the curve enforcement adds new gas paths; refresh the committed baseline so the CI gas-diff comment reflects the new surface. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements the on-chain capacity-bond curve coupling (activeBond ≥ k × Mbps^α) and introduces governance setters (setK and setAlpha) to tune the curve coefficients on-chain. To keep the CapacityBond contract under the EIP-170 size ceiling, the slash escrow lifecycle state machine and its associated types have been refactored and extracted into a new library, SlashEscrowLib. Additionally, BondMath has been updated to evaluate the curve using Solady's FixedPointMathLib. There are no review comments to evaluate, so I have no feedback to provide.
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 the previously ADR-documented capacity-bond curve (bond_required(Mbps) = k × Mbps^α) as an on-chain, governance-tunable, and enforced invariant in CapacityBond, while refactoring slash-escrow finality logic into a linked library to stay under the EIP-170 runtime-size limit.
Changes:
- Add on-chain curve evaluation (
BondMath.bondRequired) and enforceactiveBond ≥ bondRequired(declaredMbps)atdeclareMbps,requestUnbond, andregisterNode, with governance setterssetK/setAlphaplus bounds. - Extract the slash escrow finality / settlement state machine into
SlashEscrowLib(linked DELEGATECALL library) and update tests to use the movedSlashStatus/SlashRecordtypes. - Wire in
solady(remappings, slither config, lockfile, submodule) and update ADR docs to reflect shipped enforcement + governance.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| contracts/src/CapacityBond.sol | Adds curve params + enforcement, governance setters/bounds, and delegates slash-escrow finality logic to SlashEscrowLib to reduce bytecode size. |
| contracts/src/BondMath.sol | Adds fixed-point curve evaluation using Solady FixedPointMathLib.powWad and keeps the curve math in a linked library. |
| contracts/src/SlashEscrowLib.sol | New linked library holding slash escrow finality lifecycle, events, and multi-slash watermark recompute. |
| contracts/test/CapacityBond.t.sol | Adds curve tests and updates slash-record expectations to use SlashEscrowLib types. |
| contracts/test/SlashAppeal.t.sol | Updates enum/type references to SlashStatus moved into SlashEscrowLib. |
| contracts/slither.config.json | Adds Solady remapping for Slither analysis. |
| contracts/remappings.txt | Adds Solady remapping for Foundry builds. |
| contracts/foundry.lock | Pins Solady (and records crypto-lib revision) for reproducible dependency resolution. |
| .gitmodules | Adds Solady as a git submodule under contracts/lib/solady. |
| adr/026-tokenomics.md | Documents shipped on-chain enforcement and governance of the bond curve. |
| adr/016-contract-interactions.md | Updates contract interaction tables to reflect on-chain tunable curve and Governor self-setters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
review) bond() adds to activeBond, so the prior helper that always bonded the full bondRequired(mbps) would overshoot if called after a prior bond, weakening "exactly at curve" boundary assertions. Bond only max(0, need - activeBond) and top the operator up only for that deficit. Behavior-identical for the current callers (all start at activeBond == 0); 85 CapacityBond tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…+ test gaps) Review follow-ups from the multi-agent PR review. No behavior change to the shipped curve/slash logic; all 459 tests green. - EPOCH_LENGTH drift (flagged by 3 reviewers): SlashEscrowLib no longer duplicates the 7-day epoch constant — settleGranted / _recomputeSlashedAtEpoch take it as a param threaded from CapacityBond.EPOCH_LENGTH (the same source _stampSlash stamps with), so the multi-slash zero-out watermark can never diverge from the stamp. - ADR 016: the bond() / declareMbps / requestUnbond Guards rows said the curve coupling "is not enforced" / omitted it — now describe the shipped BondBelowCurve enforcement; replaced three stale `clearSlashedAtEpoch` references (no such function) with the relocated multi-slash watermark recompute. - CapacityBond: the registerNode comment cited issue #681 (CLOSED/COMPLETED, and about the minCapacityMbps band floor, not this gap) — inlined the actual residual note (registerNode does not require a prior declareMbps). - Tests (+3, plus rollback assertions): registerNode success-at-curve happy path (the gate's success side was uncovered); fuzz monotonicity over the full declarable band; requestUnbond down to exactly the curve (inclusive boundary); and assert setK / setAlpha leave storage unchanged after an out-of-range revert (locks the store-then-validate rollback invariant). Declined (single trusted caller; current idioms correct; issue specified separate setK/setAlpha): value-in/out escrowedTotal signature change, mint slashCounter cross-check, atomic setCurve / packed-struct, and in-function bondRequired bound asserts. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…review) The setK/setAlpha NatSpec warns that a valid (k, α) end-state can be unreachable in the wrong order, because each setter validates the 1 Gbps tier against the live other coefficient. That documented behavioral contract had no coverage. test_setKAlpha_orderingMatters demonstrates both legs for the target (k=180, α=1.0): k-first reverts at the (k=180, α=1.2) intermediate (~716K TOKEN > 200K ceiling), while α-first reaches the same pair with every step in range. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #770 (Option A — implement + make governable on-chain).
Problem
bond_required(Mbps) = k × Mbps^αwas documented as a governance-tunable economic mechanism (ADR 026 § Capacity-bond curve; rootCLAUDE.md"governance-tunable from day one"), but the shippedCapacityBondaccepted anyamount > 0— nok/αstorage, nobondRequiredview, no setters, and no enforcement. An operator could declare a 100 Gbps tier while bonding the 10 Mbps floor, defeating the anti-concentration pressure α is meant to provide. ADR 016 had already drifted to "not on-chain-tunable in this revision," contradicting ADR 026.What this does
BondMath.bondRequired(mbps, k, αWad)— fixed-pointk × Mbps^αviasoladyFixedPointMathLib.powWad. Implemented as apublic(linked-library) function so thepowmath compiles intoBondMath's deployed bytecode, notCapacityBond's.CapacityBond—kConstant/alphaWadstorage (defaults12.6e18/1.2e18), abondRequired(mbps)view, and enforcement ofactiveBond ≥ bondRequired(declaredMbps)at the three operator-initiated sites:declareMbps,requestUnbond,registerNode. Slash paths are intentionally exempt (a penalized operator may fall under the curve and is auto-ejected belowminBond/2).setK/setAlpha(GOVERNANCE_ROLE): α hard-bounded to[1.0, 1.8];kbounded so the resulting 1 Gbps-tier bond stays within[10K, 200K TOKEN]against the live α (the ADR's "bounded by 1G tier" semantic). EmitsKUpdated/AlphaUpdated.EIP-170 headroom
The curve surface pushed
CapacityBondfrom 24,466 B to 25,521 B — 945 B over the 24,576 limit (only 110 B of baseline margin).via_iris a hard blocker here (crypto-lib's Ed25519 assembly hits Yul "stack too deep"), so per the approved plan the slash-escrow finality state machine (mint,finalizeUnappealed/markAppealOpen/settleUpheld/settleGranted, and the multi-slash zero-out recompute) was extracted into a new linkedSlashEscrowLiboperating onstorage-ref args.CapacityBondkeeps the thin role-gated / reentrancy / pause wrappers and owns the value-typedescrowedTotal/slashCounter. TheSlashStatus/SlashRecordtypes moved to file scope inSlashEscrowLib.Result:
CapacityBondis 24,230 B — 346 B margin (more than the 110 B baseline). Behavior is unchanged: the fullSlashAppeal(19) andCapacityBond(85) suites are green.Docs
setK/setAlphagovernance and bounds.setK/setAlphato theGOVERNANCE_ROLEtable; added the DecdnGovernor self-setter row (setVoteCapBps/setAgeRampMonths) requested in CapacityBond bond-curve (bond = k × Mbps^α) is unenforced and ungovernable on-chain — decide enforce-vs-document #770's adjacent cleanup; corrected theage_ramp_monthsattribution (DecdnGovernor, not CapacityBond).CLAUDE.md"governance-tunable from day one" needs no change — it is now literally true.Tests
16 new curve tests (ADR worked examples within ±2% — e.g.
bondRequired(1000) ≈ 50,161 TOKEN; monotonicity; enforcement reverts at all three sites; slash-exemption;setK/setAlpharole/bounds/events; 1 Gbps-tier coupled bound). ExistingdeclareMbpstests migrated to bond above the curve first. 456 tests pass.Verification
Notes / non-goals
solady(pinned submodulev0.1.26), excluded from slither/aderyn/forge-lint scope like the otherlib/deps.declareMbps/requestUnbond/registerNode; already-registered under-bonded operators are not force-corrected (acceptable pre-launch).registerNode(declaredMbps > 0) remains out of scope — tracked in Minimum declared capacity floor forCapacityBond.register#681.🤖 Generated with Claude Code