Skip to content

Monero Key Generation fails if the key would have trailing zeroes

This code

let mut seed_arr = [0; 32];
seed_arr.clone_from_slice(&hex::decode("6734c05d337c2f4883eb710bc02be1c30f1b2d46b2657c46cc833eecb7d7cb10").unwrap());
let wallet = wallet_gen::cryptonote::from_seed(wallet_gen::coin::Coin::Monero, seed_arr)?;
println!("Private Key: {}", &wallet.private_key);

prints

Private Key: 7a60ca0019191df0ac4e7a68e13102af0f1b2d46b2657c46cc833eecb7d7cb30

This is wrong. Correct would be

Private Key: 7a60ca0019191df0ac4e7a68e13102af0f1b2d46b2657c46cc833eecb7d7cb00

which was generated with this code using the wagyu-monero library:

    let private_key =
        wagyu_monero::private_key::MoneroPrivateKey::<wagyu_monero::network::Mainnet>::from_seed(
            "6734c05d337c2f4883eb710bc02be1c30f1b2d46b2657c46cc833eecb7d7cb10",
            &wagyu_monero::format::MoneroFormat::Standard,
        )
        .unwrap();
    println!(
        "Private Key: {}",
        hex::encode(private_key.to_private_spend_key())
    );

My guess is that wallet-gen erroneously truncates the trailing zeroes somewhere in the calculation.