Repository navigation
feat(contracts): terms-hash acceptance at registration + governor-swappable currentTermsHash (#1076) - #1078
Conversation
…ppable currentTermsHash (#1076) Ships the on-chain half of ADR 019 § Terms Acceptance, previously only specified ("pre-extension surface"). `CapacityBond.registerNode` now carries a `termsHash` the operator accepts; it must equal the governance-canonical `currentTermsHash`, is covered by the binding signature over a distinct `RegisterNode(nodeId,nonce,termsHash)` typehash, and emits `TermsAccepted(nodeId, termsHash, timestamp)`. - `currentTermsHash` is set at genesis (constructor) and swapped post-deploy via `setCurrentTermsHash` under GOVERNANCE_ROLE — no `[floor, ceiling]` rail since a hash has no monotonic direction (ADR 019 §243). - Enforcement is registration-only: `bindNodeId` (key rotation) keeps the unchanged `BindNodeId` payload and never re-accepts terms. The distinct typehash blocks replaying a registration signature as a bare rebind; the shared `bindingNonce` preserves cross-path replay protection. - Deploy config threads `currentTermsHash` (env `CURRENT_TERMS_HASH`, default 0). - ADR 003 § NodeId Binding documents the `RegisterNode` struct; ADR 019 drops the pre-extension caveat and names the setter. CLI display + acceptance flow is the tracked follow-up (#1077). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contracts coverageLine coverage: 91.52% (2320/2535 lines) |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
Code Review
This pull request implements operator terms acceptance during node registration as specified in ADR 019. It introduces a new RegisterNode EIP-712 typed structured data format that includes a termsHash parameter, which must match the governance-canonical currentTermsHash stored in the CapacityBond contract. The registerNode function has been updated to validate this hash and signature, emitting a TermsAccepted event upon success. Additionally, a governance-restricted setCurrentTermsHash function has been added to allow updating the canonical terms hash. Deployment scripts and test suites have been updated accordingly to support and verify this new workflow. 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
This PR implements ADR 019’s on-chain “operator terms acceptance” mechanism by extending CapacityBond.registerNode to require/verify a termsHash that matches a governance-canonical currentTermsHash, recording acceptance on-chain and allowing governance to update the canonical hash over time.
Changes:
- Added
currentTermsHash,REGISTER_NODE_TYPEHASH,TermsAccepted, and a governance-gatedsetCurrentTermsHashtoCapacityBond, and updatedregisterNodeto enforce and signature-bindtermsHash. - Threaded
currentTermsHashthrough protocol deployment configuration/wiring. - Updated ADR 019 and ADR 003 to reflect the shipped
RegisterNodetyped struct and registration-only enforcement; updated tests accordingly.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| contracts/src/CapacityBond.sol | Enforces terms-hash at registration via new EIP-712 payload; adds governance-swappable currentTermsHash and acceptance/event surface. |
| contracts/script/BaseProtocolDeploy.s.sol | Extends deploy config and constructor wiring to pass currentTermsHash into CapacityBond. |
| contracts/script/DeployProtocol.s.sol | Reads CURRENT_TERMS_HASH into deployment config for genesis initialization. |
| contracts/test/CapacityBond.t.sol | Adds and updates tests covering terms-hash enforcement, signature binding, and governance updates. |
| contracts/test/CapacityBondRegionE2E.t.sol | Updates E2E region registration helpers/calls to use RegisterNode(..., termsHash). |
| contracts/test/E2EProtocol.t.sol | Updates registration signing helper and registerNode call site for new typehash + termsHash. |
| contracts/test/DeployProtocol.t.sol | Updates deploy fixture config to include currentTermsHash. |
| contracts/test/GovernanceLifecycle.t.sol | Threads currentTermsHash through governance lifecycle fixture config. |
| contracts/test/SlashAppeal.t.sol | Updates deploy config construction to include currentTermsHash. |
| contracts/test/CapacityBondSlashJudgeInvariant.t.sol | Updates deploy config construction to include currentTermsHash. |
| adr/019-node-onboarding.md | Removes “pre-extension” caveat and documents the shipped RegisterNode/currentTermsHash behavior. |
| adr/003-payments.md | Documents the two typed structs (RegisterNode vs BindNodeId) and registration-time-only terms enforcement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rough Rust ABI, refresh gas snapshot Addresses CI + review on #1078. Contract: - CapacityBond rejects the zero `currentTermsHash` sentinel in the constructor and `setCurrentTermsHash` (`ZeroTermsHash`), so genesis must commit to a real (possibly draft) terms version and governance can only swap to another non-zero one — no permissive terms-disabled bootstrap. Addresses Copilot review on the constructor/deploy zero-default. - DeployProtocol.s.sol now REQUIRES `CURRENT_TERMS_HASH` (no zero default); dev-deploy.sh + the anvil/e2e harnesses pass a non-zero placeholder. Rust ABI (the contract signature change reached the registration path): - bind_sig: add `RegisterNode(nodeId,nonce,termsHash)` typed struct + `register_node_signing_hash`, with a type-hash parity test vs the contract. `BindNodeId` / `binding_signing_hash` stay for ephemeral client bindings and key-rotation rebinds. - capacity_bond + e2e bindings: `registerNode` gains `termsHash`; add `currentTermsHash()` view. - register.rs + e2e chain fixtures read `currentTermsHash` on-chain, sign `RegisterNode`, and pass `termsHash`. Operator-facing terms display + explicit acknowledgement remains #1077. Also: regenerated the stale `.gas-snapshot`, and fixed a `BindNode` → `BindNodeId` doc typo in the test helper (Copilot review). Full anvil settlement e2e passes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThis PR adds registration-time termsHash acceptance to CapacityBond, introduces a governance-managed currentTermsHash, and updates deploy wiring, tests, Rust bindings, and CLI/e2e registration flows to use the new RegisterNode signature. ChangesTerms Acceptance Feature
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Update — CI fixes + review feedback (fc8f410)The initial commit changed the CI failures
Review (Copilot) — zero-default hardening
Operator-facing terms display + explicit acknowledgement remains scoped to #1077; this PR delivers the on-chain enforcement + ABI compatibility. Local CI-mirror: forge fmt/build |
Coverage reportTotal: 82.06% (was 82.11%, ▼ 0.05%) — 42388/51654 lines
History
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
adr/019-node-onboarding.md (1)
83-113: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winStep 2.3 call signature and atomic-actions list are now internally inconsistent.
Line 85 still shows
registerNode(nodeId, multiaddrs, regionHint, bindingSignature, ed25519Signature)(notermsHash), and the bullet at line 89 still describes verifyingBindNodeId(nodeId, bindingNonce[ethAddress]). Both contradict the newly added text at lines 104-109 (and the shipped call site inE2EProtocol.t.sol, which passestermsHashas a positional argument and signsRegisterNode).📝 Proposed fix to reconcile Step 2.3
-Call `CapacityBond.registerNode(nodeId, multiaddrs, regionHint, bindingSignature, ed25519Signature)`. +Call `CapacityBond.registerNode(nodeId, multiaddrs, regionHint, termsHash, bindingSignature, ed25519Signature)`. This single transaction atomically: -- Verifies the EIP-712 `bindingSignature` over `BindNodeId(nodeId, bindingNonce[ethAddress])`, establishing the `nodeId → ethAddress` mapping for slash evidence and payment attribution. +- Requires `termsHash == currentTermsHash` and verifies the EIP-712 `bindingSignature` over `RegisterNode(nodeId, bindingNonce[ethAddress], termsHash)`, establishing the `nodeId → ethAddress` mapping for slash evidence and payment attribution. - Verifies the `ed25519Signature` over `keccak256(abi.encodePacked(nodeId, ethAddress, chainId, registrationNonce[nodeId]))`, proving the operator controls the iroh private key (prevents NodeId squatting). (`ethAddress` is `msg.sender` and `chainId` is `block.chainid` on-chain; this ADR uses operator-perspective names for consistency with the signing pseudo-code below.) - Records `NodeInfo` (including `firstBondedAt` if this is the node's first-ever registration — used for cold-start bootstrap eligibility in [ADR 008](008-reputation.md#cold-start-bootstrap)). - Sets `active = true` in the registry. +- Emits `TermsAccepted(nodeId, termsHash, timestamp)`.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@adr/019-node-onboarding.md` around lines 83 - 113, Update Step 2.3 so the documented `CapacityBond.registerNode` call matches the actual `RegisterNode` flow used by `E2EProtocol.t.sol`: include `termsHash` in the signature and describe the binding step as signing `RegisterNode { nodeId, nonce, termsHash }` rather than `BindNodeId(...)`. Keep the atomic-actions list aligned with the real on-chain behavior in `registerNode` by noting that it verifies both `termsHash == currentTermsHash` and the EIP-712 binding signature, while preserving the `ed25519Signature` verification and `NodeInfo`/`active` updates.
🧹 Nitpick comments (1)
contracts/test/DeployProtocolScript.t.sol (1)
51-60: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd a
currentTermsHashassertion to the config round-trip test.
test_readConfig_appliesDefaultsForOptionalVarsasserts every otherDeployConfigfield but notcfg.currentTermsHash, even though this PR adds theCURRENT_TERMS_HASHenv var this test'ssetUp()now depends on. A wiring regression on this field would go unnoticed here.✅ Proposed addition
assertEq(cfg.regionStabilityWindow, DEFAULT_REGION_STABILITY_WINDOW, "regionStability"); + assertEq(cfg.currentTermsHash, TEST_TERMS_HASH, "currentTermsHash");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/test/DeployProtocolScript.t.sol` around lines 51 - 60, The config round-trip test is missing coverage for the new CURRENT_TERMS_HASH wiring, so a regression in DeployConfig.currentTermsHash could slip through. Update test_readConfig_appliesDefaultsForOptionalVars in DeployProtocolScript.t.sol to assert that cfg.currentTermsHash matches the expected TEST_TERMS_HASH alongside the other DeployConfig fields, using the existing readConfig/deploy config assertions as the place to add it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@adr/019-node-onboarding.md`:
- Around line 83-113: Update Step 2.3 so the documented
`CapacityBond.registerNode` call matches the actual `RegisterNode` flow used by
`E2EProtocol.t.sol`: include `termsHash` in the signature and describe the
binding step as signing `RegisterNode { nodeId, nonce, termsHash }` rather than
`BindNodeId(...)`. Keep the atomic-actions list aligned with the real on-chain
behavior in `registerNode` by noting that it verifies both `termsHash ==
currentTermsHash` and the EIP-712 binding signature, while preserving the
`ed25519Signature` verification and `NodeInfo`/`active` updates.
---
Nitpick comments:
In `@contracts/test/DeployProtocolScript.t.sol`:
- Around line 51-60: The config round-trip test is missing coverage for the new
CURRENT_TERMS_HASH wiring, so a regression in DeployConfig.currentTermsHash
could slip through. Update test_readConfig_appliesDefaultsForOptionalVars in
DeployProtocolScript.t.sol to assert that cfg.currentTermsHash matches the
expected TEST_TERMS_HASH alongside the other DeployConfig fields, using the
existing readConfig/deploy config assertions as the place to add it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1f67bd62-1d67-463b-875e-885eacc54efe
📒 Files selected for processing (22)
adr/003-payments.mdadr/019-node-onboarding.mdcontracts/.gas-snapshotcontracts/dev-deploy.shcontracts/script/BaseProtocolDeploy.s.solcontracts/script/DeployProtocol.s.solcontracts/src/CapacityBond.solcontracts/test/CapacityBond.t.solcontracts/test/CapacityBondRegionE2E.t.solcontracts/test/CapacityBondSlashJudgeInvariant.t.solcontracts/test/DeployProtocol.t.solcontracts/test/DeployProtocolScript.t.solcontracts/test/E2EProtocol.t.solcontracts/test/GovernanceLifecycle.t.solcontracts/test/SlashAppeal.t.solcrates/cli/src/commands/register.rscrates/e2e/src/bindings.rscrates/e2e/src/chain.rscrates/incentive/src/bind_sig.rscrates/incentive/src/capacity_bond.rscrates/incentive/src/lib.rscrates/node/tests/anvil_settlement_e2e.rs
…t currentTermsHash wiring CodeRabbit review on #1078: - ADR 019 Step 2.3 still showed the pre-extension `registerNode(...)` call and a `BindNodeId` binding bullet; update to the shipped `RegisterNode` signature (termsHash arg + termsHash==currentTermsHash requirement + TermsAccepted emit). - DeployProtocolScriptTest: assert `cfg.currentTermsHash == TEST_TERMS_HASH` in the config round-trip so a wiring regression on the new field is caught. Regenerated .gas-snapshot for the added assertion. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks @coderabbitai — both addressed in dc65040:
🤖 Addressed by Claude Code |
|
Tip For best results, initiate chat on the files or code changes.
Nice work tightening this up. (=^・ω・^=) |
#1079) * feat(cli): operator terms display + acceptance at registration (#1077) Implements the operator-facing half of ADR 019 § Terms Acceptance (the on-chain enforcement shipped in #1078). - New `commands::terms`: embeds the canonical TERMS.md (`include_str!`), so the displayed text is the exact preimage of the recorded hash. `decide` is the pure acceptance policy; `ensure_accepted` is the IO wrapper. - `decdn node register` / `decdn setup` read the network's `currentTermsHash`, then gate registration on acceptance: - Terminal: print the terms + version + hash, prompt `[y/N]` (default no). - Headless/automation: require `--accept-terms` (errors clearly without it) — keeps scripted provisioning working while keeping consent explicit. - Stale client: if the embedded terms hash != the network's currentTermsHash, refuse — never sign terms the operator wasn't shown (ADR 019 § 281). - `--accept-terms` added to both commands (setup keeps it separate from `--yes`, which only skips the bond confirmation). - Terms display + prompt go to stderr so `--json` stdout stays clean. Tests: pure `decide` matrix, real `ensure_accepted` branches (headless/flag/ stale), and a lock on `keccak256(TERMS.md)` so a terms edit is a gated event paired with a governance setCurrentTermsHash bump. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(cli): require both stdin+stderr to be terminals before prompting for terms Gemini review on #1079: if stderr is redirected but stdin is a TTY, the terms + prompt print to the invisible stderr and the process blocks on stdin — a silent hang. Gate the interactive path on both streams being terminals; otherwise fall back to requiring --accept-terms. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(cli): gate terms on dry-run + before bond, off the runtime thread Review round on #1079 (Copilot + CodeRabbit): - register --dry-run now also enforces terms acceptance: a dry run still emits a real, submit-able signature committing to termsHash, so it must not be produced over unseen/stale terms. (Copilot) - setup accepts terms BEFORE bond::execute (gated on !already_registered) so a refusal / stale-client aborts before the bond is spent, not after. Extracted `accept_terms_if_registering` helper (keeps setup::run under the cognitive- complexity limit). (CodeRabbit) - New `terms::ensure_accepted_async` runs the blocking prompt via spawn_blocking so it never parks a tokio worker; call sites use it. (CodeRabbit) - (stderr-redirect interactive check already landed in the prior commit.) Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Resolve conflict in contracts/test/CapacityBondRegionE2E.t.sol: main (#1078) inserted REG_TERMS_HASH inside the AUTO-GENERATED ed25519-vector marker block. That block is now generator-authoritative (freshness CI job regenerates it and fails on any diff), and termsHash is not part of the ed25519 ownership digest, so REG_TERMS_HASH is moved just below the END AUTO-GENERATED frame. The block's regen comment keeps the PR's '--write' wording that the generator emits. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #1076. Ships the on-chain half of ADR 019 § Terms Acceptance, which until now existed only as spec — ADR 019 §109 called the shown signatures the "pre-extension surface" and no contract carried
termsHash. The legal text (#1044) and ADR (#1023) had already merged; this is the missing contract.What changed
CapacityBondregisterNodegains atermsHashparam. It must equal the governance-canonicalcurrentTermsHash(TermsHashMismatchotherwise) and is covered by the binding signature over a newRegisterNode(nodeId,nonce,termsHash)typehash. EmitsTermsAccepted(nodeId, termsHash, timestamp).currentTermsHashis set at genesis (constructor) and governor-swappable post-deploy viasetCurrentTermsHashunderGOVERNANCE_ROLE. No[floor, ceiling]rail — a hash has no monotonic direction (ADR 019 §243).bindNodeId(key rotation) keeps the unchangedBindNodeIdpayload and never re-accepts terms. The distinct typehash prevents replaying a registration signature as a bare rebind; the sharedbindingNoncepreserves cross-path replay protection.Deploy:
DeployConfig.currentTermsHashthreaded throughBaseProtocolDeploy/DeployProtocol(envCURRENT_TERMS_HASH, default0).ADRs: ADR 003 § NodeId Binding documents the
RegisterNodetyped struct alongsideBindNodeId; ADR 019 drops the pre-extension caveat and namessetCurrentTermsHash.Design note
Registration uses its own
RegisterNodetypehash rather than extendingBindNodeId, so key rotation stays a pure rebind with no meaningless terms re-acceptance. Genesis initializescurrentTermsHashin the constructor (no permissive zero-default bootstrap).Tests (7 new, all TDD + negative-controlled)
recordsTermsAcceptance,revertsOnTermsHashMismatch,signatureMustCoverTermsHash,setCurrentTermsHash_onlyGovernance,_emitsAndSwaps,_bindsNewRegistrantsOnly,bindNodeId_rebindRequiresNoTermsAcceptance. Negative control confirmed the behavior tests fail when the check/event is removed.CI-mirror (local)
forge fmt --checkclean;FOUNDRY_PROFILE=ci forge build --deny warningsexit 0 (CapacityBond 23,019 B, 1,557 under EIP-170).forge test: 682 passed, 0 failed.aderyn: 4 highs — identical to pre-change baseline (known local over-report; no new finding).slither(fail_on: medium): exit 0; no finding references the new symbols.Follow-up
CLI display + acceptance flow: #1077 (depends on this).
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests