Skip to content

chore(crates/primitives): migrate to new versions of rand and k256 - #1147

Open
StackOverflowExcept1on wants to merge 13 commits into
alloy-rs:mainfrom
StackOverflowExcept1on:rand-0.10-k256-0.14
Open

StackOverflowExcept1on wants to merge 13 commits into
alloy-rs:mainfrom
StackOverflowExcept1on:rand-0.10-k256-0.14

Conversation

@StackOverflowExcept1on

@StackOverflowExcept1on StackOverflowExcept1on commented Jul 12, 2026 •

Copy link
Copy Markdown

Motivation

Since new version of k256 has been released, it would be wise to support it

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

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

@StackOverflowExcept1on could you please revive this PR ? fix fmt/deny

@StackOverflowExcept1on

Copy link
Copy Markdown
Author

@mablr I would like to know if ruint update is required first?

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once this is merged we also need to do the same for all the other alloy reps

storopoli added a commit to alpenlabs/alpen-cli that referenced this pull request Oct 26, 2026
…t RUSTSEC-2026-0387 (#51)

## Description

`cargo audit` now fails on `main`. Five advisories published since its
last run on 2026-10-19 hit the current lockfile. This PR clears all
five, so the security workflow passes without waiting on #50.

Four have fixed releases, so this bumps them in the lockfile:

| Crate | From | To | Advisory |
| --- | --- | --- | --- |
| `rustls-webpki` | 0.103.15 | 0.103.16 | RUSTSEC-2026-0382 |
| `webpki-roots` | 1.0.9 | 1.0.11 | RUSTSEC-2026-0381 |
| `webpki-root-certs` | 1.0.9 | 1.0.11 | RUSTSEC-2026-0383 |
| `ctutils` | 0.4.2 | 0.4.6 | RUSTSEC-2026-0385 |

`crypto-bigint` 0.5.5 (RUSTSEC-2026-0387) can't be fixed from here. The
fix exists only in `crypto-bigint` 0.7.6. The latest `alloy-signer`
(2.5.0) and `alloy-primitives` (1.7.3) still require
`k256`/`elliptic-curve` 0.13, which pin `crypto-bigint` 0.5. This PR
adds `.cargo/audit.toml` with the advisory ignored. The comment there
records how the crate gets in, what it exposes and when to remove the
entry.

What it exposes: `k256` 0.13 does its scalar arithmetic with
`crypto-bigint`. EVM signing through the `PrivateKeySigner` from
`Seed::get_alpen_wallet` therefore runs the private key through the
affected subtraction code. An attacker would need to watch timing or
microarchitectural state on the user's machine while the CLI signs.
Bitcoin signing uses libsecp256k1 and doesn't touch `crypto-bigint`.

Upstream, `alloy-rs/alloy#4445` tracks the advisory.
`alloy-rs/core#1147` moves `alloy-primitives` to `k256` 0.14, but
`alloy-signer` needs the same bump before the entry can go.

### Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature/Enhancement (non-breaking change which adds
functionality or enhances an existing one)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update
- [ ] Refactor
- [ ] New or updated tests
- [x] Dependency update
- [x] Security fix

## Notes to Reviewers

- #50 has the same four bumps. Here they were redone on `main`'s
lockfile with `cargo update --precise`, which leaves out the
`windows-sys` churn from dependabot's resolution in #50. A test merge of
this branch into #50 is clean, and the result differs from #50 only by
`.cargo/audit.toml`, so either PR can land first.
- Run locally against the current advisory DB, `cargo audit` passes on
this branch and on the merge with #50.
- `cargo audit -D warnings` (`continue-on-error` in CI) still lists the
existing unmaintained-crate warnings and the informational tokio
RUSTSEC-2026-0386. #50's tokio bump to 1.54.1 clears the tokio one.

## Checklist

- [x] I have performed a self-review of my code.
- [x] I have commented my code where necessary.
- [x] I have updated the documentation if needed.
- [x] My changes do not introduce new warnings.
- [ ] I have added tests that prove my changes are effective or that my
feature works.
- [ ] New and existing tests pass with my changes.

## Related Issues

Related to #50.
@DaniPopes

Copy link
Copy Markdown
Member

