Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forc-crypto: vanity address generation #6661

Merged
merged 30 commits into from
Oct 25, 2024

Conversation

zees-dev
Copy link
Contributor

@zees-dev zees-dev commented Oct 22, 2024

Description

Support for Bech32 case-insensitive vanity address generation via forc-crypto CLI tool.

Usage:

forc-crypto vanity --help

CLI options:

Generate a vanity address

Usage: forc-crypto vanity [OPTIONS]

Options:
      --starts-with <HEX_STRING>  Desired hex string prefix for the address
      --ends-with <HEX_STRING>    Desired hex string suffix for the address
      --regex <PATTERN>           Desired regex pattern to match the entire address (case-insensitive)
      --timeout <SECONDS>         Timeout in seconds for address generation
      --mnemonic                  Return mnemonic with address (default false)
      --save-path <PATH>          Path to save the generated vanity address to
  -h, --help                      Print help
  -V, --version                   Print version

Generate vanity addresses for the Fuel blockchain

Example outputs

# > forc-crypto vanity --starts-with 0 --ends-with F

Starting to generate vanity address...
Successfully found vanity address in 0.012 seconds.
Address: 0d3c399e756dee9f7312215882f92685fdae25449bc74f33c31063000d68afdf
PrivateKey: cec536d4f5aae64685856ad36818777ba0aed349bdef848b487d6ebb1cc2a0a4
# > forc-crypto vanity --starts-with 0 --ends-with F --mnemonic

Starting to generate vanity address...
Successfully found vanity address in 0.141 seconds.
Address: 030b8484305c9f3af7b662d9fdd88dc75bdceb29f42d0f5ea5f72d3dfaf9380f
Mnemonic: found broccoli trap left thought attack quality smooth patrol enrich fault flavor legend amused monitor shoulder legend blast elbow custom dirt cotton tackle much
PrivateKey: 269ee26dd810a4a2df72969ed8941fe92ddc0bab236715535b867448c3ffa25e

Relevant issues

@zees-dev zees-dev requested review from a team as code owners October 22, 2024 08:39
@zees-dev zees-dev added enhancement New feature or request forc labels Oct 22, 2024
@zees-dev zees-dev force-pushed the forc-crypto/vanity-address-generation branch from cf8dbc0 to afd326b Compare October 22, 2024 08:48
@zees-dev zees-dev force-pushed the forc-crypto/vanity-address-generation branch from afd326b to 9b26daa Compare October 22, 2024 08:49
@zees-dev zees-dev self-assigned this Oct 22, 2024
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

Hey @zees-dev, Nice job on your first PR!

I will be leaving a second review that actually checks the code but to start with can you:

  1. run cargo clippy
  2. format the forc-crypto Cargo.toml file, basically the order of dependencies needs to be alphabetical
  3. Ensure that root Cargo.lock file is free of conflicts.

@kayagokalp
Copy link
Member

kayagokalp commented Oct 22, 2024

Also if you use closes #6684 in PR description. Github automatically marks the relevant issue to be closed after this PR is merged.

Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

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

Just a couple of suggestions. Great to see the benchmarking and tests added for this.

@JoshuaBatty JoshuaBatty requested a review from a team October 22, 2024 23:14
@alfiedotwtf
Copy link
Contributor

Nice!

Quick question - is there a big difference in timings between random vs mnemonic? I'm thinking it would always be a good idea to provide the mnemonic by default and if they're close in timing we should only provide that pathway... but if the performance of random is way faster, then yeah let's keep both.

@zees-dev
Copy link
Contributor Author

zees-dev commented Oct 23, 2024

Nice!

Quick question - is there a big difference in timings between random vs mnemonic? I'm thinking it would always be a good idea to provide the mnemonic by default and if they're close in timing we should only provide that pathway... but if the performance of random is way faster, then yeah let's keep both.

There is a difference in timing; quite significant actually; here is benchmark:

#> cargo bench -p forc-crypto

     Running benches/bench_main.rs (target/release/deps/bench_main-1a9598fa5a6f3ca5)
Gnuplot not found, using plotters backend
Vanity Address Generation/HexMatcher (starts with 'a')
                        time:   [99.431 µs 99.820 µs 100.43 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe
Vanity Address Generation/HexMatcher (ends with 'f')
                        time:   [99.885 µs 100.33 µs 100.80 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) low mild
Vanity Address Generation/HexMatcher (starts with 'a' ends with 'f')
                        time:   [646.08 µs 661.15 µs 687.66 µs]
                        change: [-6.2211% -2.6757% +0.8480%] (p = 0.19 > 0.05)
                        No change in performance detected.
Vanity Address Generation/RegexMatcher (starts with 'a')
                        time:   [189.04 µs 190.52 µs 192.36 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild
Vanity Address Generation/RegexMatcher (contains two consecutive digits)
                        time:   [217.57 µs 223.00 µs 230.51 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe
Vanity Address Generation/HexMatcher with Mnemonic (starts with 'a')
                        time:   [4.7431 ms 4.8189 ms 4.8840 ms]
Found 2 outliers among 10 measurements (20.00%)
  1 (10.00%) low severe
  1 (10.00%) high mild
Vanity Address Generation/RegexMatcher with Mnemonic (starts with 'a')
                        time:   [4.8460 ms 4.9052 ms 4.9625 ms]
Found 4 outliers among 10 measurements (40.00%)
  1 (10.00%) low severe
  1 (10.00%) low mild
  2 (20.00%) high mild

forc-plugins/forc-crypto/src/keys/vanity.rs Outdated Show resolved Hide resolved
forc-plugins/forc-crypto/src/keys/vanity.rs Outdated Show resolved Hide resolved
forc-plugins/forc-crypto/src/keys/vanity.rs Show resolved Hide resolved
forc-plugins/forc-crypto/src/keys/vanity.rs Outdated Show resolved Hide resolved
forc-plugins/forc-crypto/src/keys/vanity.rs Outdated Show resolved Hide resolved
forc-plugins/forc-crypto/src/lib.rs Show resolved Hide resolved
Cargo.lock Show resolved Hide resolved
alfiedotwtf
alfiedotwtf previously approved these changes Oct 24, 2024
sdankel
sdankel previously approved these changes Oct 24, 2024
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

Looks good! :shipit:

kayagokalp
kayagokalp previously approved these changes Oct 24, 2024
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@kayagokalp
Copy link
Member

I think only thing left in CI is to fix the tests generated by forc_util::cli_examples! macro.

@zees-dev zees-dev dismissed stale reviews from sdankel and kayagokalp via 1047cf3 October 24, 2024 23:13
Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

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

Great work!

@zees-dev zees-dev merged commit 058f4e2 into master Oct 25, 2024
38 checks passed
@zees-dev zees-dev deleted the forc-crypto/vanity-address-generation branch October 25, 2024 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request forc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants