Repository navigation
feat(cup_explorer): extract the threshold master public keys of a CUP - #11786
Conversation
Add an `extract-master-public-keys` subcommand to the CUP explorer. It verifies a CUP against the subnet's public key in the registry, then prints the threshold master public keys that the subnet holds according to the CUP, hex-encoded like the mainnet keys that are hardcoded for `ic-pub-key`. The orchestrator already extracted these keys from CUPs. Move its `get_master_public_keys` unchanged to `ic-consensus-cup-utils`, so that the orchestrator and the CUP explorer share it, and drop the orchestrator's now unused `ic-consensus-dkg` dependency. In the CUP explorer, the reading and verification of a CUP file is shared by `verify` and the new subcommand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The command can succeed with an incomplete key set because extraction failures are only logged and not propagated.
1 open finding
What changed in this PR
Adds verified threshold master-public-key extraction to the CUP explorer and shares existing extraction logic with the orchestrator.
Changes:
- Adds the
extract-master-public-keyscommand and documentation. - Centralizes CUP verification and key extraction utilities.
- Updates Rust and Bazel dependencies accordingly.
| File | Description |
|---|---|
rs/orchestrator/src/upgrade.rs |
Uses shared key extraction. |
rs/orchestrator/Cargo.toml |
Removes obsolete DKG dependency. |
rs/orchestrator/BUILD.bazel |
Mirrors dependency removal. |
rs/cup_explorer/src/main.rs |
Adds the extraction subcommand. |
rs/cup_explorer/src/lib.rs |
Verifies CUPs and prints extracted keys. |
rs/cup_explorer/README.md |
Documents key extraction. |
rs/cup_explorer/Cargo.toml |
Adds logging dependency. |
rs/cup_explorer/BUILD.bazel |
Adds Bazel logging dependency. |
rs/consensus/cup_utils/src/lib.rs |
Hosts shared extraction logic. |
rs/consensus/cup_utils/Cargo.toml |
Adds extraction dependencies. |
rs/consensus/cup_utils/BUILD.bazel |
Mirrors new dependencies. |
Cargo.lock |
Updates workspace dependency resolution. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
|
✅ No security or compliance issues detected. Reviewed everything up to d4c8209. Security Overview
Detected Code Changes
|
pierugo-dfinity
left a comment
There was a problem hiding this comment.
The CUP explorer has no tests because all its commands read from the NNS registry
There's a system test for it, so we could probably adapt it with signing subnets to verify that the tool reads the keys correctly
The encoding of the printed keys is that of `MasterPublicKey`, and the README already explains how the keys relate to `ic-pub-key`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tem test The system subnet of `cup_explorer_test` now holds keys of all schemes, and a new test running in parallel to the existing one extracts their master public keys from the subnet's latest CUP with the CUP explorer. It checks them by deriving the public keys of a canister from them, the same way execution does, and comparing these to the public keys returned by the management canister. The app subnet of the existing test can't hold the keys, because it stays halted after its recovery. For the test, `extract_master_public_keys` now also returns the keys, so `//rs/cup_explorer` joins the visibility allowlist of `ic-management-canister-types-private`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Re the review:
Good point. The PR description was wrong about that; I've corrected it. In d4c8209,
The keys aren't on the app subnet because that subnet stays halted after its recovery: For the test, |
There was a problem hiding this comment.
🟢 Approval recommended
The shared extraction preserves existing behavior and the new command is comprehensively covered across supported key schemes.
0 open findings
1 resolved since last review
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
`//rs/tests/consensus:cup_explorer_test` flaked 4 times in 182 runs since dfinity#11786 (2026-10-09), across `_farm`, `_local` and `_head_nns_farm`, and always the same way. The `test` task fails with `assertion left == right failed, left: 5, right: 4` because the `RecoverSubnet` proposal ends `Failed` instead of `Executed`. Its failure reason: the registry canister traps at `do_recover_subnet.rs:124`, because the system subnet answered the recovery's `setup_initial_dkg` request with `Attempts to run this DKG repeatedly failed`. ### Root cause The system subnet rejects the request because it uses up its attempts while it still cannot use the request's registry version: 1. `do_recover_subnet` sends `SetupInitialDKG` with the registry canister's latest version (`pre_call_registry_version`). The test created that version 3.5-4.2 s earlier with its "Update DKG length" proposal, the one that puts a registry version between halting and recovery. 2. Blocks only include dealings and transcripts for a remote DKG request once the block's registry version has reached the request's version (`build_callback_id_config_map`, `remote.rs:185`). The block maker only uses a version that has been in the replica's registry client for at least `POLLING_PERIOD + poll_delay_duration_ms` = 10 s (`get_stable_registry_version`). Before that, the orchestrator's registry replicator has to store the version (it polls every 5 s), and the replica's registry client has to pick it up from the local store (also every 5 s). So the request cannot be served until 10-20 s after the version is created. Each failed replicator poll adds up to ~10 s. 3. Meanwhile, every DKG summary increments the request's attempt counter, whether or not the request could be served (`get_updated_remote_dkg_attempts`). The request is rejected at the 5th summary after it arrives (`MAX_REMOTE_DKG_ATTEMPTS`), i.e. after 4 to 5 DKG intervals. 4. dfinity#11786 set the system subnet's DKG interval to 14 so that the subnet generates its vetKD key quickly. On this fast single-node subnet a 15-block interval lasts 3.5-4 s, so the request was rejected only 15-17 s after it arrived. 5. Measured from the creation of the version, that budget is ~20-21 s, minus the ~3 blocks the DKG needs once it can use the version. That is about the worst case of point 2, so the request is rejected whenever both pollers pick the version up late. That is what happened in the 4 failures: - The replicator stored the new version 4.5-5.3 s after its creation, the top of its range. - The version became usable at most ~1.2 s too late for the DKG to finish before the 5th summary. - In the 4 passing retries, the remote transcripts were created 10.9-15.6 s after the version was stored, as point 2 predicts. - Apart from the two errors that carry the rejection itself, no system-node log shows any DKG dealing or transcript error. ### Fix Give the system subnet its own DKG interval of 49 instead of 14. The app subnet keeps 14, so it still halts quickly. - **Not shorter.** The subnet makes at most 5 blocks/s, because a single node notarizes after `initial_notary_delay` = 200 ms. At that rate, 4 intervals of 50 blocks give the request at least ~40 s. That is about twice the 10-20 s of point 2, with room left for one failed replicator poll. - **Not much longer.** The system subnet's first signed CUP has to exist before `test_extract_master_public_keys` downloads its first CUP, 40-50 s after genesis. While no CUP verifies, `explore()` writes nothing, and `extract_master_public_keys` then panics on the empty file instead of retrying. - With 49, that first CUP is at height 50. It exists 12-19 s after genesis and already holds all keys, the vetKD key included. - With 99, the first CUP would be at height 100. In the slowest attempts it would come only a few seconds before the download. ### History This test has hit the same failure before: - dfinity#10055 (2026-05-12) started counting every interval as an attempt. Before it, a request was only counted in intervals in which its DKG configs were created. - Back then the system subnet used interval 14, and the test flaked with the same error in June. dfinity#10515 fixed that by returning the system subnet to the default interval of 499. - dfinity#11786 set the interval back to 14 to get the vetKD key quickly. The new comment above the constant explains why the interval must not be shortened again. ### Verification On a devenv, `bazel test --runs_per_test=3` of the 4 non-manual variants passed 12 out of 12 runs: `_farm`, `_head_nns_farm`, `_local` and `_head_nns_local`. - **The recovery's remote DKG.** In the 6 `_local` runs, the test log includes the system node's journal. There the remote DKG transcripts were created 8.6-12.6 s after the request, before or during the first DKG interval that counted it. The 5th summary would only have come 65-90 s after the request; the devenv makes fewer blocks per second than CI. - One run hit the failures' unlucky phase: the version was stored 0.3 s after the request arrived. It still finished after 12.6 s. - **The key extraction.** In all 12 runs, `test_extract_master_public_keys` got a CUP holding all keys (height 100) on its first attempt. ### Possible follow-ups (not in this PR) - **Consensus:** `get_updated_remote_dkg_attempts` could stop counting a request while the summary's registry version hasn't reached the request's version, as before dfinity#10055. Requests would then no longer be rejected as "repeatedly failed" without being attempted. This matters little for subnets with long DKG intervals, such as the 499-block default, where 4 intervals last far longer than the ~20 s registry delay. - **CUP explorer:** `explore()` could report whether it wrote a CUP, and `read_and_verify_cup` could return errors instead of panicking. `test_extract_master_public_keys` could then retry while no CUP verifies yet, which would lift the upper bound on the system subnet's DKG interval in this test. This PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Leo Eichhorn <[email protected]>