@StackOverflowExcept1on No, ruint does not need to release first. ruint 1.21.1 is already on crates.io and has a rand-010 feature (an optional rand 0.10 dependency; the earlier rand-09 feature pulls in rand 0.9). alloy-primitives' rand feature enabled ruint/rand-09, so U256::random_with and Distribution<Uint> took rand 0.9 traits while FixedBytes took 0.10. I pushed a merge of main that raises ruint to 1.21.1, switches that feature to ruint/rand-010, updates Cargo.lock, and restores the from_dec_str test expectation, which the 1.21 ruint parser still satisfies in its original form.

@DaniPopes

Copy link
Copy Markdown
Member

cyclops audit

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

cc @DaniPopes

Cyclops audit event published. View workflow run

Config: config: default, iterations: default, hours: default

@tempoxyz-bot

tempoxyz-bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✅ Cyclops Security Review: safe to merge

Last reviewed: e3a2069 (latest) · no open findings

aiiven added a commit to Fabric-Labs/polyester-sdk-rust that referenced this pull request Nov 22, 2026
Moves the SDK's crypto stack to the current RustCrypto and dalek releases, so the compiled dependency graph no longer contains crypto-bigint 0.5.5 (RUSTSEC-2026-0387). This follows the k256 assessment in #223. Signing output does not change: golden vectors captured before the upgrade pass unchanged after it.

## Changes

- **k256 0.13 → 0.14** (ecdsa 0.17, elliptic-curve 0.14.3, crypto-bigint 0.7.11). `src/chain/userop.rs` changes in two places: `to_encoded_point(false)` becomes `to_sec1_point(false)`, and `sign_prehash_recoverable` now returns `(Signature, RecoveryId)` directly, so its `map_err` is gone. `SigningKey::from_slice` is unchanged.
- **crypto-bigint floor.** `k256` 0.14.0 requires `elliptic-curve` ^0.14.1, and `elliptic-curve` 0.14.0 and 0.14.1 accept the yanked, affected `crypto-bigint` 0.7.5. `Cargo.toml` now declares `elliptic-curve = "0.14.3"` directly (it requires `crypto-bigint` ^0.7.8, past the fix in 0.7.6), with a comment saying why.
- **ed25519-dalek 2 → 3, sha2 0.10 → 0.11, rand_core 0.6 → 0.10, getrandom 0.4 (`sys_rng`).** `rand_core::OsRng` is gone in 0.10:
  - Fallible byte fills use `getrandom::fill`: withdrawal idempotency keys and nonces, mutation request IDs, and the WebSocket upgrade nonce. `sign_websocket_upgrade` already returned a `Result`, so an OS randomness failure is now `Error::Transport`; it used to panic.
  - Infallible uses take `rand_core::UnwrapErr(getrandom::SysRng)`, which panics like `OsRng` did: `SigningKey::generate` in `generate_ed25519_keypair`, reconnect and resubscribe jitter, and test seeds.
  - None of these types appear in the public API.
- **`pub use k256;`** at the crate root. `chain::sign_safe_user_operation(&k256::ecdsa::SigningKey, ..)` keeps its signature, and callers can build keys as `polyester::k256::ecdsa::SigningKey` without a matching direct dependency. Its rustdoc gains a runnable example, and the README's smart-account section shows the same.
- **rust_decimal floor 1.43.** 1.43.0 drops its optional `rkyv` 0.7 dependency, so `rkyv` 0.7.46 (RUSTSEC-2026-0235) leaves `Cargo.lock`. This crate never enabled it.
- **CHANGELOG** (Unreleased): a breaking entry with the migration: build the key through `polyester::k256`, or move to `k256 = "0.14"`, plus `to_encoded_point` → `to_sec1_point`, `sign_prehash_recoverable` without `?`/`map_err`, and `SigningKey::random` taking a rand_core 0.10 RNG. There are no compatibility shims.

## Signing is bit-for-bit unchanged

