mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-09 05:08:17 +00:00

## 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 - https://github.com/FuelLabs/sway/issues/6664 --------- Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
73 lines
2.7 KiB
Rust
73 lines
2.7 KiB
Rust
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);
|