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
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b5e12e5
restructure forc-crypto main file, introduce lib file
zees-dev Oct 22, 2024
4d14aa1
vanity address generation implementation with mnemonic option
zees-dev Oct 22, 2024
1ada623
forc-crypto vanity address unit tests
zees-dev Oct 22, 2024
43ab5e4
benchmarks for vanity address generation with and without mnemonic
zees-dev Oct 22, 2024
9b26daa
cargo.lock upd
zees-dev Oct 22, 2024
091ab69
fixed merge conflict
zees-dev Oct 22, 2024
6cc649a
fixed cargo clippy errors
zees-dev Oct 22, 2024
723db3e
added timeout to vanity address generation
zees-dev Oct 23, 2024
e493891
added helpful stdout for count of addresses traversed and generation …
zees-dev Oct 23, 2024
b16c926
moved up pattern length check higher before hex decoding
zees-dev Oct 23, 2024
1575f45
Merge branch 'master' into forc-crypto/vanity-address-generation
zees-dev Oct 23, 2024
f4bb7b6
fixed cargo clippy errors
zees-dev Oct 23, 2024
2cab730
Merge branch 'master' into forc-crypto/vanity-address-generation
zees-dev Oct 23, 2024
0c18bb8
fixed dependency sorting
zees-dev Oct 23, 2024
1dd7915
fixed dependency sorting
zees-dev Oct 23, 2024
e8dc206
fixed dependency sorting
zees-dev Oct 23, 2024
59ab719
refactor to introduce explicit regex pattern matching; updated unit t…
zees-dev Oct 24, 2024
5332e15
updated benchmarks
zees-dev Oct 24, 2024
6746af4
updated help text for args
zees-dev Oct 24, 2024
a55fbb6
forc vanity examples
zees-dev Oct 24, 2024
80ca7a2
moved hex and regex validation to clap CLI parser
zees-dev Oct 24, 2024
615c52b
updated unit tests
zees-dev Oct 24, 2024
887ed2d
fixed issue without timeout not being respected
zees-dev Oct 24, 2024
5f284cd
output checksummed address
zees-dev Oct 24, 2024
5a850d2
removed regex pattern constraint for matching lowercase ascii chars
zees-dev Oct 24, 2024
b73da0f
Merge branch 'master' into forc-crypto/vanity-address-generation
sdankel Oct 24, 2024
e9023ae
Merge branch 'master' into forc-crypto/vanity-address-generation
zees-dev Oct 24, 2024
9b322e0
Merge branch 'master' into forc-crypto/vanity-address-generation
zees-dev Oct 24, 2024
1047cf3
fixed doc test
zees-dev Oct 24, 2024
5633b6a
Merge branch 'master' into forc-crypto/vanity-address-generation
kayagokalp Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions forc-plugins/forc-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ forc-tracing.workspace = true
forc-util.workspace = true
fuel-core-types.workspace = true
fuel-crypto = { workspace = true, features = ["random"] }
fuels-accounts.workspace = true
fuels-core.workspace = true
futures.workspace = true
hex.workspace = true
libp2p-identity = { workspace = true, features = ["peerid", "secp256k1"] }
rand.workspace = true
rayon.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
sha3.workspace = true
termion.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "process"] }
tracing.workspace = true

[dev-dependencies]
criterion = "0.5"
tempfile.workspace = true

[[bench]]
name = "bench_main"
harness = false
73 changes: 73 additions & 0 deletions forc-plugins/forc-crypto/benches/bench_main.rs
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);
1 change: 1 addition & 0 deletions forc-plugins/forc-crypto/src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::ValueEnum;
pub mod get_public_key;
pub mod new_key;
pub mod parse_secret;
pub mod vanity;

#[derive(Clone, Debug, Default, ValueEnum)]
pub enum KeyType {
Expand Down
Loading
Loading