You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This removes a lot of small dependencies that are better inlined. By inlining we remove a lot of transitive dependencies. This speeds up the build and avoids a whole class of suply-chain attacks.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
The workspace-wide dependency and behavior migrations span many critical components and require comprehensive Cargo and Bazel validation before approval.
Review effort: Balanced Findings: None
What changed in this PR
This PR reduces Rust and Bazel dependency graph complexity by removing unused dependencies and replacing several small crates with standard-library or existing workspace functionality.
Changes:
Removes unused Cargo and Bazel dependencies across many crates.
Replaces helper crates with OnceLock, LazyLock, available_parallelism, flate2, tracing, and local implementations.
Consolidates Bitcoin dependencies and removes the obsolete PCRE2 patch.
This removes a lot of small dependencies that are better inlined. By
inlining we remove a lot of transitive dependencies. This speeds up the
build and avoids a whole class of suply-chain attacks.
The crate added on master in #11619 only logs through ic_logger's macros,
which this branch changed to expand to `$crate::slog`, so the direct slog
dependency is no longer needed.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ger and unit
duration-string also accepts compound durations such as `1m30s` or `1h 30m`,
as the 0.3.0 version used before this change did, so describing the format as
"an integer followed by a unit" undersold it.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The ckBTC minter tests, the pocket-ic tests and the bitcoin fuzzers used
bitcoin 0.28.2 before this PR, which moved them to the workspace
`bitcoin` crate, i.e. the bitcoin-dogecoin fork. The Dogecoin
integration is going to be wound down, so keep them on bitcoin 0.28.2
rather than coupling them to the fork, as suggested in review:
#11669 (comment)
This restores their pre-PR code, their bitcoin 0.28.2 dev-dependency and
Bazel labels, the crate.spec, and the lock entries for bitcoin 0.28.2,
bech32 0.8.1, bitcoin_hashes 0.10.0, secp256k1 0.22.2 and
secp256k1-sys 0.5.2, all identical to master's. The PR's other changes
to these crates (unused-dependency removals) stay. So does the new
deserialize_dogecoin_raw_network_message fuzzer, which needs the fork
for its bitcoin::dogecoin types.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
FileContexts consumes the SELinux file_contexts file extracted from the GuestOS rootfs (ic-os/defs.bzl:158-163), whose pattern language is PCRE2. regex::bytes::Regex implements a smaller grammar and rejects valid PCRE2 constructs such as look-around and backreferences, so a policy update containing one of those patterns will make FileContexts::new fail and block image construction. Keep a PCRE2-compatible engine, or explicitly translate/validate the full SELinux pattern grammar before dropping this dependency.
Preserve backward-compatible duration syntax in IC_CONFIG
rs/tests/driver/src/driver/ic.rs:740
This changes the accepted syntax of the externally supplied system-test configuration. from_config.rs deserializes IC_CONFIG into IcConfig, whose complex subnet variant is Box<Subnet> (rs/tests/dre/utils/lib.rs:91-96), so existing values accepted by humantime-serde—for example "unit_delay": "1.5s" or units such as min—now fail under duration-string. Please retain the old grammar with a compatibility parser (and add a complex-subnet deserialization test) rather than making dependency cleanup break existing configurations.
…cies lint (dfinity#12165)
Rust 1.100.0 (dfinity#12143) brought Cargo's new
[`cargo::unused_dependencies`](https://doc.rust-lang.org/stable/cargo/reference/lints.html#unused_dependencies)
and `cargo::unused_workspace_dependencies` lints (warn by default). On
master,
```
cargo check --workspace --all-targets --all-features --keep-going
```
reports 30 unused `[dependencies]`/`[build-dependencies]` entries and
one unused `[workspace.dependencies]` entry. A run with default features
reports the same 31.
This PR removes the ones that are really unused. Where Bazel listed the
same dependency, the PR removes it from the `BUILD.bazel` file too; the
"already absent" rows below needed no Bazel change. It also removes the
`crate.spec` of each removed workspace dependency from
`bazel/rust.MODULE.bazel`.
The lint says nothing about a dependency while another dependency of the
same crate still pulls it in, so the removals exposed four more, which
this PR also removes:
- `rustc-hash` in `ic-nns-integration-tests`, previously also reachable
through its dev-dependency `ic-nervous-system-integration-tests`;
- `ic-types` and `icp-ledger` in `ic-sns-governance-api`, previously
also reachable through `ic-nns-common`;
- the workspace's `rustc-hash` entry, once no member inherited it.
In total the PR removes 21 `[dependencies]`, 2 `[build-dependencies]`
and 2 `[workspace.dependencies]` entries, and moves 4 entries to
`[dev-dependencies]`. After it, the command above reports only the six
false positives listed at the end, with default features as well.
A `[dependencies]` entry only counts as used if the library or a binary
(including their unit tests) uses it. The lint therefore also reports
dependencies that only integration tests (`tests/*.rs`) use. Deleting
those would break the tests, so they move to `[dev-dependencies]`
instead; the lint doesn't check that table.
### Removed
| Crate | Unused dependency | Bazel |
|---|---|---|
| `consensus-vetkd-system-tests` | `ic_consensus_system_test_utils` |
removed |
| `ic-boundary-nodes-performance-test-common` |
`ic-boundary-nodes-system-test-utils` | removed |
| `ic_consensus_system_test_utils` | `ic-http-utils` | removed |
| `ic-cup-explorer` | `ic-registry-client` | already absent |
| `ic-nervous-system-integration-tests` | `ic-nns-test-utils-macros` |
already absent |
| `ic-nervous-system-integration-tests` | `ic-test-utilities-load-wasm`,
`rustc-hash` | removed |
| `ic-nns-integration-tests` | `dfn_json`, `rustc-hash` | removed |
| `ic-nns-test-utils` | `ic-node-rewards-canister-api` | removed |
| `ic-node-rewards-canister-api` | `ic-nervous-system-proto` | already
absent |
| `rewards-calculation` | `ic-cdk`, `ic-nns-constants` | already absent
|
| `dfn_http_metrics` | `dfn_http` | already absent |
| `ic-sns-governance-api` | `ic-nns-common`, `ic-types`, `icp-ledger`,
`itertools` | already absent |
| `ic-sns-test-utils` | `ic-nns-governance` | already absent |
| `ic-validator-ingress-message-test-canister` | `build-info` | removed
|
| `ic-sns-governance` | build-dependencies `ic-base-types` and
`prost-build` (`build.rs` only calls `build_info_build`) | removed from
`BUILD_DEPENDENCIES` |
| `ic-dummy-getrandom-for-wasm` | `getrandom` on targets other than
`wasm32-unknown-unknown`, where all of the crate's code is compiled out
| `deps` became a `select()` on `wasm32-unknown-unknown` |
| workspace | `ring` (no member has inherited it since dfinity#11669) and
`rustc-hash` (no member inherits it after the removals above) |
`crate.spec`s removed |
### Moved to `[dev-dependencies]` (only integration tests use them)
| Crate | Dependency | Bazel |
|---|---|---|
| `ic-consensus` | `ic-consensus-certification` | removed from
`:malicious_consensus`; the test targets already list it |
| `ic-crypto-internal-seed` | `hex` | already only on
`:seed_integration` |
| `ic_stable_memory_integrity` | `canister-test` | already only on the
`rust_ic_test` |
| `ic-nervous-system-integration-tests` | `ic-sns-cli` | moved from the
shared list to the three `rust_test`s that use it |
### `ring` and `rustc-hash`
Both stay transitive dependencies in Cargo and in Bazel.
- **`ring`** comes in through `rcgen`, `x509-parser` and, on wasm32,
`quinn-proto`, so its `crate.annotation` stays. The removed `crate.spec`
was the only thing enabling ring's `std` feature in Bazel. Cargo already
builds ring without `std` (see `cargo tree -e features -i ring --target
all`), so after the repin Bazel matches Cargo. In ring 0.17.14, `std`
only adds `std::error::Error` impls for `error::Unspecified` and
`error::KeyRejected`.
- **`rustc-hash` 1.1.0** comes in through `bindgen`. Its `crate.spec`
enabled no features and it has no `crate.annotation`, so the repin only
drops it from the direct dependencies.
### Kept: false positives
The lint only sees code compiled for the host. These dependencies are
only used when compiling for wasm, so they stay:
- `ic0` in `canlog` (`#[cfg(target_family = "wasm")]`) and
`ic-canister-profiler` (`#[cfg(target_arch = "wasm32")]`)
- `ic-cdk` in `ic-nervous-system-time-helpers` (`#[cfg(target_arch =
"wasm32")]`)
- `ic-dummy-getrandom-for-wasm` in `cycles-minting-canister`,
`ic-ckbtc-minter` and `xnet-test`. Nothing references it in Rust code.
It turns on getrandom 0.2's `custom` feature, which `rand` needs to
compile for `wasm32-unknown-unknown` with Cargo.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
…xide 0.9.1 (dfinity#12191)
Updates flate2 from 1.1.9 (Cargo) and 1.1.5 (Bazel) to 1.1.11 in both
builds. Since 1.1.10, flate2's default backend is miniz_oxide 0.9
instead of 0.8, and the locks resolve it to miniz_oxide 0.9.1.
dfinity#12180 held flate2 back for this reason:
- miniz_oxide 0.9.1 rejects some deflate streams that 0.8.9 accepted.
- The replica decodes a canister's stored gzipped Wasm module again
whenever it compiles it, so an installed module could stop loading after
a replica upgrade.
This description sets out how far that risk goes. Whether to take it is
for the Execution team to decide (@dfinity/core-protocol, which owns
`rs/embedders`).
**Recommendation: take it.** A hit is very unlikely (see below). If one
happens, it is limited to that canister, it shows in the replica's
metrics, and a replica release that restores the old rule undoes it.
# What changes for gzipped canister modules
**One stream shape is newly rejected.**
- **The shape:** a dynamic Huffman block whose literal/length or
distance code gives a code to exactly one symbol, with a code length of
2 to 15.
- miniz_oxide 0.9.1 rejects the table as soon as it reads the block
header, even if the block never uses that code (Frommi/miniz_oxide#190,
which fixesFrommi/miniz_oxide#137). 0.8.9 accepted it.
- For the literal/length code this can only be an empty block whose one
code is end-of-block.
- **zlib already rejects it,** and so do GNU gzip and pigz. 0.9.1's
table checks follow zlib's `inflate_table` rule for rule.
- **No other acceptance change:** the 0.8.9 → 0.9.1 inflate diff changes
only this table check.
- In 11 million differential cases, every stream that 0.8.9 accepted and
0.9.1 rejected had this shape. 0.9.1 accepted nothing that 0.8.9
rejected, and streams both accepted decoded to the same bytes.
- Nothing else on the `decode_wasm` path changes which modules are
accepted.
**No common compressor produces that shape:**
- **At least two codes:**
- zlib and its derivatives (zlib-ng, zlib-rs, pako, Node), GNU gzip,
pigz, 7-Zip and ISA-L always emit at least two codes.
- So does libdeflate from 1.19. Earlier versions emit an empty code or
two 1-bit codes, which both versions accept.
- **A 1-bit code:** miniz, miniz_oxide, zopfli, libflate and Go's
compress/flate give a lone symbol a 1-bit code, which both versions
accept.
- **dfx** compresses with flate2 when `"gzip": true` is set and whenever
it rewrites a gzipped module. It has used miniz_oxide since 0.24.2
(dfinity/sdk#3958), and zlib-ng before that.
- **IC tooling:**
- Our canisters are gzipped with pigz. The bundled ic-btc-canister
release uses GNU gzip.
- The asset canister and Internet Identity use `gzip --best --no-name`.
- icp-cli's recipes use `gzip --no-name`.
- **Experiments:** none of the encoders that could be run here produced
such a table. They were GNU gzip, pigz, busybox, 7-Zip, zlib via Python,
Node and Java, zlib-rs, libdeflate, zopfli, libflate, the deflate crate,
and miniz_oxide 0.8.9 and 0.9.1, directly and through flate2. The runs
covered:
- 35,522 gzip streams from 57 edge-case and real inputs;
- 948,000 raw streams from 6,000 random inputs, using the Rust encoders.
Go, ISA-L, pako and zlib-ng were checked in source only.
**None of the real modules we could obtain has it.** All 2,290 distinct
canister modules we found decode to identical bytes with flate2 1.1.5,
1.1.9 and 1.1.11. None of their 79,097 dynamic blocks has an incomplete
or single-symbol table. The modules came from:
- the history of `mainnet-canister-revisions.json` since 2024-10 (581
module hashes);
- DFINITY's CDN for 23 IC versions since 2023-01 (1,043 release
canisters);
- the asset canister and wallet bundled with dfx since 2022-08;
- 22 public IC projects' GitHub releases (529 assets);
- our current canisters, and the modules our Bazel build downloads as
test data.
**Most installed modules are not among them.** A sample of 3,000 mainnet
canisters from the public dashboard API had 843 with a module. Only 252
of those run one of the modules above, and 241 of the 252 are asset
canisters. Checking the rest needs the installed modules themselves.
Someone with access to a recent checkpoint could scan the canisters' and
snapshots' `software.wasm` files for the shape; this is the check dfinity#12180
asked for.
**If an installed module has the shape,** for example because it was
hand-crafted or fuzzed:
- **Its developer would not have noticed.** Today's decoder, miniz_oxide
0.8.9 (on mainnet since dfinity#11669 in October 2026), accepts it. So did
libflate, which the replica used before, and so do dfx, ic-wasm and
7-Zip.
- **After the replica upgrade:**
- Every message to the canister fails with IC0505
(`CanisterInvalidWasm`) on every node, and so do heartbeats and timers.
- The failure is deterministic, so there's no divergence between nodes
and no effect on the rest of the subnet.
- The canister still pays the fixed execution fee for each failed call,
callback and heartbeat. A canister that exports `canister_heartbeat`
pays it every round until it freezes, and a global timer that fires is
used up.
- **A normal upgrade fails too** if the module exports
`canister_pre_upgrade`, because the upgrade runs that hook from the old
module. The options:
- **Upgrade with `skip_pre_upgrade`:** this works and keeps stable
memory. It loses whatever `canister_pre_upgrade` would have saved, which
for canisters that serialize their heap in that hook is all heap state.
With enhanced orthogonal persistence, adding `wasm_memory_persistence =
keep` loses nothing.
- **Reinstall:** this also works, but wipes all state, stable memory
included.
- **Load a snapshot:** this should work without losing state, but is
untested. Take a snapshot, which doesn't decode the module. Download it,
replace its module with the same Wasm gzipped by a standard tool, upload
that as a new snapshot and load it.
- **No controller:** a canister without one can only be fixed by a
replica change.
- **Detection:** the replica counter
`sandboxed_execution_replica_cache_lookups` with `lookup_result`
`embedder_cache_hit_compilation_error` or
`compilation_cache_hit_compilation_error` counts executions that hit a
cached compilation error. A broken canister would make it rise after the
rollout.
- **Reversal:** nothing derived from the failed decode is persisted. The
module and the canister's memory stay as they are, and compilation
results, errors included, are only cached in memory and in a temporary
directory that is wiped when the replica starts. So a replica release
that restores the old rule makes the canister work again. Only the
effects of the failed messages remain: rejects, fees and used-up timers.
**Alternatives, if execution wants no change in what is accepted:**
- **Stay on flate2 1.1.9 / 1.1.5** (miniz_oxide 0.8.9).
- **Hold miniz_oxide at `=0.9.0`.** flate2 1.1.11 accepts it, and it
still has 0.8.9's rule; 0.9.1's only other changes affect wasm32. The
costs:
- No crate of ours depends on miniz_oxide directly, so this needs a
pinned direct dependency in `Cargo.toml` and a `crate.spec` in
`bazel/rust.MODULE.bazel`.
- It moves backtrace's copy back from 0.9.1.
- It only defers the decision.
- **Measure first.** Keep the old rule, ship a check in `decode_wasm`
that counts decoded modules with the rejected shape in a metric, and
switch once mainnet reports none for a release. The costs:
- `decode_wasm` runs in the compiler sandbox, so the count has to come
back with the compilation result.
- Modules are only decoded when a canister is installed or executes, so
idle canisters and stored snapshots stay unchecked.
# Other changes
- **Error text:** a gzip module whose deflate data is truncated, but
whose size trailer looks plausible, now fails with "failed to decode
compressed Wasm module: incomplete deflate stream". Before, it was "...:
unexpected end of file". The text appears in reject messages, and no
test asserts it. Most truncated uploads fail the module size check
before reaching flate2.
- **Raw-deflate and zlib decoders** now report truncated input as an
error instead of returning partial output, and zlib streams missing
their Adler-32 trailer now fail. Where this applies, all off-chain:
- **ICP Rosetta** (@dfinity/defi): request bodies with
`Content-Encoding: deflate` that are truncated or lack the trailer are
now rejected instead of parsed. Truncated gzip bodies only get a
different error. Bodies with the newly rejected table shape are rejected
too. ICRC Rosetta doesn't decompress requests.
- **ic-response-verification's raw `DeflateDecoder`,** for v1-certified
`deflate` responses. It runs in PocketIC's HTTP gateway and in the
ic-gateway binary that GuestOS ships for cloud engine nodes.
- **Other gzip decoders:** two places use the same gzip decoder on
inputs from standard compressors:
- the `.tar.gz` branch of `ic-http-utils`' archive extraction, which
only the orchestrator calls, to fetch the registry store during subnet
recovery;
- PocketIC.
- **Compression:**
- **Unchanged:** one-shot gzip and raw-deflate output is byte-identical
at every level.
- **Changed:**
- zlib-wrapped output at level 0 changes only its 2-byte header (`08 1D`
→ `78 01`);
- output in flush edge cases;
- output of `read::GzEncoder` and `bufread::GzEncoder` at level 1.
- **Production use:** production code compresses with flate2 only for
ic-boundary's and ic-gateway's `/metrics` responses, through tower-http
at the default level. Nothing stores, hashes or certifies those bytes.
No production canister links flate2, so all 44 canisters in
`//publish/canisters` are byte-identical with and without this change
(PR base 4b4fc5d).
- **Requirements and locks:**
- flate2's requirement goes from `1.0.31` to `1.1.11` in `Cargo.toml`
and `bazel/rust.MODULE.bazel`.
- miniz_oxide 0.8.9 drops out of both locks.
- zlib-rs 0.6.8, an optional flate2 backend, appears in them but isn't
built.
- miniz_oxide 0.9.1 gains its `default`, `simd` and `with-alloc`
features, which backtrace's copy now also gets.
- flate2's new default feature `runtime_detection` only enables
crc32fast's `std` feature, which was already on.
- No other package changes version.
# Verification
- **Locks:** in the dev container, `cargo update --workspace` reports
"Locking 0 packages". `./bin/bazel-pin.sh` reports "Nothing to repin.",
and `MODULE.bazel.lock` doesn't change.
- **Lint:** `./ci/scripts/rust-lint.sh` passes.
- **Tests:** these pass on the rebased head:
- `//rs/embedders:embedders_test`;
- `//rs/embedders:embedders_integration_tests/misc_tests`;
-
`//rs/execution_environment:execution_environment_misc_integration_tests/execution_test_test`,
which installs gzipped modules;
- the `//rs/http_utils` tests.
- **Evidence:** the figures above come from:
- differential tests of miniz_oxide 0.8.9 and 0.9.1 and of flate2 1.1.5,
1.1.9 and 1.1.11 against zlib;
- encoder experiments;
- decoding the module corpus;
- the dashboard sample;
- local builds of `//publish/canisters` with and without this change.
For each part except the dashboard sample, a second AI agent re-checked
the first one's findings with its own code and runs. The figures above
include its corrections. The scripts and raw results are not in the
repo.
This PR carries the `CI_ALL_BAZEL_TARGETS` label.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This removes a lot of small dependencies that are better inlined. By inlining we remove a lot of transitive dependencies. This speeds up the build and avoids a whole class of suply-chain attacks.