Skip to content

feat(crypto): CRP-2879 Add PocketIC keys to ic-secp256k1 and ic-ed25519 - #7148

Merged
randombit merged 6 commits into
masterfrom
jack/crp-2879
Oct 10, 2025
Merged

randombit merged 6 commits into
masterfrom
jack/crp-2879

Conversation

@randombit

Copy link
Copy Markdown
Contributor

The corresponding change to ic-pub-key must wait until this change is merged and new releases are created. Then we can roll forward the crates within the monorepo (in the toplevel Cargo.toml) and then update ic-pub-key.

This also fixes an issue building the tests with cargo.

@randombit
randombit requested a review from a team October 8, 2025 18:30
@github-actions github-actions Bot added the feat label Oct 8, 2025

@fspreiss fspreiss 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.

Thanks, @randombit!

Comment thread packages/ic-ed25519/src/lib.rs Resolved
Comment thread packages/ic-ed25519/src/lib.rs Resolved
Comment thread packages/ic-ed25519/src/lib.rs Resolved
Comment thread packages/ic-secp256k1/src/lib.rs Resolved
Comment thread packages/ic-secp256k1/src/lib.rs Resolved
Comment thread packages/ic-secp256k1/src/lib.rs Resolved
Comment thread packages/ic-secp256k1/src/lib.rs Resolved
Comment thread packages/ic-secp256k1/tests/tests.rs Resolved
Comment thread packages/ic-secp256k1/tests/tests.rs Resolved
@randombit
randombit enabled auto-merge October 10, 2025 18:06
@randombit
randombit added this pull request to the merge queue Oct 10, 2025
Merged via the queue into master with commit 584ca27 Oct 10, 2025
@randombit
randombit deleted the jack/crp-2879 branch October 10, 2025 19:06
github-merge-queue Bot pushed a commit that referenced this pull request Oct 15, 2025
…pub-key (#7194)

Split from #7148 because `ic-pub-key` depends on the published
`ic-ed25519` and `ic-secp256k1`, so it was required first to add
PocketIC support to those crates and publish new versions, prior to
making this change.

---------

Co-authored-by: IDX GitHub Automation <[email protected]>
basvandijk pushed a commit to Ocheretovich/ic that referenced this pull request Oct 23, 2026
dfinity#11895)

### Why

`ic-secp256k1` and `ic-ed25519` ship the mainnet and PocketIC master
public keys of their algorithms, and `ic-pub-key` uses them to derive
keys offline. The mainnet ECDSA keys `key_1` and `test_key_1` now also
exist over secp256r1 (P-256), and PocketIC holds secp256r1 keys too
(dfinity#11741). But `ic-secp256r1` has none of them.

This PR adds the keys and bumps the version, so the crate can be
released. `ic-pub-key` can only use the keys once that release is out
(dfinity#11894). That's the same order as dfinity#7148 before dfinity#7194 for the secp256k1
and Ed25519 PocketIC keys.

### What

* `PublicKey::mainnet_key(MasterPublicKeyId)` returns `key_1` and
`test_key_1`.
* `PublicKey::pocketic_key(PocketIcMasterPublicKeyId)` returns the keys
PocketIC uses for `key_1`, `test_key_1` and `dfx_test_key`.
* `PublicKey::derive_mainnet_key` and `PublicKey::derive_pocketic_key`
derive a canister's public key from those master keys. They are offline
equivalents of `ecdsa_public_key`. For their `&CanisterId` argument, the
crate re-exports `ic_principal::Principal` as `CanisterId`, as
`ic-secp256k1` and `ic-ed25519` do.
* `hex-literal` becomes a regular dependency, to embed the keys, and
`ic_principal` a new one.
* The version goes from 0.2.0 to 0.3.0, with a dated changelog entry,
for a release after merging. In-repo dependents use the crate by path
without a version, so nothing else changes.
* The `cup_explorer` README now lists `ic-secp256r1` among the crates
with hardcoded master keys.

Where the keys come from:

* **Mainnet:** the CUPs of subnets uzr34 (`key_1`) and fuqsr
(`test_key_1`). In that same output, the secp256k1, BIP340, Ed25519 and
VetKD master keys match the values `ic-secp256k1`, `ic-ed25519` and
`ic-vetkeys` already ship.
* **PocketIC:** derived the way the StateMachine does it, from
`PrivateKey::generate_insecure_key_for_testing(42)` and the key name.

### Tests

* `mainnet_keys_round_trip`: the mainnet keys round-trip.
* A test derives the PocketIC keys the StateMachine's way and compares
them with the hardcoded ones.
* `derive_mainnet_key` and `derive_pocketic_key` have known-answer tests
for all five keys. The expected keys are what the replica's
`derive_threshold_public_key` (the function that answers
`ecdsa_public_key`) returns for the same master key, canister and path.
* The SLIP-10 retry for nist256p1 (index 33941) is now tested. It's the
only branch of the derivation the existing tests didn't reach: it runs
when iL >= n, about once in 2^32 steps on P-256. The vector is the one
the replica's own key derivation test uses.
* Locally, in the dev container, all of these pass: `cargo check`,
`cargo fmt`, `rust-lint.sh`, `bazel build //... --nobuild`,
`//bazel:buildifier.check`, and the 37 tests from the depth-2 rdeps
query (this package, `ic-pub-key`, `rs/crypto`, the P-256 basic-sig
crate, `standalone-sig-verifier`, `rs/validator`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[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.

2 participants