Deterministic signatures may differ from earlier releases only for a prehash >= the secp256k1 group order; both are valid. k256 0.14 reduces such a prehash modulo the order n before it seeds the RFC 6979 nonce, as the RFC specifies; k256 0.13 seeded with the unreduced value. A keccak256 SafeOp hash reaches n with probability about 2^-128. `prehashes_at_the_group_order_sign_verifiably` signs prehashes n−1, n and n+1 with key scalar 1 and asserts that each signature passes `PrehashVerifier::verify_prehash` (and recovers to the signer's key). It compares against no earlier bytes.

For every other input, including all the vectors below:

The first commit adds `src/crypto_golden_tests.rs` and `testdata/crypto_golden_vectors.json`. It was generated and committed with k256 0.13 / ed25519-dalek 2 still in place, and passes there. The second commit upgrades the dependencies and leaves both files untouched (`git diff HEAD~1 -- src/crypto_golden_tests.rs testdata/` is empty), and they still pass.

- **secp256k1:** four owner keys (scalar 1, Hardhat #0, the EIP-155 example key, n−1) × three SafeOps (devnet empty, devnet call with gas and validity window, testnet with initCode, paymaster data and max values). For each pair the vectors pin the predicted Safe address, `r`, `s`, `v` and the packed signature from `sign_safe_user_operation`, plus the owner address derived from the key.
- **Ed25519:** three API-key seeds (the shared 00..1f test seed, all zeros, RFC 8032 test 1) × three `sign_payload` payloads, plus three signed requests (GET and POST, with a receive window and a binary body), pinning the `X-API-*` headers.
- **Coverage guards:** both `v` = 27 and 28 occur, every `s` is low-S, the owner addresses match the published addresses of the well-known keys, and RFC 8032 test 1 signs the empty message to its published signature.

## cargo audit (RustSec advisory DB, Cargo.lock)

cargo-audit 0.23.0 with the current RustSec advisory DB.

**Before (main, 2 vulnerabilities, 3 warnings):**

| Advisory | Crate | Kind | Title |
| --- | --- | --- | --- |
| RUSTSEC-2026-0387 | crypto-bigint 0.5.5 | vulnerability | Multiple timing variability issues in operations intended to be constant-time |
| RUSTSEC-2026-0235 | rkyv 0.7.46 | vulnerability | Insufficient archive validation can cause out-of-bounds reads in archives containing Rc/Arc |
| RUSTSEC-2026-0543 | chrono 0.4.45 | unmaintained | chrono is unmaintained |
| RUSTSEC-2024-0388 | derivative 2.2.0 | unmaintained | `derivative` is unmaintained; consider using an alternative |
| RUSTSEC-2024-0436 | paste 1.0.15 | unmaintained | paste - no longer maintained |

**After (this branch, 1 vulnerability, lockfile-only, 3 warnings):**

| Advisory | Crate | Kind | Title |
| --- | --- | --- | --- |
| RUSTSEC-2026-0387 | crypto-bigint 0.5.5 | vulnerability (not compiled, see below) | Multiple timing variability issues in operations intended to be constant-time |
| RUSTSEC-2026-0543 | chrono 0.4.45 | unmaintained | chrono is unmaintained |
| RUSTSEC-2024-0388 | derivative 2.2.0 | unmaintained | `derivative` is unmaintained; consider using an alternative |
| RUSTSEC-2024-0436 | paste 1.0.15 | unmaintained | paste - no longer maintained |

### Why crypto-bigint 0.5.5 is still in Cargo.lock

`alloy-primitives` (every release through the latest 1.7.3) declares an optional `k256 = "^0.13"` dependency behind its `k256` feature, which this crate does not enable. Cargo records optional dependencies in `Cargo.lock`, so `k256` 0.13.4 → `crypto-bigint` 0.5.5 stays listed there, and `cargo audit` reads the lockfile. No build of this crate compiles it:

```text
$ cargo tree -i [email protected] --all-features --target all -e all
warning: nothing to print.
$ cargo tree -i [email protected] --all-features --target all -e all
warning: nothing to print.
```

The same holds for `ecdsa` 0.16.9, `elliptic-curve` 0.13.8, `sha2` 0.10.9 and `rand_core` 0.6.4. The compiled graph has exactly one secp256k1 stack: `k256` 0.14.0 → `elliptic-curve` 0.14.3 → `crypto-bigint` 0.7.11.

The advisory is deliberately not suppressed in an audit config: a suppression would also hide it if a future feature change ever compiled it. It goes away when alloy-primitives moves its optional `k256` to 0.14. Upstream work on that: alloy-rs/core#1147 (open).

The unmaintained warnings are unchanged from #223: `chrono` and `derivative` are lockfile-only optional dependencies, and `paste` is a proc-macro of `alloy-primitives`.

## Local validation (Rust 1.90.0)

The CI workflow's checks, run locally:

- `python3 scripts/check_public_disclosure.py`, `gen_module_tree.py` (tree current), `check_sdk_coverage.py` and the release channel tests pass.
- `cargo fmt --all -- --check` and `cargo clippy --all-targets --all-features -- -D warnings` are clean.
- `cargo test --all-features --lib --test ui --test hardening --test a7_strict_live --test price_fixtures --test read_preservation --test server_unsubscribe --test standalone_tls` passes: lib 958 (three tests in `crypto_golden_tests` and one test for the OS-randomness paths are new), hardening 510, a7_strict_live 9, price_fixtures 16, read_preservation 2, server_unsubscribe 12, standalone_tls 1, ui 1.
- `cargo test --all-features --doc`: 52 passed (the `sign_safe_user_operation` example and the README `polyester::k256` example are new).
- `cargo test --all-features --all-targets --no-run` compiles every target, the credentialed integration suite and the examples included.
- `cargo package` verifies, and the packaged crate builds.
- The golden vectors were also run on the first commit, before the dependency change: 2/2 pass there.

## Not changed

- `fuzz/Cargo.lock` is refreshed at releases, as before. The fuzz crate depends on this crate by path, so it picks up the new versions when it next resolves.
nicoecheza added a commit to decentraland/dcl-one that referenced this pull request Nov 25, 2026
…RUSTSEC-2026-0387)

crypto-bigint 0.5.5 has operations meant to be constant-time that can
branch on secret values (RUSTSEC-2026-0387, fixed in 0.7.6). dcl-auth
reached it twice: through its own k256 0.13 and through alloy-primitives'
`k256` feature, which is still on k256 0.13 in the newest alloy-primitives
(1.7.3; alloy-rs/core#1147 moves it, unreleased). Wallet signs with a
secret key, so the fixed crate matters here, not only for verification.

- dcl-auth depends on k256 0.14 (crypto-bigint 0.7.11, ctutils 0.4.8)
  and recovers and signs with it directly; the address is keccak256 of
  the uncompressed key, as alloy computed it.
- The workspace's alloy-primitives drops its `k256` feature. The members
  that recover through alloy's Signature still get it through alloy's
  signer crates, so they build unchanged; dcl-auth no longer asks for it,
  and a service that depends only on dcl-auth no longer links k256 0.13.
- A test signs with the new code and with alloy's PrivateKeySigner for
  the same keys and messages and requires byte-identical signatures,
  addresses and public keys.
nicoecheza added a commit to decentraland/dcl-one that referenced this pull request Nov 25, 2026
…RUSTSEC-2026-0387)

crypto-bigint 0.5.5 has operations meant to be constant-time that can
branch on secret values (RUSTSEC-2026-0387, fixed in 0.7.6). dcl-auth
reached it twice: through its own k256 0.13 and through alloy-primitives'
`k256` feature, which is still on k256 0.13 in the newest alloy-primitives
(1.7.3; alloy-rs/core#1147 moves it, unreleased). Wallet signs with a
secret key, so the fixed crate matters here, not only for verification.

- dcl-auth depends on k256 0.14 (crypto-bigint 0.7.11, ctutils 0.4.8)
  and recovers and signs with it directly; the address is keccak256 of
  the uncompressed key, as alloy computed it.
- The workspace's alloy-primitives drops its `k256` feature. The members
  that recover through alloy's Signature still get it through alloy's
  signer crates, so they build unchanged; dcl-auth no longer asks for it,
  and a service that depends only on dcl-auth no longer links k256 0.13.
- A test signs with the new code and with alloy's PrivateKeySigner for
  the same keys and messages and requires byte-identical signatures,
  addresses and public keys.
nicoecheza added a commit to decentraland/dcl-one that referenced this pull request Nov 25, 2026
…RUSTSEC-2026-0387) (#2364)

crypto-bigint 0.5.5 has operations meant to be constant-time that can
branch on secret values (RUSTSEC-2026-0387, fixed in 0.7.6). dcl-auth
reached it twice: through its own k256 0.13 and through alloy-primitives'
`k256` feature, which is still on k256 0.13 in the newest alloy-primitives
(1.7.3; alloy-rs/core#1147 moves it, unreleased). Wallet signs with a
secret key, so the fixed crate matters here, not only for verification.

- dcl-auth depends on k256 0.14 (crypto-bigint 0.7.11, ctutils 0.4.8)
  and recovers and signs with it directly; the address is keccak256 of
  the uncompressed key, as alloy computed it.
- The workspace's alloy-primitives drops its `k256` feature. The members
  that recover through alloy's Signature still get it through alloy's
  signer crates, so they build unchanged; dcl-auth no longer asks for it,
  and a service that depends only on dcl-auth no longer links k256 0.13.
- A test signs with the new code and with alloy's PrivateKeySigner for
  the same keys and messages and requires byte-identical signatures,
  addresses and public keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants