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

Add support for CreateX salts #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ This tool was originally built for use with [`Pr000xy`](https://github.com/0age/

There is also an experimental OpenCL feature that can be used to search for addresses using a GPU. To give it a try, include a fourth parameter specifying the device ID to use, and optionally a fifth and sixth parameter to filter returned results by a threshold based on leading zero bytes and total zero bytes, respectively. By way of example, to perform the same search as above, but using OpenCL device 2 and only returning results that create addresses with at least four leading zeroes or six total zeroes, use `$ cargo run --release $FACTORY $CALLER $INIT_CODE_HASH 2 4 6` (you'll also probably want to try tweaking the `WORK_SIZE` parameter in `src/lib.rs`).

To generate [CreateX](https://github.com/pcaversaccio/createx) salts which are cross-chain redeploy protected, pass in 1 for the optional seventh argument, like `$ cargo run --release $FACTORY $CALLER $INIT_CODE_HASH 2 4 6 1`.

PRs welcome!
23 changes: 21 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct Config {
pub gpu_device: u8,
pub leading_zeroes_threshold: u8,
pub total_zeroes_threshold: u8,
pub createx_replay_protection_flag: u8,
}

/// Validate the provided arguments and construct the Config struct.
Expand Down Expand Up @@ -75,6 +76,10 @@ impl Config {
Some(arg) => arg,
None => String::from("5"),
};
let createx_replay_protection_flag_string = match args.next() {
Some(arg) => arg,
None => String::from("0"),
};

// convert main arguments from hex string to vector of bytes
let Ok(factory_address_vec) = hex::decode(factory_address_string) else {
Expand Down Expand Up @@ -108,13 +113,23 @@ impl Config {
let Ok(total_zeroes_threshold) = total_zeroes_threshold_string.parse::<u8>() else {
return Err("invalid total zeroes threshold value supplied");
};
let Ok(createx_replay_protection_flag) =
createx_replay_protection_flag_string.parse::<u8>()
else {
return Err("invalid CreateX replay protection flag value supplied");
};

if leading_zeroes_threshold > 20 {
return Err("invalid value for leading zeroes threshold argument. (valid: 0..=20)");
}
if total_zeroes_threshold > 20 && total_zeroes_threshold != 255 {
return Err("invalid value for total zeroes threshold argument. (valid: 0..=20 | 255)");
}
if createx_replay_protection_flag > 1 {
return Err(
"invalid value for CreateX replay protection flag argument. (valid: 0 | 1)",
);
}

Ok(Self {
factory_address,
Expand All @@ -123,6 +138,7 @@ impl Config {
gpu_device,
leading_zeroes_threshold,
total_zeroes_threshold,
createx_replay_protection_flag,
})
}
}
Expand Down Expand Up @@ -155,7 +171,8 @@ pub fn cpu(config: Config) -> Result<(), Box<dyn Error>> {
header[0] = CONTROL_CHARACTER;
header[1..21].copy_from_slice(&config.factory_address);
header[21..41].copy_from_slice(&config.calling_address);
header[41..].copy_from_slice(&FixedBytes::<6>::random()[..]);
header[41] = config.createx_replay_protection_flag;
header[42..].copy_from_slice(&FixedBytes::<5>::random()[..]);

// create new hash object
let mut hash_header = Keccak::v256();
Expand Down Expand Up @@ -321,7 +338,9 @@ pub fn gpu(config: Config) -> ocl::Result<()> {
// begin searching for addresses
loop {
// construct the 4-byte message to hash, leaving last 8 of salt empty
let salt = FixedBytes::<4>::random();
let mut salt = FixedBytes::<4>::random();
// replace the starting byte of the salt with the CreateX replay protection flag
salt[0] = config.createx_replay_protection_flag;

// build a corresponding buffer for passing the message to the kernel
let message_buffer = Buffer::builder()
Expand Down