Subject
typenum is a Rust library that encodes integers in the type system so that arithmetic, comparison, bitwise operations, and ordering can be performed at compile time. The crate exposes type-level bits (B0, B1), type-level unsigned integers (UTerm, UInt<U, B>), type-level signed integers (Z0, PInt<U>, NInt<U>), a type-level array (TArr), the comparison markers (Less, Equal, Greater), and a large set of trait-based type operators (Add, Sub, Mul, Div, Rem, BitAnd, BitOr, BitXor, Shl, Shr, Cmp, Min, Max, Pow, Gcd, Sqrt, Logarithm2, …). The op! macro provides a more ergonomic infix syntax over those operators via a shunting-yard macro_rules! parser. The consts module re-exports pre-named aliases (U0–U1024, powers of 2, powers of 2 minus 1, powers of 10 up to 10^19, P*/N* signed counterparts, plus U3600). The crate is #![no_std] and only depends on libcore; the optional scale_info feature pulls in scale-info for Parity Substrate compatibility, and the optional const-generics feature exposes U<const N: usize> mappings.
Methodology
Tooling used:
openvet audit new (0.6.0) to fetch and unpack the crate from crates.io and clone the upstream GitHub repository at the commit recorded in .cargo_vcs_info.json.
diff -r (Apple Darwin) to compare published crate contents against the upstream VCS checkout.
grep to search across contents/src and contents/tests for unsafe, FFI declarations, process::*, std::net::, std::fs::, env::, panic-prone calls (panic!, expect, unwrap, unimplemented!, unreachable!), transmute, raw-pointer manipulation, and heap allocators.
- Manual reading of the seven hand-written source files under
src/ (~6.5 K LOC: lib.rs, bit.rs, int.rs, uint.rs, array.rs, tuple.rs, marker_traits.rs, operator_aliases.rs, private.rs, type_operators.rs) and surveys of the three generated files under src/gen/ (~12 K LOC) and the generated integration-test file tests/generated.rs (~21 K LOC).
- Spot-checks of the generated content: the bit encoding of
U6 (UInt<UInt<UInt<UTerm, B1>, B1>, B0> = 110₂) and the test test_4_Mul_3 (U4 * U3 == U12).
The crate ships no build.rs, no proc macros, and #![forbid(unsafe_code)] is set at the crate root, so static review is sufficient — no need to inspect generated MIR or runtime behaviour.
The published typenum-1.20.1.crate was diffed against the upstream repository at the commit pinned in .cargo_vcs_info.json. All files under src/ and the tests/generated.rs integration-test file match byte-for-byte; the only differences are cargo's Cargo.toml normalisation and the upstream-only .envrc, .git, .github/, clippy.toml, flake.lock, flake.nix, justfile, and generate/ workspace member (all explicitly excluded via the exclude list in Cargo.toml.orig).
Results
The diff between published contents and the upstream repository shows no unexpected changes. The crate contains no binary artefacts (justifying has-binaries) and no build.rs. The 1.18.0 changelog records the removal of an earlier build.rs that generated the constants in favour of checking the output into the repository under src/gen/; the 1.20.0 changelog records the removal of the test-generation build.rs in favour of checking the generated tests into tests/generated.rs. The published Cargo.toml accordingly sets build = false. The [lib] section sets no proc-macro = true, so the crate is a normal library. Together this justifies has-build-exec and has-install-exec.
The codebase was reviewed for unsafe, FFI, process spawning, network or filesystem I/O, environment variables, concurrency primitives, JIT/interpreter behaviour, and cryptography. None was found, justifying uses-unsafe (enforced by #![forbid(unsafe_code)] at the crate root), uses-exec, uses-network, uses-filesystem, uses-environment, uses-concurrency, uses-crypto, uses-jit, and uses-interpreter, and likewise the corresponding implementation claims impl-crypto, impl-interpreter, impl-jit, impl-protocol, and impl-concurrency. Although the crate implements type-level arithmetic, the work happens entirely in the type system via trait resolution at compile time, not in runtime code paths; the corresponding impl-* claims (impl-algorithm, impl-datastructure, impl-parser) are about runtime algorithms and data structures and are therefore asserted false. The op! macro is a macro_rules! shunting-yard expansion to nested type aliases; it is not a parser in the data-format sense and is also covered by impl-parser.
Test coverage is provided by per-module #[cfg(test)] unit tests (truth-table coverage of bit operations in src/bit.rs; binary-formatting coverage in src/uint.rs; bit-creation in src/bit.rs) — justifying has-unit-tests — and by the auto-generated integration-test file tests/generated.rs with roughly 1 700 #[test] functions exercising bitwise, arithmetic, and comparison operations across the unsigned-integer constants, justifying has-integration-tests. No fuzz harness and no property-test harness ship with the crate or appear in the upstream tree, justifying has-fuzz-tests and has-property-tests.
One low-severity quality finding (FINDING-1) was recorded: the header of CHANGELOG.md continues to advertise an MSRV of 1.37.0 even though Cargo.toml declares rust-version = "1.41.0" and the changelog entry for 1.20.0 itself records the bump. Documentation-only inconsistency; no impact on compilation or behaviour.
No malicious behaviour was identified, justifying is-benign.
Conclusion
typenum is a mature, narrowly-scoped library that pushes integer arithmetic into the Rust type system. The crate has no runtime I/O of any kind, no unsafe (compiler-enforced via forbid(unsafe_code)), no build script, no proc macros, no procedural code execution at compile time beyond standard trait resolution, and only one optional dependency (scale-info). The hand-written code is well documented, the generated portions are clearly labelled and reproduced from a separate generate/ workspace member in the upstream repository, and the generated integration-test suite provides broad coverage of the arithmetic operators. The one finding is a stale MSRV claim in the changelog header.