feat(cli): add gpu safe address mining#15
Open
mmv08 wants to merge 1 commit into
Open
Conversation
867e5c5 to
db291dd
Compare
Add an opt-in wgpu compute miner with adapter listing, backend selection, and GPU batch sizing for Metal, Vulkan, and DX12 backends. Expose Safe search context APIs so CPU and GPU derivation share the same Safe-specific CREATE2 inputs, and keep CPU verification as the source of truth for GPU hits. Document the host/device buffer layout, nonce scanning strategy, shader helpers, and reference benchmark environment.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add Opt-In GPU Mining for Safe Vanity Addresses
Summary
This branch adds an optional GPU mining mode to
deadbeef.The normal CPU miner is still available and remains the source of truth. When GPU mining is enabled, the GPU quickly scans possible Safe salt nonce values and returns a possible match. The CPU then checks that candidate again before the CLI prints the final address and transaction data.
The GPU work was inspired by
create2crunch.What This Unlocks
The practical win is that longer vanity prefixes become realistic on consumer-grade GPU hardware.
Using the RTX 5090 benchmark in the README, the GPU miner checks about 2.2 billion candidate addresses per second. The same machine has a 12-core CPU. If we take the README's single-thread CPU benchmark and assume perfect scaling across all 12 physical cores, the GPU is still about 107x faster.
At that speed, a 5-byte prefix such as
0x5afe000000,0xdeadbeef00, or0x0000000000takes about 8 minutes on average on the GPU. With the optimistic 12-core CPU estimate above, the same search would take about 15 hours.A 6-byte prefix such as
0x5afe00000000is still much harder. On the same RTX 5090 benchmark, it is closer to a day and a half on average. With the same optimistic 12-core CPU estimate, it would be closer to 5 months. So this change does not make every vanity address cheap, but it moves useful 5-byte prefixes into the "run it over lunch" range and makes some longer searches possible without a dedicated mining setup.Important Safety Note
The GPU kernel was written with the assistance of AI.
The Keccak hashing function inside the GPU shader has not been cryptographically verified. Because of that, we do not treat the GPU result as trusted on its own.
Instead, the CPU implementation is always treated as the known-good implementation. The GPU only proposes a candidate. Before returning a result, the CLI uses the CPU code to recompute the Safe address and confirm that it really matches the requested prefix.
If the GPU ever returns a wrong candidate, the CLI reports an error instead of printing unsafe deployment data.
What Changed
--gputo mine Safe vanity addresses with a GPU.--list-gpusto show the GPU adapters available throughwgpu.--gpu-backendso users can choose the backend, includingmetal,vulkan,dx12, andgl.--gpu-adapterso users can select a specific GPU from the adapter list.--gpu-batch-sizeso users can tune how many candidate addresses are checked in one GPU dispatch.--allow-software-gpuflag for tests and diagnostics.--quietcompatible with GPU mining by suppressing GPU progress output.How GPU Mining Works
The CPU still builds the Safe configuration, initialiser, factory address, and proxy init code hash.
For GPU mining, the CPU sends the fixed search inputs to the GPU:
The GPU checks many counter values in parallel. Each counter becomes the last 8 bytes of the Safe salt nonce. If the shader finds a value that appears to create an address with the requested prefix, it writes that nonce into a small result buffer.
The CPU reads the candidate nonce, recomputes the Safe address using the existing Rust implementation, and accepts the result only if the CPU-computed address matches the requested prefix.
Implementation Details
cli/src/gpumodule split into adapter selection, dispatch layout, host/GPU input packing, mining, and tests.cli/src/gpu.wgsl, which contains the compute shader used by the GPU miner.SearchContextindeadbeef-coreso the CLI can share fixed Safe address search inputs with the GPU path without moving full Safe setup logic into the shader.Safe::search_context()andSafe::update_salt_nonce()helpers so both CPU and GPU mining paths use the same final Safe transaction construction.wgpu,pollster,bytemuck, andranddependencies to the CLI crate.Testing and Validation
This branch adds tests for:
--list-gpusbehaviour without requiring Safe owner or prefix arguments.SearchContext.The GPU tests are written so they skip when no GPU adapter is available. A separate, ignored benchmark test can be run manually to measure GPU throughput.