-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forc-crypto: vanity address generation (#6661)
## Description Support for Bech32 case-insensitive vanity address generation via `forc-crypto` CLI tool. Usage: ```sh 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 ```sh # > 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 ``` ```sh # > 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 - #6664 --------- Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
- Loading branch information
1 parent
31974b4
commit 058f4e2
Showing
8 changed files
with
595 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use forc_crypto::keys::vanity::{find_vanity_address_with_timeout, HexMatcher, RegexMatcher}; | ||
use rayon::iter::Either; | ||
|
||
fn benchmark_vanity_address(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Vanity Address Generation"); | ||
|
||
// Benchmark HexMatcher with prefix | ||
group.bench_function("HexMatcher (starts with 'a')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Right(HexMatcher::new("a", "").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), false, None) | ||
}) | ||
}); | ||
|
||
// Benchmark HexMatcher with suffix | ||
group.bench_function("HexMatcher (ends with 'f')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Right(HexMatcher::new("", "f").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), false, None) | ||
}) | ||
}); | ||
|
||
// Benchmark HexMatcher with both prefix and suffix | ||
group.bench_function("HexMatcher (starts with 'a' ends with 'f')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Right(HexMatcher::new("a", "f").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), false, None) | ||
}) | ||
}); | ||
|
||
// Benchmark RegexMatcher with simple pattern | ||
group.bench_function("RegexMatcher (starts with 'a')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Left(RegexMatcher::new("^a.*").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), false, None) | ||
}) | ||
}); | ||
|
||
// Benchmark RegexMatcher with complex pattern | ||
group.bench_function("RegexMatcher (contains two consecutive digits)", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Left(RegexMatcher::new(r"[0-9]{2}").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), false, None) | ||
}) | ||
}); | ||
|
||
// Benchmark with mnemonic generation | ||
group.bench_function("HexMatcher with Mnemonic (starts with 'a')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Right(HexMatcher::new("a", "").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), true, None) | ||
}) | ||
}); | ||
|
||
group.bench_function("RegexMatcher with Mnemonic (starts with 'a')", |b| { | ||
b.iter(|| { | ||
let matcher = Either::Left(RegexMatcher::new("^a.*").unwrap()); | ||
find_vanity_address_with_timeout(black_box(matcher), true, None) | ||
}) | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default() | ||
.sample_size(10) // Reduced sample size due to potentially long-running benchmarks | ||
.measurement_time(std::time::Duration::from_secs(20)); | ||
targets = benchmark_vanity_address | ||
} | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.