Repository navigation
test(contracts): full ADR 030 updateRegion e2e — EIP-712 + ed25519 registerNode signing harness (#689) - #760
Conversation
…sterNode signing (#689) Replace the mock-based `test_updateRegion_cooldownAndPrevSnapshot` smoke test with an end-to-end flow that registers a node through the production `Ed25519Verifier` (unblocked by #669) and exercises the full ADR 030 region surface plus the cross-contract eject path. - Extend the pinned `ed25519-vectors` generator (no FFI, matching the repo's committed-vector pattern) with a section 4 that emits a real ed25519 signature over the exact `registerNode` ownership digest `keccak256(nodeId ‖ operator ‖ chainId ‖ registrationNonce)`. Add a pinned `sha3` dep + an EIP-55 checksummer; update Cargo.lock and README. - New `CapacityBondRegionE2E.t.sol` deploying the real verifier: signed register succeeds; corrupt-sig negative control reverts `InvalidEd25519Signature`; `updateRegion` cooldown / prev-snapshot / event; ed25519 replay rejection via the `deregisterNode` nonce bump; and the `ContentBlacklist → ejectNode` cross-contract path. - Remove the superseded mock smoke test from `CapacityBond.t.sol`. Issue #689 scope item 3 ("eject triggered when regionLastChanged falls outside the attestation window") has no production implementation in this revision — the region-ripening predicate that reads regionPrev/regionLastChanged is deferred to the ADR 030 enforcement PR — so the test covers the only cross-contract eject path that exists today (blacklist-driven) and documents the deferral inline. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 26832238701 |
Contracts coverageLine coverage: 88.96% (1797/2020 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces end-to-end testing for the ADR 030 updateRegion flow using the production Ed25519Verifier instead of a mock. Specifically, it removes the mock-based unit test from CapacityBond.t.sol and introduces a comprehensive test suite in CapacityBondRegionE2E.t.sol that exercises registration with real signatures, signature corruption, region cooldowns, replay protection, and cross-contract ejection. To support this, the offline test-vector generator in contracts/test/ed25519-vectors has been updated to generate real registerNode ownership vectors using Keccak256, adding the sha3 dependency. There are no review comments, and I have no additional feedback to provide.
Coverage reportTotal: 86.77% (was 86.77%, ● 0.00%) — 25214/29059 lines No coverage data for changed Rust files. History
|
There was a problem hiding this comment.
Pull request overview
This PR upgrades the contracts test suite for ADR 030 region self-attestation by replacing a mock-based smoke test with a true end-to-end registration + updateRegion flow that exercises the production Ed25519 verification path and the blacklist-driven cross-contract eject path.
Changes:
- Extend the committed Rust vector generator to emit a real ed25519 signature over the exact
registerNodeownership digest (keccak256(nodeId ‖ operator ‖ chainId ‖ registrationNonce)), and document the new output section. - Add
CapacityBondRegionE2E.t.solto deployCapacityBondwith the productionEd25519Verifierand test: real registration, invalid ed25519 rejection,updateRegioncooldown + prev snapshot + event, replay rejection viaregistrationNonce, and cross-contract eject viaContentBlacklist. - Remove the superseded mock smoke test from
CapacityBond.t.soland point readers to the new e2e test.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| contracts/test/ed25519-vectors/src/main.rs | Adds section-4 generation for a registerNode ed25519 signature vector and helper utilities (keccak + checksum formatting). |
| contracts/test/ed25519-vectors/README.md | Documents the additional consumer (CapacityBondRegionE2E.t.sol) and the new section-4 output. |
| contracts/test/ed25519-vectors/Cargo.toml | Adds a pinned sha3 dependency for keccak256 when generating the registerNode digest. |
| contracts/test/ed25519-vectors/Cargo.lock | Updates lockfile for the new sha3 dependency and transitive packages. |
| contracts/test/CapacityBondRegionE2E.t.sol | New end-to-end Foundry test covering production ed25519 registration, ADR 030 updateRegion behavior, replay rejection, and cross-contract eject. |
| contracts/test/CapacityBond.t.sol | Removes the old updateRegion smoke test and clarifies that ADR 030 e2e coverage lives in the new test file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// EIP-55 mixed-case checksum of a 20-byte address (Solidity rejects | ||
| /// all-lowercase address literals as failing the checksum test). |
There was a problem hiding this comment.
Checked this against solc 0.8.28 (the repo's pinned version) — it's a hard compile error, not a tooling/readability concern. Compiling an all-lowercase literal:
address internal constant A = 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266;gives:
Error (9429): This looks like an address but has an invalid checksum.
Correct checksummed address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".
If this is not used as an address, please prepend '00'.
A 39–41-digit hex literal that fails the EIP-55 checksum test is rejected (the compiler only accepts it as an address if it passes, or as a number literal if you pad it). That's exactly why the generator emits a checksummed literal — an all-lowercase paste would not compile. Leaving the comment as-is.
…rengthen eject assertions - Correct the replay-test comment: `bindingNonce` is advanced by the first `registerNode`, not by `deregisterNode` (which only bumps `registrationNonce`); the re-sign uses the live nonce to clear the binding check. - Tighten "short-circuit" → "revert before" in the replay-test natspec. - Strengthen the cross-contract eject test: assert the `ejected` flag (the slot the `registerNode` precondition checks) and the `EjectedByBlacklist` event, not just the cleared `active` state and bumped nonce. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve CapacityBond.t.sol conflict: keep the removal of the superseded mock-based test_updateRegion_cooldownAndPrevSnapshot (its coverage moved to CapacityBondRegionE2E.t.sol), atop main's stake→bond surface rename. Adapt CapacityBondRegionE2E.t.sol to the renamed surface: MIN_STAKE→MIN_BOND, minStake_→minBond_, bond.stake→bond.bond, _stakeAndRegister→_bondAndRegister.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new end-to-end test suite (CapacityBondRegionE2E.t.sol) to thoroughly cover the ADR 030 updateRegion flow using the production Ed25519Verifier and real signatures. To support this, the Rust test-vector generator (ed25519-vectors) has been updated to generate the required signing vectors, including adding the sha3 dependency and updating the documentation. The review feedback suggests optimizing the Rust vector generator by using a stack-allocated fixed-size array instead of a heap-allocated Vec for the cryptographic preimage, and improving test assertions in the new Solidity test suite by verifying the NodeAutoEjected event during cross-contract ejection.
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.
| let mut preimage = Vec::with_capacity(92); | ||
| preimage.extend_from_slice(&node_id); | ||
| preimage.extend_from_slice(®_OPERATOR); | ||
| preimage.extend_from_slice(&u256_be(CHAIN_ID)); | ||
| preimage.extend_from_slice(&NONCE.to_be_bytes()); | ||
| let digest: [u8; 32] = Keccak256::digest(&preimage).into(); |
There was a problem hiding this comment.
For fixed-size cryptographic preimages, we can avoid heap allocation (Vec) by using a stack-allocated fixed-size array [u8; 92]. This is more idiomatic and efficient in Rust, minimizing unnecessary memory allocations.
| let mut preimage = Vec::with_capacity(92); | |
| preimage.extend_from_slice(&node_id); | |
| preimage.extend_from_slice(®_OPERATOR); | |
| preimage.extend_from_slice(&u256_be(CHAIN_ID)); | |
| preimage.extend_from_slice(&NONCE.to_be_bytes()); | |
| let digest: [u8; 32] = Keccak256::digest(&preimage).into(); | |
| // Build the abi.encodePacked preimage: 32 + 20 + 32 + 8 = 92 bytes. | |
| let mut preimage = [0u8; 92]; | |
| preimage[0..32].copy_from_slice(&node_id); | |
| preimage[32..52].copy_from_slice(®_OPERATOR); | |
| preimage[52..84].copy_from_slice(&u256_be(CHAIN_ID)); | |
| preimage[84..92].copy_from_slice(&NONCE.to_be_bytes()); |
References
- Minimize memory allocations in performance-critical code by using in-place filtering or reusable buffers instead of creating multiple intermediate collections.
There was a problem hiding this comment.
Done in 998285a — preimage now built in a fixed [u8; 92] stack array. Re-ran the generator; the emitted REG_* vector bytes are identical, so no re-paste was needed.
| vm.expectEmit(true, false, false, false, address(bond)); | ||
| emit CapacityBond.EjectedByBlacklist(REG_OPERATOR); |
There was a problem hiding this comment.
Assert the NodeAutoEjected event in addition to EjectedByBlacklist to ensure complete coverage of the node deactivation side effects during cross-contract ejection.
vm.expectEmit(true, false, false, false, address(bond));
emit CapacityBond.EjectedByBlacklist(REG_OPERATOR);
vm.expectEmit(true, false, false, true, address(bond));
emit CapacityBond.NodeAutoEjected(REG_NODE_ID, MIN_BOND);
There was a problem hiding this comment.
Done in 998285a — added expectEmit for NodeAutoEjected(REG_NODE_ID, MIN_BOND) after EjectedByBlacklist (emit order). remainingBond == MIN_BOND since the operator bonded the minimum and was never slashed. 5/5 tests still pass.
…ert NodeAutoEjected - ed25519-vectors generator: build the registerNode preimage in a fixed [u8; 92] stack array instead of a heap Vec (idiomatic; emitted vector bytes unchanged). - CapacityBondRegionE2E eject test: also assert the NodeAutoEjected(nodeId, MIN_BOND) event alongside EjectedByBlacklist, covering both eject side-effect events. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alpergundogdu
left a comment
There was a problem hiding this comment.
Review — ADR 030 updateRegion e2e + ed25519 signing harness (#689)
Read the full diff. This is a clean, well-scoped test-only change (no src/ contract changes, so aderyn/slither surface is unaffected). The differential-vector approach (extend the pinned ed25519-vectors generator rather than enabling FFI) is the right call and matches the repo's established committed-vector pattern. Nice work; I'd approve.
Verified
- Digest construction matches the contract. The generator's 92-byte preimage
nodeId(32) ‖ operator(20) ‖ chainId(uint256 BE, 32) ‖ nonce(uint64 BE, 8)correctly mirrorskeccak256(abi.encodePacked(...))forregisterNode's ownership digest.u256_bezero-extends theu64chain id into the high-order 32-byte slot correctly. ✅ - EIP-55 checksummer is correct (keccak of the lowercase hex string, uppercase nibble ≥ 8) — needed because solc 0.8.28 rejects all-lowercase mixed-case-eligible address literals. ✅
vk.verify_strict(&digest, &sig)assertion in the generator guarantees the emitted vector is parity-valid against the production verifier's strictness bar. ✅- Negative control is genuine:
test_registerNode_corruptEd25519Signature_revertsflips a byte and assertsInvalidEd25519Signature, proving the real verifier is in the path, not rubber-stamping. ✅ - Replay test reasoning holds: after
deregisterNode,registrationNonce[nodeId]→ 1; the replayed sig was signed over nonce 0, so the digest differs and it revertsInvalidEd25519Signature. The fresh_signBindNode(reading the livebindingNonce) correctly isolates the ed25519 layer from the binding check. ✅ setUppinsvm.chainId(REG_CHAIN_ID)+ assertsvm.addr(REG_OP_PK) == REG_OPERATORso any Foundry-default drift fails loudly rather than silently invalidating the committed signature. ✅- Scope item #3 deferral is well-documented both inline and in the PR body (the
regionPrev/regionLastChangedripening predicate has no production reader yet; tracked in #761). Covering only the blacklist-driven eject path that actually exists is the correct call.
Nitpicks (non-blocking)
- The
hex_lit/nibbleconst-fn helperspanic!on malformed input — fine here (generator binary, compile-time, not workspace anti-panic scope), just noting they're build-time asserts by design. - Consider a brief comment on
REG_ED25519_SIGreminding maintainers it's regenerated viacargo runined25519-vectors(the README covers it, but the constant block is where someone will be tempted to hand-edit).
No correctness concerns. Mergeable.
Generated by Claude Code
Emit a regeneration reminder from the ed25519-vectors generator directly above the REG_ED25519_SIG constant (so it survives re-paste): the signature is bound to the digest and a hand-edited value fails verify_strict, reverting registerNode with InvalidEd25519Signature. Paste the refreshed block into CapacityBondRegionE2E.t.sol. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closes #689. Unblocked by #669 (production
Ed25519Verifier, merged).What
Replaces the mock-based
test_updateRegion_cooldownAndPrevSnapshotsmoke test with an end-to-end flow that registers a node through the productionEd25519Verifierand exercises the full ADR 030 region surface plus the cross-contract eject path.Signing harness (no FFI)
Extends the existing pinned
contracts/test/ed25519-vectors/generator — matching the repo's established committed-vector pattern (FFI is not enabled infoundry.toml) — with a section 4 that emits a real ed25519 signature over the exactregisterNodeownership digest:chainIdpinned to31337.sha3 = "=0.10.8"dep + an EIP-55 checksummer;Cargo.lockand README updated.New test —
CapacityBondRegionE2E.t.sol(deploys the real verifier)registerNodesucceeds (harness ↔ real verifier agree)InvalidEd25519Signature(negative control — proves the verifier is genuinely in the path)updateRegion: first call free, within-cooldown reverts the exactRegionCooldownActive(readyAt), after-window succeeds;regionPrev/regionLastChanged+RegionUpdatedassertedderegisterNodebumpsregistrationNonce, so replaying the original ed25519 sig in a fresh registration revertsInvalidEd25519Signature(deregister is the path that isolates the sig check — eject/already-active preconditions revert before it)ContentBlacklist.addOperator → CapacityBond.ejectNode: asserts theEjectedByBlacklistandNodeAutoEjected(nodeId, MIN_BOND)events, theejectedflag, node deactivation, and theregistrationNoncebumpRemoves the superseded mock smoke test from
CapacityBond.t.sol.Scope item 3 — deferral note
The issue's scope item 3 ("eject triggered when
regionLastChangedfalls outside the attestation window") has no production implementation in the current revision: the region-ripening predicate that readsregionPrev/regionLastChangedis deferred to the ADR 030 enforcement PR (see the region-attestation storage doc inCapacityBond.sol, which states no contract reads those slots yet). This PR therefore covers the only cross-contract eject path that exists today (blacklist-driven) and documents the deferral inline. Tracked in #761; noted on #689.Review & rebase
5c13233): corrected the replay-test comment (bindingNonceis advanced by the firstregisterNode, notderegisterNode) and strengthened the eject test (assert theejectedflag +EjectedByBlacklistevent). The disputed EIP-55 comment was verified accurate against solc 0.8.28 (all-lowercase address literals are a hard compile error) and left as-is.f1e0043): mergedmainto clear a conflict from thestake → bondsurface rename (refactor(contracts): rename stake→bond on CapacityBond surface #768). Resolution kept the deleted mock test atop main's renames; adapted the new test to the renamed surface (MIN_BOND,minBond_,bond.bond,_bondAndRegister).998285a): build the generator preimage in a fixed[u8; 92]stack array instead of a heapVec(emitted vector bytes unchanged); assertNodeAutoEjectedalongsideEjectedByBlacklistin the eject test.Verification (current HEAD)
forge test --match-contract CapacityBondRegionE2ETest→ 5/5 passforge test(full suite) → 444/444 passforge fmt --checkclean;FOUNDRY_PROFILE=ci forge build --deny warningscleancargo clippyclean; regenerated vector is byte-identical to the committed constantssrc/contract changes (test-only), so aderyn/slither findings are unaffected🤖 Generated with Claude Code