Skip to content

feat(cup_explorer): extract the threshold master public keys of a CUP - #11786

Merged
eichhorl merged 3 commits into
masterfrom
eichhorl/cup-explorer-master-public-keys
Oct 9, 2026
Merged

eichhorl merged 3 commits into
masterfrom
eichhorl/cup-explorer-master-public-keys

Conversation

@eichhorl

@eichhorl eichhorl commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Why

ic-pub-key derives canister public keys offline from the mainnet master public keys that are hardcoded in ic-secp256k1, ic-ed25519 and ic-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

  • New subcommand extract-master-public-keys --cup-path <CUP_FILE>. It verifies the CUP the same way as verify-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 underlying extract_master_public_keys also 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-path downloads the latest CUP of a subnet.
  • Shared key extraction. The orchestrator already extracted these keys from CUPs, to raise an alert when a key changes. Its get_master_public_keys moves unchanged from rs/orchestrator/src/upgrade.rs to ic-consensus-cup-utils, and both the orchestrator and the CUP explorer use it from there. The orchestrator no longer depends on ic-consensus-dkg. ic-consensus-cup-utils now depends directly on ic-crypto and ic-management-canister-types-private, which were already in its dependency closure.
  • Shared CUP verification. In the CUP explorer, reading and verifying a CUP file moves out of verify into a helper used by both subcommands.
  • Because extract_master_public_keys returns the keys, the CUP explorer names MasterPublicKeyId, so //rs/cup_explorer joins the visibility allowlist of ic-management-canister-types-private, next to //rs/recovery.

Tests

cup_explorer_test now 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_keys downloads the subnet's latest CUP with explore and calls extract_master_public_keys until 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_key endpoints 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_keys also stays covered by the orchestrator's key-change tests.

Against mainnet, the latest CUPs of pzp6e and fuqsr were downloaded with explore, and the new subcommand printed key_1 (pzp6e) and test_key_1 (fuqsr) for ECDSA secp256k1, BIP340, Ed25519 and vetKD. All eight keys are identical to the keys hardcoded in ic-secp256k1, ic-ed25519 and ic-vetkeys. The output for pzp6e:

Threshold master public keys of subnet pzp6e-ekpqk-3c5x7-2h6so-njoeq-mt45d-h3h6c-q3mxf-vpeq5-fk5o7-yae according to the CUP at height 154106000:

              KEY ID: ecdsa:Secp256k1:key_1
           ALGORITHM: EcdsaSecp256k1
          PUBLIC KEY: 02121bc3a5c38f38ca76487c72007ebbfd34bc6c4cb80a671655aa94585bbd0a02

              KEY ID: schnorr:Bip340Secp256k1:key_1
           ALGORITHM: SchnorrSecp256k1
          PUBLIC KEY: 02246e29785f06d37a8a50c49f6152a34df74738f8c13a44f59fef4cbe90eb13ac

              KEY ID: schnorr:Ed25519:key_1
           ALGORITHM: Ed25519
          PUBLIC KEY: 476374d9df3a8af28d3164dc2422cff894482eadd1295290b6d9ad92b2eeaa5c

              KEY ID: vetkd:Bls12_381_G2:key_1
           ALGORITHM: VetKD
          PUBLIC KEY: a9caf9ae8af0c7c7272f8a122133e2e0c7c0899b75e502bda9e109ca8193ded3ef042ed96db1125e1bdaad77d8cc60d917e122fe2501c45b96274f43705edf0cfd455bc66c3c060faa2fcd15486e76351edf91fecb993797273bbc8beaa47404

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

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-keys command 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.

Comment thread rs/cup_explorer/src/lib.rs Resolved
@eichhorl
eichhorl marked this pull request as ready for review October 8, 2026 08:28
@eichhorl
eichhorl requested a review from a team as a code owner October 8, 2026 08:28
@zeropath-ai

zeropath-ai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to d4c8209.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/cup_explorer/src/lib.rs
    - Introduce get_master_public_keys usage and extended key handling
► rs/cup_explorer/src/main.rs
    - Add ExtractMasterPublicKeys subcommand and hook it to new extraction function
► rs/cup_explorer/Cargo.toml
    - Add ic-logger and ic-management-canister-types-private dependencies
► rs/cup_explorer/BUILD.bazel
    - Include logger and management_canister_types in deps for cup_explorer
► rs/cup_explorer/README.md
    - Document new “Extract master public keys” feature
► rs/cup_explorer/src/lib.rs
    - Implement get_master_public_keys function to extract threshold master public keys from CUP
► rs/cup_explorer/src/main.rs
    - Wire new ExtractMasterPublicKeys subcommand to extract_master_public_keys
► rs/cup_explorer/src/main.rs
    - Update imports to include extract_master_public_keys
► rs/orchestrator/src/upgrade.rs
    - Replace direct MasterPublicKeyId import usage and adjust to new get_master_public_keys import
► rs/orchestrator/BUILD.bazel
    - Remove dependency on ic-consensus-dkg from orchestrator
► rs/orchestrator/Cargo.toml
    - Remove ic-consensus-dkg dependency
► rs/tests/consensus/Cargo.toml
    - Add ic-vetkeys and ic-crypto-utils-canister-threshold-sig dependencies
► rs/tests/consensus/BUILD.bazel
    - Add dependencies for vet keys testing and cup explorer integration
► rs/tests/consensus/cup_explorer_test.rs
    - Update test description to include extraction of master public keys and integrate new feature
► rs/types/management_canister_types/BUILD.bazel
    - Include cup_explorer in subpackages whitelist

@pierugo-dfinity pierugo-dfinity left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread rs/cup_explorer/src/lib.rs Resolved
eichhorl and others added 2 commits October 8, 2026 15:35
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]>
@eichhorl

eichhorl commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Re the review:

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

Good point. The PR description was wrong about that; I've corrected it. In d4c8209, cup_explorer_test now covers the new subcommand:

  • The system subnet holds keys of all schemes from genesis. It now uses the test's 14-block DKG interval, so it generates the vetKD key quickly.
  • test_extract_master_public_keys runs in parallel to the existing test. It downloads the system subnet's latest CUP with explore, and calls extract_master_public_keys until the CUP contains all keys.
  • It derives the public keys of a canister from each extracted master public key, the same way execution does (derive_threshold_public_key for ECDSA and Schnorr, ic_vetkeys for vetKD). It then checks that they match what the management canister's *_public_key endpoints return for that canister.

The keys aren't on the app subnet because that subnet stays halted after its recovery: do_recover_subnet turns halt_at_cup_height into is_halted.

For the test, extract_master_public_keys now returns the keys as well as printing them. It therefore names MasterPublicKeyId, so //rs/cup_explorer joins the visibility allowlist of ic-management-canister-types-private, next to //rs/recovery.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@eichhorl
eichhorl added this pull request to the merge queue Oct 9, 2026
Merged via the queue into master with commit 822e08b Oct 9, 2026
42 checks passed
@eichhorl
eichhorl deleted the eichhorl/cup-explorer-master-public-keys branch October 9, 2026 06:40
AleDema pushed a commit to AleDema/ic that referenced this pull request Oct 18, 2026
`//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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants