-
Notifications
You must be signed in to change notification settings - Fork 109
vanity move address #1229
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
Open
Primata
wants to merge
12
commits into
main
Choose a base branch
from
vanity-address
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
vanity move address #1229
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e445e8
vanity move address
Primata 51575dd
specify flag issue
Primata efdf8ae
Update util/vanity/README.md
Primata 7ae6945
workspace deps
Primata 31a1cc2
fix: works in nix
Primata 22584ae
Merge branch 'vanity-address' of https://github.com/movementlabsxyz/m…
Primata 2785ce8
fix: tracing
Primata b5085df
revert tracing
Primata 7066565
add cli tests
Primata dc4edb5
feat: vanity resource address
Primata 76a8442
chore: cargo fmt
andygolay ca8b748
fix: refactor according to liam's desire
Primata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 @@ | ||
/target |
This file contains hidden or 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,13 @@ | ||
[package] | ||
name = "vanity" | ||
version = "0.2.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
aptos-sdk = { workspace = true } | ||
rand = { workspace = true } | ||
rayon = { workspace = true } | ||
hex = { workspace = true } | ||
clap = { workspace = true } | ||
thiserror = { workspace = true } | ||
num_cpus = { workspace = true } |
This file contains hidden or 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,18 @@ | ||
# Vanity 🧂⛏️ | ||
|
||
Vanity is a CLI for mining vanity move addresses. | ||
|
||
Vanity is heavily inspired by [Create2Crunch](https://github.com/0age/create2crunch). | ||
|
||
## Installation | ||
|
||
```bash | ||
git clone https://github.com/movementlabsxyz/movement.git | ||
cd movement | ||
# Run it directly | ||
cargo run -p vanity --release -- move --starts-pattern <STARTS_PATTERN> --ends-pattern <ENDS_PATTERN> | ||
|
||
cd util/vanity | ||
# Add it to your path | ||
cargo install --path . | ||
``` |
This file contains hidden or 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,61 @@ | ||
use std::{ops::Deref, str::FromStr}; | ||
|
||
/// Pattern. | ||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub(super) struct Pattern(Box<str>); | ||
|
||
impl Deref for Pattern { | ||
type Target = str; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Pattern { | ||
pub(super) fn into_bytes(self) -> Result<Vec<u8>, hex::FromHexError> { | ||
let mut string = self.to_string(); | ||
|
||
if self.len() % 2 != 0 { | ||
string += "0" | ||
}; | ||
|
||
hex::decode(string) | ||
} | ||
} | ||
|
||
/// Pattern errors. | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)] | ||
Primata marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pub(super) enum PatternError { | ||
#[error("the pattern's length exceeds 39 characters or the pattern is empty")] | ||
InvalidPatternLength, | ||
#[error("the pattern is not in hexadecimal format")] | ||
NonHexPattern, | ||
} | ||
|
||
impl FromStr for Pattern { | ||
type Err = PatternError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.len() >= 40 || s.is_empty() { | ||
return Err(PatternError::InvalidPatternLength); | ||
} | ||
|
||
if s.chars().any(|c| !c.is_ascii_hexdigit()) { | ||
return Err(PatternError::NonHexPattern); | ||
} | ||
|
||
Ok(Self(s.into())) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, clap::Parser)] | ||
#[command(name = "vanity", about = "Vanity is a fast vanity address miner.")] | ||
pub(super) enum Vanity { | ||
Move { | ||
Primata marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#[clap(long)] | ||
starts_pattern: Option<String>, | ||
#[clap(long)] | ||
ends_pattern: Option<String>, | ||
}, | ||
} |
This file contains hidden or 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,33 @@ | ||
mod cli; | ||
Primata marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
mod miner; | ||
|
||
use std::str::FromStr; | ||
use clap::Parser; | ||
use cli::{Pattern, Vanity}; | ||
use miner::mine_move_address; | ||
use num_cpus; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
match Vanity::parse() { | ||
Vanity::Move { starts_pattern, ends_pattern } => { | ||
let starts_pattern_bytes = match starts_pattern { | ||
Some(p) => Pattern::from_str(&p)?.into_bytes()?, | ||
None => vec![], | ||
}; | ||
let ends_pattern_bytes = match ends_pattern { | ||
Some(p) => Pattern::from_str(&p)?.into_bytes()?, | ||
None => vec![], | ||
}; | ||
|
||
let account = mine_move_address( | ||
&starts_pattern_bytes, | ||
&ends_pattern_bytes, | ||
num_cpus::get(), | ||
); | ||
|
||
println!("Found Move address: {}", account.address()); | ||
0xmovses marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
println!("Private key (hex): {}", hex::encode(account.private_key().to_bytes())); | ||
0xmovses marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return Ok(()); | ||
} | ||
} | ||
} |
This file contains hidden or 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,55 @@ | ||
use aptos_sdk::types::{account_address::AccountAddress, LocalAccount}; | ||
use rand::thread_rng; | ||
use rayon::prelude::*; | ||
use rayon::ThreadPoolBuilder; | ||
use std::sync::{ | ||
atomic::{AtomicBool, Ordering}, | ||
Arc, Mutex, | ||
}; | ||
use std::time::Instant; | ||
|
||
fn matches_pattern(addr: &AccountAddress, start: &[u8], end: &[u8]) -> bool { | ||
let addr_bytes = addr.to_vec(); | ||
(start.is_empty() || addr_bytes.starts_with(start)) && | ||
(end.is_empty() || addr_bytes.ends_with(end)) | ||
} | ||
|
||
pub fn mine_move_address( | ||
starts_pattern: &[u8], | ||
ends_pattern: &[u8], | ||
threads: usize, | ||
) -> LocalAccount { | ||
let found = Arc::new(AtomicBool::new(false)); | ||
let result = Arc::new(Mutex::new(None)); | ||
let start_time = Instant::now(); | ||
|
||
let pool = ThreadPoolBuilder::new() | ||
.num_threads(threads) | ||
.build() | ||
.expect("Failed to build thread pool"); | ||
|
||
pool.install(|| { | ||
(0u64..=u64::MAX) | ||
.into_par_iter() | ||
.find_any(|_| { | ||
if found.load(Ordering::Relaxed) { | ||
return false; | ||
} | ||
let mut rng = thread_rng(); | ||
let account = LocalAccount::generate(&mut rng); | ||
if matches_pattern(&account.address(), starts_pattern, ends_pattern) { | ||
let mut lock = result.lock().unwrap(); | ||
*lock = Some(account); | ||
found.store(true, Ordering::Relaxed); | ||
true | ||
} else { | ||
false | ||
} | ||
}); | ||
}); | ||
|
||
println!("✅ Mining completed in {:?}", start_time.elapsed()); | ||
|
||
let final_result = std::mem::take(&mut *result.lock().unwrap()); | ||
final_result.expect("No matching account found") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.