Repository navigation
feat(crypto): CRP-2879 Add support for PocketIC key derivation to ic-pub-key - #7194
Conversation
fspreiss
left a comment
There was a problem hiding this comment.
I noticed that we only depend on the published versions of ic-ed25519 and ic-secp256k1 in the Cargo build, but not in the Bazel build. I assume this is intentional.
Kinda? The situation is somewhat messy here. Note that the replica itself depends on If we pin to a specific version of In the current setup, changes to the crates apply to replica immediately on merge, and we are assured that tl;dr there are two different consumers of these crates, users via |
Makes sense, thanks! |
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]>
Split from #7148 because
ic-pub-keydepends on the publishedic-ed25519andic-secp256k1, so it was required first to add PocketIC support to those crates and publish new versions, prior to making this change.