Why
ic-pub-keyderives canister public keys offline from the mainnet master public keys that are hardcoded inic-secp256k1,ic-ed25519andic-vetkeys. Adding a key there, or checking an existing one, needs the master public key from a source we can trust. A subnet's CUP contains the transcripts of the keys that the subnet holds, and the CUP explorer can already verify a CUP against the subnet's public key in the NNS registry. It just could not print the keys.What
extract-master-public-keys --cup-path <CUP_FILE>. It verifies the CUP the same way asverify-cup-of-halted-subnet, then prints the key id, algorithm and hex-encoded public key of every key that the subnet holds according to the CUP. The underlyingextract_master_public_keysalso returns the keys. The keys use the encoding of the hardcoded keys: compressed SEC1 points for ECDSA and BIP340, 32-byte points for Ed25519, and compressed G2 points for vetKD.explore --download-pathdownloads the latest CUP of a subnet.get_master_public_keysmoves unchanged fromrs/orchestrator/src/upgrade.rstoic-consensus-cup-utils, and both the orchestrator and the CUP explorer use it from there. The orchestrator no longer depends onic-consensus-dkg.ic-consensus-cup-utilsnow depends directly onic-cryptoandic-management-canister-types-private, which were already in its dependency closure.verifyinto a helper used by both subcommands.extract_master_public_keysreturns the keys, the CUP explorer namesMasterPublicKeyId, so//rs/cup_explorerjoins the visibility allowlist ofic-management-canister-types-private, next to//rs/recovery.Tests
cup_explorer_testnow covers the new subcommand. The system subnet holds keys of all schemes (ECDSA secp256k1 and secp256r1, BIP340, Ed25519 and vetKD) from genesis, and uses the test's 14-block DKG interval so that it generates the vetKD key quickly. In parallel to the existing test,test_extract_master_public_keysdownloads the subnet's latest CUP withexploreand callsextract_master_public_keysuntil the CUP contains all keys. It then derives the public keys of a canister from each extracted master public key, the same way execution does, and checks that they match what the management canister's*_public_keyendpoints return for that canister. The keys are not on the app subnet of the existing test, because that subnet stays halted after its recovery.The moved
get_master_public_keysalso stays covered by the orchestrator's key-change tests.Against mainnet, the latest CUPs of
pzp6eandfuqsrwere downloaded withexplore, and the new subcommand printedkey_1(pzp6e) andtest_key_1(fuqsr) for ECDSA secp256k1, BIP340, Ed25519 and vetKD. All eight keys are identical to the keys hardcoded inic-secp256k1,ic-ed25519andic-vetkeys. The output forpzp6e:Locally, all 5 bazel tests that depend on the changed files at depth 2 pass, including the 4 variants of
cup_explorer_test(Farm and local, mainnet and head NNS canisters).🤖 Generated with Claude Code