🧪 Part 2: Minimal Stratum V2 Handshake (Noise XX/NX + SetupConnection)
Following up on the Noise Protocol intro — here's a small, self-contained C implementation that performs a Noise handshake (XX or NX) and exchanges Stratum V2 SetupConnection messages immediately after.
It’s built to test client/server handshake logic without needing full SV2 support or encryption on the transport layer (yet).
Just Noise + SetupConnection, using raw TCP with framed messages.
🔧 What’s included:
Minimal “pool server” (sv2_pool_server.c) that:
Accepts TCP connections
Completes a Noise handshake (XX by default, NX optional via --nx)
Decodes a SetupConnection message and responds with SetupConnection.Success
Matching client (noise_client.c) that:
Connects to the pool
Runs Noise handshake
Sends a valid SetupConnection payload
Handshake and transport logic is handled using noise-c — clean, constant-time, and easy to audit.
🔐 Handshake Patterns:
XX: Both parties are anonymous; ephemeral key exchange on both sides.
NX: Server has a static key; client is ephemeral (more realistic for mining pools).
These map directly to Noise patterns (Noise_XX_25519_ChaChaPoly_BLAKE2s) and can be swapped via --xx / --nx.
🧰 Framing and Messages:
Transport uses simple framing: uint16_be length prefix + payload.
After handshake, we send:
SetupConnection (client → server)
SetupConnection.Success (server → client)
These are built using SV2 helpers (sv2_common.[ch], sv2_wire.[ch]) to encode/decode the frames.
🔄 Example Usage:
Start the pool server:
./sv2_pool_server -l 0.0.0.0:3334 --prologue STRATUM/2 --sk <hex-secret>
Start the client:
./noise_client -l 127.0.0.1:3334 --prologue STRATUM/2
Both ends should print confirmation of the handshake and the SetupConnection exchange.
🚫 What's intentionally missing (for now):
No full SV2 session yet (no channel open, no job distribution)
No post-handshake encryption of transport messages
No persistent session keys or reconnection logic
This is by design — the goal is to test handshakes + basic SV2 flows before introducing more complexity. Once the handshake layer is stable, you can drop in encrypted transport using sv2_noise_send_transport() and sv2_noise_recv_transport() provided in the demo.
💡 I’m using this for testing SV2 client implementations and validating message formats over raw TCP before wiring into a full miner or pool stack.
This is all part of adding SV2 mining protocol support to Datum gateway.
I already have a SV1 to SV2 translator. Now adding SV2 server features.
#noiseprotocol #stratumv2 #miningprotocol #bitcoinmining #handshake #cryptography #protocoltesting #cprogramming #securecommunications #nostrdev #decentralization #packetengineering #DLT
View quoted note →
Login to reply