cpubits: promoting wasm32 to 64-bit makes k256 0.14 up to 3.3x slower in Wasm (p256 0.14 is faster)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 15/100
- Type d'issue
- Fonctionnalité
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- rust, wasm
- Domaine
- cryptography, performance
Piste de recherche
This is a design question, not a scoped edit: the measurements are clear, but the choice between per-crate field selection and a documented trade-off is unresolved. Start by reading the cpubits documentation in this repo and the field-backend selection in k256 (5x52 vs 10x26) and p256, then reproduce the wasmtime-fuel numbers with wasm32-unknown-unknown before proposing anything. Done means either a decision recorded in the thread or a docs change describing the k256/p256 split.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
The cpubits docs ask for an issue when overriding its detection, so here is why we now build our Wasm code (Internet Computer canisters, wasm32-unknown-unknown) with --cfg cpubits="32" (dfinity/ic#12234).
With the default promotion of wasm32 to 64-bit, k256 0.14 uses its 5x52 field. Wasm has no 64×64→128-bit multiply, so the limb products go through the compiler's __multi3 helper, and k256 0.14 needs up to 3.3x the Wasm instructions of k256 0.13, which used the 10x26 field on wasm32. With cpubits="32", k256 0.14 is back to about 0.13's cost or below. p256 0.14 goes the other way: it signs and verifies about 1.5x faster with 64-bit limbs.
Executed Wasm instructions per operation (wasmtime fuel, one unit per instruction) for wasm32-unknown-unknown, built with rustc 1.100.0, opt-level=3, fat LTO, codegen-units=1 and -C target-feature=+bulk-memory. Versions: k256 0.13.4/0.14.0 and p256 0.13.2/0.14.0 (0.14 with precomputed-tables and std), p384 0.13.1/0.14.0 (0.14 with --cfg p384_backend="fiat"), crypto-bigint 0.7.11, cpubits 0.1.1. The outputs are identical in every configuration.
| Operation | 0.13 | 0.14, default (64-bit on wasm32) |
0.14, cpubits="32" |
|---|---|---|---|
| k256 public key decompression | 159,236 | 521,996 (3.28x) | 160,591 (1.01x) |
k256 verify_prehash |
3,768,545 | 6,600,992 (1.75x) | 2,580,879 (0.68x) |
k256 sign_prehash |
2,273,571 | 2,876,293 (1.27x) | 1,788,025 (0.79x) |
k256 P + t·G |
1,310,714 | 2,533,486 (1.93x) | 1,376,993 (1.05x) |
| k256 basepoint table build (once) | 4,338,964 | 12,895,507 (2.97x) | 4,478,362 (1.03x) |
| p256 public key decompression | 530,406 | 772,670 (1.46x) | 722,298 (1.36x) |
p256 sign_prehash |
12,302,904 | 3,246,229 (0.26x) | 4,677,611 (0.38x) |
p256 verify_prehash |
20,573,873 | 12,285,808 (0.60x) | 18,214,871 (0.89x) |
| p384 public key decompression | 2,324,050 | 3,335,435 (1.44x) | 2,459,178 (1.06x) |
p384 verify_prehash |
92,446,932 | 47,516,383 (0.51x) | 49,705,285 (0.54x) |
The k256 code also gets smaller: our canisters that use k256 shrink by 7.6 to 20.8 KB gzipped with cpubits="32".
So on wasm32 the better limb size depends on the crate: 32-bit for k256, 64-bit for p256, and mixed for the fiat-based p384. As the setting has to be consistent across crypto-bigint and the curve crates built on it, one global choice can't get both. We picked 32-bit because our canisters run secp256k1 code but no P-256 code. Would it make sense for k256 to choose its field representation on wasm32 separately from the cpubits result, if nothing else in k256 depends on it, or otherwise to mention this trade-off in the cpubits docs?
🤖 Generated with Claude Code
- Langage dominant
- Rust
- Étoiles
- 695
- Forks
- 185
- Merge moyen
- 10 h 40 min
- PR mergées (30 j)
- 24
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de RustCrypto/utils
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
RustCrypto/utils#1555 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
RustCrypto/utils#1546 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
cpufeatures: aarch64 Linux reports aes, sha3 and sm4 when only one of their two HWCAPs is setPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
RustCrypto/utils#1627 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
RustCrypto/utils#1621 · 17 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 Moins d'une heure Accessibilité débutants 15/100
RustCrypto/utils#1617 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de RustCrypto/utils
Issues similaires
-
The new tests repeat each other and one only checks a two-line helperPeut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. Ouverteinfra
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
storytold/wordcraft#9405 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
in-progress
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
area: ai-assistants documentation help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
BetaBots-LLC/latticegate#17 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 94/100
storytold/craft-libs#5594 ·
Les mainteneurs répondent en général sous 1 jour
-
available documentation good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Nixitov/Riptide-Native#932 ·
Les mainteneurs répondent en général sous 1 jour