Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

key generate subcommand silently coerces any word count other than 12 to 24 words

Aperta Adatta ai principianti
#362 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Inizia individuando KeySubCommand::Generate e il parser dell’argomento word_count descritto nell’issue. Controlla come il comando associa i valori analizzati a bdk_wallet::keys::bip39::WordCount, quindi esegui i test CLI pertinenti oppure prova gli esempi con 15 parole e con un valore non valido. Il lavoro è completato quando vengono accettate tutte e cinque le lunghezze supportate e i valori non supportati vengono rifiutati con un messaggio che elenca le opzioni valide.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Describe the bug

key generate accepts any integer for --word-count but only distinguishes 12 from everything else. The match arm is:

let mnemonic_type = match self.word_count {
    12 => WordCount::Words12,
    _ => WordCount::Words24,
};

So --word-count 15 produces a 24-word mnemonic, --word-count 0 produces a 24-word mnemonic, and --word-count 999 produces a 24-word mnemonic. No error, no warning, no indication that the requested value was ignored. BIP39 defines five valid lengths: 12, 15, 18, 21, 24 and bdk_wallet::keys::bip39 WordCount already support all five, so the restriction is purely in the CLI's argument handling.

To Reproduce

  1. Request a 15-word mnemonic:
    bdk-cli key generate --word-count 15
    
  2. Count the words in the output: it is 24, not 15.
  3. Confirm nonsense values are also accepted without error:
    bdk-cli key generate --word-count 0
    
    This also produces 24 words.

Expected behavior

--word-count 15 should produce a 15-word mnemonic, since the library supports it. Invalid values such as 0, 13, or 999 should be rejected at parse time with a message listing the valid options, not silently coerced. PossibleValuesParser or a custom value_parser handles both:

#[arg(
    long = "word-count",
    short = 'w',
    default_value = "WordCount::Words12",
    value_parser = word_count_parser
)]
pub word_count: WordCount,

in the word_count_parser:

let word_count = match word_count {
    "12" => WordCount::Words12,
    "15" => WordCount::Words15,
    "18" => WordCount::Words18,
    "21" => WordCount::Words21,
    "24" => WordCount::Words24,
    _ => return(Error::Generic("...")), 
};

The change is confined to KeySubCommand::Generate; no library or API changes are needed.

Build environment

· BDK-CLI tag/commit: main
· OS+version: macOS 12.7.6 (Monterey)
· Rust/Cargo version: rustc --version output
· Rust/Cargo target: x86_64-apple-darwin

Additional context

The silent coercion means a user's request is never honoured unless it happens to be exactly 12, and the failure mode is invisible. The command just succeeds and returns a valid mnemonic of the wrong length. Since usize parsing already rejects negative values, the only way to reach the match arm with an unintended value is a typo or an unsupported length, and both currently produce 24 words with no diagnostic. Validating at the clap boundary fixes both the missing lengths and the silent acceptance in a single change.

Lingua principale
Rust
Stelle
143
Fork
103
Merge medio
2g 9h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bitcoindevkit/bdk-cli

Tutte le issue di bitcoindevkit/bdk-cli

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.