Skip to content

Conversation

@UdjinM6
Copy link

@UdjinM6 UdjinM6 commented Jun 22, 2023

Issue being fixed or feature implemented

Allow generating 12, 18, 24 words mnemonics. Default to 12 words as it's the most popular option/de-facto a standard now imo.

What was done?

Add -mnemonicbits option, add tests

How Has This Been Tested?

run tests, play with wallets on regtest

Breaking Changes

n/a, old wallets should not be affected

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

UdjinM6 added 2 commits June 22, 2023 23:41
Add `-mnemonicbits` cmd-line option
to be more compatible with most wallets out there
@UdjinM6 UdjinM6 added this to the 20 milestone Jun 22, 2023
@PastaPastaPasta
Copy link
Member

I like the relatively small diff; has bitcoin never implemented something like this? If so we should probably just take their implementation, but I'm guessing that you looked already. Only other thing is why default to 12 words? It does seem slightly debated still what level is for sure fine, and seems to me best to err on the high end, no?

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

noticed couple more things when carefully checked, see comments.


@PastaPastaPasta

has bitcoin never implemented something like this?

$ grep -r biology bitcoin/ #one of the words from bip39
<nothing>

I suppose they doesn't have anything similar at least in core. Some application such as android wallet or 3rd party wallets have this feature.

Only other thing is why default to 12 words

dash's android app and 'Bitcoin wallet' both have 12 mnemonic words.

@@ -0,0 +1,43 @@
#!/usr/bin/env python3
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing executable flag on wallet_mnemonicbits.py: chmod +x wallet_mnemonicbits.py


argsman.AddArg("-hdseed=<hex>", "User defined seed for HD wallet (should be in hex). Only has effect during wallet creation/first start (default: randomly generated)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::WALLET_HD);
argsman.AddArg("-mnemonic=<text>", "User defined mnemonic for HD wallet (bip39). Only has effect during wallet creation/first start (default: randomly generated)", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::WALLET_HD);
argsman.AddArg("-mnemonicbits=<n>", strprintf("User defined mnemonic security for HD wallet in bits (BIP39). Only has effect during wallet creation/first start (allowed values: 128, 192, 256; default: %u)", CHDChain::DEFAULT_MNEMONIC_BITS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET_HD);
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't 160 also accepted as a correct value?

    // check number of words
    if (nWordCount != 12 && nWordCount != 18 && nWordCount != 24) {
        return false;
    }

but when it's generated:

    if (strength % 32 || strength < 128 || strength > 256) {

Probably should be updated 32 to 64: otherwise Generate() is happy with 160 bits, 224 bits but CMnemonic::Check later fails with error: mnemonic with 15 words are invalid mnemonic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tested it with modified script:

--- a/test/functional/wallet_mnemonicbits.py
+++ b/test/functional/wallet_mnemonicbits.py
@@ -28,6 +28,8 @@ class WalletMnemonicbitsTest(BitcoinTestFramework):
         assert_equal(len(self.nodes[0].dumphdinfo()["mnemonic"].split()), 12)  # 12 words by default
 
         self.log.info("Can have multiple wallets with different mnemonic length loaded at the same time")
+        self.restart_node(0, extra_args=self.extra_args[0] + ["-mnemonicbits=160"])
+        self.nodes[0].createwallet("wallet_160")
         self.restart_node(0, extra_args=self.extra_args[0] + ["-mnemonicbits=192"])
         self.nodes[0].createwallet("wallet_192")
         self.restart_node(0, extra_args=self.extra_args[0] + ["-mnemonicbits=256"])
@@ -35,6 +37,7 @@ class WalletMnemonicbitsTest(BitcoinTestFramework):
         self.nodes[0].createwallet("wallet_256", False, True)  # blank
         self.nodes[0].get_wallet_rpc("wallet_256").upgradetohd()
         assert_equal(len(self.nodes[0].get_wallet_rpc(self.default_wallet_name).dumphdinfo()["mnemonic"].split()), 12)  # 12 words by default
+        assert_equal(len(self.nodes[0].get_wallet_rpc("wallet_160").dumphdinfo()["mnemonic"].split()), 15)              # 15 words

...

test_framework.authproxy.JSONRPCException: SetMnemonic: invalid mnemonic: `noise glow drift unveil intact fruit mind add claim ankle pumpkin cheap come tuna win` (-1)

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

slightly tested ACK

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

utACK for squash merge

Copy link

@ogabrielides ogabrielides left a comment

Choose a reason for hiding this comment

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

utACK

@UdjinM6 UdjinM6 merged commit d97ec35 into dashpay:develop Jun 28, 2023
@UdjinM6 UdjinM6 deleted the mnemonic_bits branch June 28, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants