Skip to content
ccashwellPublic

About

Vanity address salt miner for CREATE2 and CREATE3 (CreateX), using the GPU and every CPU core at once. Built for Apple silicon with a native Metal kernel and SHA3 NEON keccak.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

40 Commits

Folders and files

Repository files navigation

saltmill

A salt miner for vanity contract addresses, for both CREATE2 and CREATE3, that uses the GPU and every CPU core at once. It is built for Apple silicon first: a native Metal kernel on the GPU and a 2-way SHA3 NEON keccak on the CPU.

It brings together two earlier tools: the Apple silicon work on create2crunch (CREATE2 only) and a CPU-only CREATE3 miner for CreateX deployments.

cargo install saltmill
saltmill --help

That needs Rust 1.89 or later. To build from a checkout instead, run cargo build --release and use ./target/release/saltmill.

Mining

Every input is a named flag. You give a derivation (how a salt becomes an address) and a target (which addresses you want). Each hit is printed to stdout as <salt> <checksummed address>; progress goes to stderr, so the output pipes cleanly.

CREATE3 through CreateX

The address depends only on CreateX, the account that calls it, and the salt. It does not depend on the init code, so one salt gives the same address on every chain and for any constructor arguments.

saltmill --scheme create3 --caller 0xYourDeployer --prefix 0000000000

The salt is a CreateX permissioned salt: bytes 0-19 are the caller, byte 20 is 0x00, and the remaining 11 bytes are mined. Only that caller can deploy with it, so nobody else can take the address. Deploy with ICreateX.deployCreate3(salt, initCode) from that account.

Add --chain-id <ID> to turn on CreateX's cross-chain redeploy protection: byte 20 becomes 0x01, the chain id enters the hash, and the address is valid on that chain only.

CREATE2

saltmill --scheme create2 \
  --factory 0x4e59b44847b379578588920cA78FbF26c0B4956C \
  --init-code-hash 0x<keccak256 of creation code ++ abi-encoded constructor args> \
  --prefix c0ffee

Instead of hashing the init code yourself, give it and let saltmill hash it: --artifact out/Token.sol/Token.json (a Foundry or Hardhat build artifact), --init-code <HEX> or --init-code-file <FILE>, each with --constructor-args <HEX> when the constructor takes arguments (cast abi-encode "constructor(address,uint256)" … produces them). Unlinked bytecode is refused.

The salt is --caller (20 bytes, zero when omitted) followed by 12 mined bytes. Pass --caller for factories that only accept a salt starting with msg.sender. The example factory is the deterministic deployment proxy forge script uses for new Contract{salt: salt}(...); it takes the salt as given.

Other factories

Flags Derivation
--scheme create2 --factory <F> --init-code-hash <H> plain CREATE2
--scheme create2 --factory 0xba5E…ba5Ed --caller <C> --init-code-hash <H> CreateX.deployCreate2 (guarded salt)
--scheme create3 --caller <C> CreateX.deployCreate3 (guarded salt)
--scheme create3 --guard createx-open CreateX.deployCreate3 with a salt tied to no caller (see below)
--scheme create3 --factory <F> solmate or Solady CREATE3 used by contract F with the salt as given

--guard createx-open mines the CreateX salts that start with the zero address in place of a caller (with --chain-id, byte 20 is 0x01 and the address is bound to that chain). CreateX accepts such a salt from anyone, so whoever sees it can deploy to the address first, and with CREATE3 they can deploy different code there. Use it only when that is acceptable; saltmill prints a warning when it mines one.

--factory also takes a name in place of an address: createx, arachnid (the deterministic deployment proxy), safe-singleton, erc2470 and immutable-create2. The last only accepts salts that start with the caller or with zeros, which is the layout --caller produces.

The CreateX guard is applied whenever the factory is CreateX, because CreateX always applies it; --guard none|createx overrides that for forks and other deployments. --proxy-init-code-hash covers CREATE3 factories with a different proxy.

Targets

All targets given must hold at once. --prefix and --suffix can be repeated to accept any one of several: --prefix c0ffee --prefix decaf0 takes whichever turns up first, and with several of both, every prefix and suffix pairing is accepted (8 alternatives at most). Each added alternative of the same length makes a hit proportionally more likely.

Flag Address must
--prefix <HEX> start with these hex characters (odd lengths allowed; repeatable)
--suffix <HEX> end with these hex characters (repeatable)
--case-sensitive have the letters of --prefix and --suffix in the case typed, in its checksummed (EIP-55) form
--hook-flags <FLAGS> have address & 0x3fff == FLAGS, the 14 Uniswap v4 hook permission bits
--leading-zero-bytes <N> start with at least N zero bytes
--total-zero-bytes <N> contain at least N zero bytes anywhere
--best leading-zeros|total-zeros beat the previous hit: the run keeps going and prints only improvements

--prefix C0FFEE --case-sensitive finds 0xC0FFEE… and passes over 0xc0FFee…. Each letter doubles the work, because a checksum capitalizes a letter half the time. With very short patterns (under three characters) on the GPU some matches are lost: the GPU reports at most 64 candidates per batch before their case is checked.

