Skip to content

Commit

Permalink
chore(crypto): CRP-2697 Move getrandom wasm32-unknown-unknown workaro…
Browse files Browse the repository at this point in the history
…und to packages (#3926)

This will allow us to publish it to crates.io for use by canister
developers outside the monorepo.

Rename from ic-crypto-getrandom-for-wasm to ic-dummy-getrandom-for-wasm
since that more clearly indicates what it does. That this crate lived in
crypto at all is just a historical accident; we happened to be the first
team that upgraded a dependency which in turn had a dependency on `rand
0.8`. That is the version of `rand` which relies on `getrandom 0.2`, and
`getrandom 0.2` is the first version which intentionally refuses to
compile on `wasm32-unknown-unknown`.

---------

Co-authored-by: IDX GitHub Automation <[email protected]>
  • Loading branch information
randombit and IDX GitHub Automation authored Feb 14, 2025
1 parent 7a27527 commit 882e7af
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 38 deletions.
25 changes: 13 additions & 12 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ go_deps.bzl @dfinity/idx
/publish/ @dfinity/idx

# [Packages]
/packages/icrc-cbor/ @dfinity/finint @dfinity/cross-chain-team
/packages/icrc-ledger-agent/ @dfinity/finint
/packages/icrc-ledger-types/ @dfinity/finint
/packages/ic-ledger-hash-of/ @dfinity/finint
/packages/pocket-ic/ @dfinity/pocket-ic
/packages/ic-ed25519/ @dfinity/crypto-team
/packages/ic-ethereum-types/ @dfinity/cross-chain-team
/packages/ic-metrics-assert/ @dfinity/cross-chain-team
/packages/ic-secp256k1/ @dfinity/crypto-team
/packages/ic-sha3/ @dfinity/crypto-team
/packages/ic-signature-verification/ @dfinity/crypto-team
/packages/ic-vetkd-utils/ @dfinity/crypto-team
/packages/icrc-cbor/ @dfinity/finint @dfinity/cross-chain-team
/packages/icrc-ledger-agent/ @dfinity/finint
/packages/icrc-ledger-types/ @dfinity/finint
/packages/ic-ledger-hash-of/ @dfinity/finint
/packages/pocket-ic/ @dfinity/pocket-ic
/packages/ic-dummy-getrandom-for-wasm/ @dfinity/crypto-team
/packages/ic-ed25519/ @dfinity/crypto-team
/packages/ic-ethereum-types/ @dfinity/cross-chain-team
/packages/ic-metrics-assert/ @dfinity/cross-chain-team
/packages/ic-secp256k1/ @dfinity/crypto-team
/packages/ic-sha3/ @dfinity/crypto-team
/packages/ic-signature-verification/ @dfinity/crypto-team
/packages/ic-vetkd-utils/ @dfinity/crypto-team

# [IC-OS]
/ic-os/ @dfinity/node
Expand Down
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"packages/icrc-ledger-client",
"packages/icrc-ledger-client-cdk",
"packages/icrc-ledger-types",
"packages/ic-dummy-getrandom-for-wasm",
"packages/ic-ed25519",
"packages/ic-ethereum-types",
"packages/ic-metrics-assert",
Expand Down Expand Up @@ -96,7 +97,6 @@ members = [
"rs/crypto/internal/test_vectors",
"rs/crypto/node_key_generation",
"rs/crypto/node_key_validation",
"rs/crypto/getrandom_for_wasm",
"rs/crypto/prng",
"rs/crypto/sha2",
"rs/crypto/utils/canister_threshold_sig",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ load("@rules_rust//rust:defs.bzl", "rust_library")
package(default_visibility = ["//visibility:public"])

rust_library(
name = "getrandom_for_wasm",
name = "ic-dummy-getrandom-for-wasm",
srcs = glob(["src/**"]),
crate_name = "ic_crypto_getrandom_for_wasm",
crate_name = "ic_dummy_getrandom_for_wasm",
version = "0.1.0",
deps = [
# Keep sorted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[package]
name = "ic-crypto-getrandom-for-wasm"
version.workspace = true
name = "ic-dummy-getrandom-for-wasm"
version = "0.1.0"
description = "Workaround a problem with rand on wasm32-unknown-unknown targets"
license = "Apache-2.0"
readme = "README.md"
authors.workspace = true
edition.workspace = true
description.workspace = true
documentation.workspace = true

[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"))'.dependencies]
Expand Down
12 changes: 12 additions & 0 deletions packages/ic-dummy-getrandom-for-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ic-dummy-getrandom-for-wasm
=============================

The `rand` crate is widely used in the Rust ecosystem. The `rand` crate in turn
relies on `getrandom` to acquire cryptographic seed material. For policy
reasons, `getrandom` refuses to compile on the `wasm32-unknown-unknown` target
used by the Internet Computer. This prevents using `rand` without workarounds.

This crate implements such a workaround; on `wasm32-unknown-unknown` target, it
registers a custom getrandom implementation which just returns an error at
runtime. On any other target, it does nothing.

File renamed without changes.
4 changes: 2 additions & 2 deletions rs/bitcoin/ckbtc/minter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package(default_visibility = ["//visibility:public"])

LIB_DEPS = [
# Keep sorted.
"//packages/ic-dummy-getrandom-for-wasm",
"//packages/ic-secp256k1",
"//packages/icrc-ledger-client-cdk:icrc_ledger_client_cdk",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/bitcoin/checker:btc_checker_lib",
"//rs/crypto/getrandom_for_wasm",
"//rs/crypto/sha2",
"//rs/ledger_suite/common/ledger_core",
"//rs/ledger_suite/icrc1/ledger",
Expand Down Expand Up @@ -79,8 +79,8 @@ alias(
deps = [
# Keep sorted.
":ckbtc_minter_lib",
"//packages/ic-dummy-getrandom-for-wasm",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/crypto/getrandom_for_wasm",
"//rs/rust_canisters/canister_log",
"//rs/rust_canisters/http_types",
"@crate_index//:candid",
Expand Down
2 changes: 1 addition & 1 deletion rs/bitcoin/ckbtc/minter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ic-canister-log = { path = "../../../rust_canisters/canister_log" }
ic-canisters-http-types = { path = "../../../rust_canisters/http_types" }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-crypto-getrandom-for-wasm = { path = "../../../crypto/getrandom_for_wasm" }
ic-crypto-sha2 = { path = "../../../crypto/sha2" }
ic-dummy-getrandom-for-wasm = { path = "../../../../packages/ic-dummy-getrandom-for-wasm" }
ic-icrc1 = { path = "../../../ledger_suite/icrc1" }
ic-ledger-core = { path = "../../../ledger_suite/common/ledger_core" }
ic-management-canister-types-private = { path = "../../../types/management_canister_types" }
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/cmc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
# Keep sorted.
"//packages/ic-dummy-getrandom-for-wasm",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/crypto/getrandom_for_wasm",
"//rs/crypto/tree_hash",
"//rs/ledger_suite/common/ledger_core",
"//rs/ledger_suite/icp:icp_ledger",
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/cmc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dfn_core = { path = "../../rust_canisters/dfn_core" }
dfn_http_metrics = { path = "../../rust_canisters/dfn_http_metrics" }
icrc-ledger-types = { path = "../../../packages/icrc-ledger-types" }
ic-base-types = { path = "../../types/base_types" }
ic-crypto-getrandom-for-wasm = { path = "../../crypto/getrandom_for_wasm" }
ic-crypto-tree-hash = { path = "../../crypto/tree_hash" }
ic-dummy-getrandom-for-wasm = { path = "../../../packages/ic-dummy-getrandom-for-wasm" }
ic-management-canister-types-private = { path = "../../types/management_canister_types" }
ic-ledger-core = { path = "../../ledger_suite/common/ledger_core" }
ic-metrics-encoder = "1"
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/governance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ filegroup(
# See rs/nervous_system/feature_test.md
DEPENDENCIES = [
# Keep sorted.
"//rs/crypto/getrandom_for_wasm",
"//packages/ic-dummy-getrandom-for-wasm",
"//rs/crypto/sha2",
"//rs/ledger_suite/common/ledger_core",
"//rs/ledger_suite/icp:icp_ledger",
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ ic-canisters-http-types = { path = "../../rust_canisters/http_types" }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-cdk-timers = { workspace = true }
ic-crypto-getrandom-for-wasm = { path = "../../crypto/getrandom_for_wasm" }
ic-crypto-sha2 = { path = "../../crypto/sha2/" }
ic-dummy-getrandom-for-wasm = { path = "../../../packages/ic-dummy-getrandom-for-wasm" }
ic-ledger-core = { path = "../../ledger_suite/common/ledger_core" }
ic-management-canister-types-private = { path = "../../types/management_canister_types" }
ic-metrics-encoder = "1"
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/gtc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ filegroup(
# See rs/nervous_system/feature_test.md
DEPENDENCIES = [
# Keep sorted.
"//packages/ic-dummy-getrandom-for-wasm",
"//packages/ic-secp256k1",
"//rs/crypto/getrandom_for_wasm",
"//rs/crypto/sha2",
"//rs/ledger_suite/icp:icp_ledger",
"//rs/nervous_system/common",
Expand Down
2 changes: 1 addition & 1 deletion rs/nns/gtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dfn_core = { path = "../../rust_canisters/dfn_core" }
hex = { workspace = true }
hex-literal = "0.4.1"
ic-base-types = { path = "../../types/base_types" }
ic-crypto-getrandom-for-wasm = { path = "../../crypto/getrandom_for_wasm" }
ic-crypto-sha2 = { path = "../../crypto/sha2/" }
ic-dummy-getrandom-for-wasm = { path = "../../../packages/ic-dummy-getrandom-for-wasm" }
ic-nervous-system-common = { path = "../../nervous_system/common" }
ic-nervous-system-common-build-metadata = { path = "../../nervous_system/common/build_metadata" }
ic-nns-governance-api = { path = "../governance/api" }
Expand Down

0 comments on commit 882e7af

Please sign in to comment.