How LuckyHash Works – WebGPU Solo Bitcoin Miner

WebGPU CPU Fallback Stratum Solo Mining

How LuckyHash
works

LuckyHash is a solo BTC miner running entirely in the browser. It leverages GPU compute power via the WebGPU API to perform millions of SHA256d hashes per second, connecting directly to a Bitcoin pool via the Stratum protocol.

SHA256d
Hash Algorithm
WebGPU
Compute API
Stratum
Pool Protocol
WGSL
Shader Language
System Architecture
┌─────────────────────────────────────────────────────┐
│                    BROWSER                          │
│                                                     │
│  ┌─────────────┐    Stratum/WS   ┌─────────────┐  │
│  │  miner.js   │ ◄──────────► │  Proxy WS  │  │
│  │             │              │   :3030     │  │
│  │  ┌────────┐ │              └──────┬──────┘  │
│  │  │WebGPU  │ │                     │ Stratum TCP  │
│  │  │Compute │ │              ┌──────▼──────┐  │
│  │  │Shader  │ │              │  Bitcoin   │  │
│  │  │SHA256d │ │              │  Pool      │  │
│  │  └────────┘ │              │  :3333      │  │
│  │  ┌────────┐ │              └─────────────┘  │
│  │  │CPU     │ │                                │
│  │  │Workers │ │  (fallback when no GPU)        │
│  │  └────────┘ │                                │
│  └─────────────┘                                │
└─────────────────────────────────────────────────────┘
Step-by-Step Mining Flow
1
Connect via Stratum

The miner opens a WebSocket to luckyhash_proxy. The proxy maintains a TCP connection to the actual Bitcoin pool. The protocol uses Stratum JSON-RPC: mining.subscribe → mining.authorize.

↓
2
Receive Job (mining.notify)

The pool sends a job containing: prevHash, coinb1/coinb2, merkleBranch, nBits, nTime, version. The miner assembles the coinbase transaction and computes the Merkle Root via SHA256d.

↓
3
Build the Block Header (80 bytes)

Header is assembled from: version (4B) + prevHash (32B) + merkleRoot (32B) + nTime (4B) + nBits (4B) + nonce (4B). The nonce is the only field that changes on every attempt.

↓
4
Parallel SHA256d — GPU or CPU

WebGPU: each GPU thread tries a unique nonce — 65K–4M nonces per batch. CPU: multiple Web Worker threads split the nonce range. Formula: hash = SHA256(SHA256(header_80_bytes)).

↓
5
Compare Hash Against Target

If hash < target the nonce is valid — the digest is compared as a little-endian 256-bit integer (Bitcoin's uint256 convention, so a valid digest has trailing zero bytes; the familiar leading-zero form is the byte-reversed block-hash display). The target is derived from nBits and the pool-set difficulty. At difficulty = 1, the probability of any single hash being valid is ~1/2³².

↓
6
Submit Share (mining.submit)

Send [worker, jobId, extranonce2, nTime, nonce] to the pool via WebSocket. The pool responds with true (accepted) or an error (rejected). If the share meets full network difficulty, it's a valid block — you win!

WGSL Shader (GPU kernel)
// Each GPU thread receives a unique nonce @compute @workgroup_size(256) fn main(@builtin(global_invocation_id) gid: vec3<u32>) { let nonce = inp[28] + gid.x; // nonce = base + thread_id // SHA256 pass 1: 80-byte block header var s1: array<u32, 8> = IV; compress(&w1, &s1); // block 1: bytes 0–63 compress(&w2, &s1); // block 2: bytes 64–79 + padding // SHA256 pass 2: hash the 32-byte result var s2: array<u32, 8> = IV; compress(&w3, &s2); // Check: hash < target? if (below) { atomicStore(&out_buf[0], 1u); } }
WebGPU vs CPU
WebGPU
~10–500 MH/s
Depends on GPU
CPU Workers
~100–2000 KH/s
Depends on core count
GPUCPU
Parallel threadsThousands4–16
Batch/cycle4M noncesEvenly split
RequirementChrome 113+Any browser
ShaderWGSLJavaScript
Stratum Protocol
→ Sent to pool { "method": "mining.subscribe", "params": ["LuckyHash/1.0"] } { "method": "mining.authorize", "params": ["btc_address.worker", "x"] } { "method": "mining.submit", "params": ["worker","jobId","en2","ntime","nonce"] } ← Received from pool { "method": "mining.notify", "params": [jobId, prevHash, coinb1, coinb2, merkleBranch, version, nBits, nTime] } { "method": "mining.set_difficulty", "params": [difficulty] }
FAQ
How is solo mining different from pool mining?
Pool mining shares hash power and distributes small but frequent rewards. Solo mining: you mine alone — very low probability of success, but if you win you receive the full block reward (~3.125 BTC currently).
Which browsers support WebGPU?
Chrome 113+, Edge 113+, Opera 99+, Safari 18+ (macOS 14+). Firefox does not yet support WebGPU in production. If WebGPU is unavailable, the miner automatically falls back to CPU mode.
What does luckyhash_proxy do?
Browsers cannot open raw TCP connections to a Bitcoin pool directly. luckyhash_proxy runs a WebSocket server (port 3030) and bridges it to the pool's Stratum TCP server (port 3333). All Stratum messages are forwarded transparently through the proxy.
How does batch size affect performance?
A larger batch means fewer CPU↔GPU round-trips per second, which is more efficient — but each batch holds the GPU longer. If the UI feels sluggish, reduce the batch size. Use 1M–4M for weaker GPUs, 16M for high-end ones.
Is my private key ever exposed?
No. Mining only requires your BTC address (public) to receive the reward — your private key is never needed. Rewards are sent directly to that address if a block is successfully mined.
Glossary
SHA256dDouble SHA-256: SHA256(SHA256(data)) — Bitcoin's proof-of-work hash algorithm
NonceA 32-bit number iterated continuously to find a valid hash
Target256-bit threshold the resulting hash must be below to be accepted
DifficultyA scalar that controls how small the target is — higher = harder
ExtraNonceExtra entropy injected into the coinbase to extend the nonce search space
Merkle RootAggregated hash of all transactions in the block
WGSLWebGPU Shading Language — used to write GPU compute shaders
Disclaimer
Extremely Low Probability

The odds of mining a Bitcoin block with consumer hardware are astronomically low — statistically it could take thousands of years. This is an experimental / educational tool, not a money-making application.

Power Consumption

Continuous GPU mining can heat your device and significantly increase power draw. Ensure adequate cooling and do not run at full load for extended periods.

No Guaranteed Returns

This software does not guarantee any financial return. Results depend entirely on luck and your share of the total network hashrate (currently >700 EH/s).

Legal Compliance

Users are solely responsible for complying with local laws and regulations regarding cryptocurrency mining. The authors accept no liability for any damages arising from the use of this software.

This software is provided "as is" — without warranty of any kind. Intended for educational, research, and WebGPU exploration purposes only.