--best is for gas-efficient addresses, where you want as many zero bytes as the time you have allows instead of a fixed number. It starts from one zero byte (or from --leading-zero-bytes / --total-zero-bytes when given), raises the bar past each hit, and runs until Ctrl-C or --time-limit; the last line printed is the best found. The other target flags still apply to every hit.

A v4 hook with beforeSwap and afterSwap and a vanity prefix:

saltmill --scheme create2 --factory $FACTORY --init-code-hash $HASH --hook-flags 0x00c0 --prefix c0ffee

Running

Flag Effect
--count <N> stop after N hits (default 1; 0 mines until interrupted)
--time-limit <SECONDS> give up after this long; fails if fewer than --count hits were found
--output <FILE> also append each hit to a file
--check <SALT> print the address a salt deploys to, and fail if it misses the target
--seed <HEX> fix the salt bytes that separate one run's search space from another's
--bench [SECONDS] measure the hash rate instead of mining (see Performance)
--json print each hit as a JSON object on one line: the salt, the address and the inputs that derive it (also the form of --output, --check and --bench results)
--quiet print hits and errors only

Ctrl-C stops a run in order: the summary is printed and --output is complete. A run with --count 0 is meant to end that way and exits successfully; one that was still short of its count exits with an error. A second Ctrl-C exits at once.

Verifying a salt

Check a salt independently before you depend on it. --check recomputes it here; these recompute it elsewhere:

# CREATE2
cast create2 --deployer $FACTORY --salt $SALT --init-code-hash $HASH

# CreateX CREATE3: simulate the deployment from the caller, on any chain
cast call --from $CALLER 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed \
  "deployCreate3(bytes32,bytes)(address)" $SALT 0x600160005360016000f3

Compute

--compute auto (the default) mines on the GPU and the CPU together, and on the CPU alone when no GPU can be used. cpu, gpu and hybrid force a choice; hybrid fails if the GPU is unusable.

  • GPU, Metal (macOS). The kernel keeps each 64-bit keccak lane as two 32-bit words of even and odd bits, because Apple GPUs have no 64-bit integer ALU. All three hashes of a CREATE3 candidate run in that form in one kernel. Batches are 2^--gpu-batch-bits candidates (default 26).
  • GPU, OpenCL (cargo build --release --features opencl, then --backend opencl). The same kernel for other GPUs. On macOS OpenCL is a slow shim over Metal; use Metal there.
  • CPU. One thread per core (--threads), one core held back for the GPU's host thread when the GPU mines. With the ARMv8.4 SHA3 extension (every Apple M-series chip) each thread hashes two candidates at once in the NEON registers; other CPUs use scalar CRYPTOGAMS assembly (--cpu-kernel forces either).

The CPU starts immediately and the GPU joins after its kernel compiles, about 1.5 seconds. Before mining, the compiled kernel is aimed at a candidate whose address the host already knows and must find exactly that one. Every hit, from any miner, is recomputed on the host through a separate plain keccak before it is printed; a mismatch stops the run.

Performance

One saltmill --bench run on an Apple M4 Max laptop (14-core CPU, 40-core GPU), in millions of salts per second. A CREATE3 salt costs three hashes, so it runs at about a third of the CREATE2 rate.

CPU (2-way SHA3 NEON) GPU (Metal) Hybrid
CREATE2 142.1 711.3 723.8
CREATE3 via CreateX 44.2 214.4 227.3

Repeat runs on the same machine differ by up to about 10%, mostly with temperature. The GPU and CPU share one power and thermal budget: once the chassis is hot the GPU throttles, and adding the CPU can take as much from the GPU as it contributes. In back-to-back CREATE3 runs on a hot machine, hybrid has measured below --compute gpu.

To measure your own machine:

saltmill --bench                                   # both schemes on CPU, GPU and hybrid, 10 s each
saltmill --bench 30 --scheme create3 --compute gpu # one combination, for longer

The table goes to stdout as Markdown. Each combination is timed from the moment its miners are all hashing, so the GPU kernel's compile time is not counted. They run one after another, so the later ones meet a warmer machine; for a long run on a laptop, measure gpu and hybrid in separate invocations and use the faster.

How the search space is laid out

CREATE2 / unguarded     caller (20) | tag (4) | counter (8)
CreateX                 caller (20) | flag (1) | tag (3) | counter (8)

The tag is random per run (or --seed), and its last bit differs between the CPU and the GPU, so the two never try the same salt. The counter's top byte is the CPU thread index; on the GPU the counter is the position in the batch and the dispatch number.

Development

cargo test                      # includes Metal kernel tests on macOS
cargo test --features opencl    # also runs the kernel through OpenCL
cargo clippy --all-targets --features opencl

The expected addresses in the tests come from cast, and the CreateX ones were also reproduced by simulating deployCreate3 on mainnet and Base.

License

MIT. The keccak kernels derive from create2crunch by 0age.

About

Vanity address salt miner for CREATE2 and CREATE3 (CreateX), using the GPU and every CPU core at once. Built for Apple silicon with a native Metal kernel and SHA3 NEON keccak.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages