SetNet.ProofOfWork 1.1.0

dotnet add package SetNet.ProofOfWork --version 1.1.0
                    
NuGet\Install-Package SetNet.ProofOfWork -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SetNet.ProofOfWork" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.ProofOfWork" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.ProofOfWork" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SetNet.ProofOfWork --version 1.1.0
                    
#r "nuget: SetNet.ProofOfWork, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SetNet.ProofOfWork@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SetNet.ProofOfWork&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.ProofOfWork&version=1.1.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.ProofOfWork

Hashcash admission gate for SetNet — make mass/bot connections expensive.

On connect the server issues a random challenge; until the client sends a nonce whose SHA-256(challenge ‖ nonce) has enough leading zero bits, the server drops all of that peer's application frames. A single honest client burns a fraction of a second of CPU once; an attacker opening thousands of connections must pay that cost thousands of times. The client side solves and submits automatically. Added by composition — the server gate is chained onto any existing InboundAuthorizer.

Install

dotnet add package SetNet
dotnet add package SetNet.ProofOfWork

Usage

Call ProofOfWorkRuntime.Enable() once at startup (before handler discovery) on both ends so the handshake handlers are registered.

Server:

ProofOfWorkRuntime.Enable();

var server = new MyServer(config);
server.UseProofOfWork(difficulty: 20);   // required leading zero bits (~2^20 hashes)
await server.StartAsync();

Client:

ProofOfWorkRuntime.Enable();

var client = new MyClient(config);
client.UseProofOfWork();                  // auto-solves the challenge on connect
await client.ConnectAsync();

That's it — the client solves the challenge off the receive thread and submits the nonce; once verified, its frames flow normally.

API

Call Purpose
server.UseProofOfWork(int difficulty = 20) install the gate; peers must solve before their frames pass
client.UseProofOfWork() auto-solve and submit on connect / reconnect
ProofOfWorkRuntime.Enable() one-time bootstrap so the PoW handlers are discovered

Difficulty is the number of required leading zero bits. Cost is roughly 2^difficulty SHA-256 hashes:

difficulty ~hashes typical solve time
16 65 K instant
20 1 M tens of ms
22 4 M ~0.1–0.3 s
24 16 M ~0.5–1 s

Pick the highest value your slowest legitimate client tolerates.

Notes

  • Reserved wire types 65506 / 65507. Don't reuse them for application messages.
  • Standalone admission gate. PoW blocks all non-PoW frames until solved. If you also use another "deny-until" gate that blocks its own control frames (e.g. SetNet.Auth), run PoW as the connection-admission step and let auth happen after — stacking two mutually-blocking gates can deadlock. SetNet.RateLimit and SetNet.BanList chain fine.
  • Mitigation, not authentication. PoW raises the cost of connection floods; it does not identify users. Combine with auth for identity and with rate limiting for sustained abuse.
  • One client per process is the common case and fully supported; the challenge is solved and answered on the connection that received it.

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 133 7/2/2026