Skip to content

num-traits 0.2.19 breaks wasm32 compilation for runtimes using arkworks cryptography #10953

@nol4lej

Description

@nol4lej

Building a Substrate runtime that uses arkworks cryptography libraries (ark-bn254, ark-groth16, etc.) fails during wasm32 compilation due to sp-arithmetic's transitive dependency on num-traits 0.2.19, which has critical trait method ambiguity bugs (E0034) in no-std environments.

Environment

  • Rust version: 1.93.0
  • polkadot-sdk: stable2506 branch
  • Target: wasm32v1-none (no-std)
  • Build context: wasm-builder with SKIP_WASM_BUILD="", BUILD_DUMMY_WASM_BINARY disabled

Arkworks libraries in use:

ark-bn254 = { version = "0.4.0", default-features = false, features = ["curve"] }
ark-ec = { version = "0.4.0", default-features = false }
ark-ff = { version = "0.4.0", default-features = false }
ark-groth16 = { version = "0.4.0", default-features = false }
ark-serialize = { version = "0.4.0", default-features = false }
ark-std = { version = "0.4.0", default-features = false }
ark-scale = { version = "0.0.11", default-features = false, features = ["hazmat"] }

Use case:
Building a Substrate runtime with ZK-SNARK verification capabilities (Groth16 proofs on BN254 curve) for private transactions using a shielded pool pallet. The primitives include:

  • fp-zk-primitives: Native cryptographic primitives (Poseidon hash, commitment schemes)
  • fp-zk-verifier: Groth16 proof verification using arkworks
  • pallet-shielded-pool: Runtime pallet for private transactions

Root Cause
Dependency chain:

orbinum-runtime (wasm32v1-none, no-std)
  └─ sp-arithmetic v27.0.0 (stable2506)
      └─ integer-sqrt (workspace dependency)
          └─ num-traits 0.2.19 (with std feature incorrectly enabled)

When wasm-builder compiles the runtime for wasm32v1-none target:

  • sp-arithmetic pulls in integer-sqrt
  • integer-sqrt depends on num-traits 0.2.19
  • num-traits 0.2.19 has the std feature activated somehow (bug in feature resolution)
  • Compilation fails because wasm32v1-none doesn't support std library

Complete Error Output

Executing build command: env -u CARGO_ENCODED_RUSTFLAGS -u RUSTC \
  CARGO_TARGET_DIR="/path/to/target/release/wbuild/orbinum-runtime/target" \
  RUSTFLAGS="-C link-arg=--export-table -C link-arg=--export=__heap_base \
             -C link-arg=--import-memory --cfg substrate_runtime" \
  cargo rustc --target=wasm32v1-none --manifest-path=.../Cargo.toml \
  --color=always --profile release

Compiling num-traits v0.2.19
error[E0463]: can't find crate for `std`
  --> num-traits-0.2.19/src/lib.rs:23:1
   |
23 | extern crate std;
   | ^^^^^^^^^^^^^^^^^ can't find crate
   |
   = note: the `wasm32v1-none` target may not support the standard library

error[E0034]: multiple applicable items in scope
  --> num-traits-0.2.19/src/float.rs:837:15
   |
837 |         Self::floor(self) -> Self;
    |               ^^^^^ multiple `floor` found
    |
note: candidate #1 is defined in an impl of the trait `Float` for the type `f64`
  --> num-traits-0.2.19/src/macros.rs:9:13
   |
 9 |             fn $method(self $( , $arg : $ty )* ) -> $ret {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
2080 | float_impl_std!(f64 integer_decode_f64);
     | --------------------------------------- in this macro invocation

note: candidate #2 is defined in an impl of the trait `FloatCore` for the type `f64`
  --> num-traits-0.2.19/src/macros.rs:9:13
   |
 9 |               fn $method(self $( , $arg : $ty )* ) -> $ret {
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
898 | /     forward! {
899 | |         Self::floor(self) -> Self;
900 | |         Self::ceil(self) -> Self;
901 | |         Self::round(self) -> Self;
...
906 | |         Self::powi(self, n: i32) -> Self;
907 | |     }
    | |_____- in this macro invocation

[... 27 more similar E0034 errors for ceil, round, trunc, fract, powi ...]

error[E0308]: arguments to this function are incorrect
  --> num-traits-0.2.19/src/ops/euclid.rs:77:17
   |
77 |                 <$t>::div_euclid(*self, *v)
   |                 ^^^^^^^^^^^^^^^^ -----  -- expected `&f32`, found `f32`
   |                                  |
   |                                  expected `&f32`, found `f32`
...
92 | euclid_forward_impl!(f32 f64);
   | ----------------------------- in this macro invocation

[... 3 more E0308 errors for div_euclid/rem_euclid ...]

error: could not compile `num-traits` (lib) due to 29 previous errors

num-traits issue:
rust-num/num-traits#374

Greetings!

Metadata

Metadata

Assignees

No one assigned

    Labels

    I10-unconfirmedIssue might be valid, but it's not yet known.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions