Client challenge runtime
The client challenge runtime gives a browser a short proof-of-work task before it can continue to a protected request. It presents the task, runs the selected work in browser workers, and sends the result to the server so the server can validate it and restore the original request flow.
Challenge lifecycle
The runtime connects a server-issued challenge to a browser proof and then to a protected request. The challenge page carries the work inputs, while the server remains responsible for deciding whether the proof is valid.
flowchart LR
A[Server issues challenge and rules] --> B[Browser loads challenge page]
B --> C[Runtime selects algorithm]
C --> D[Workers search nonce space]
D --> E[Runtime receives hash and nonce]
E --> F[Browser waits for registered extensions]
F --> G[Browser calls pass-challenge]
G --> H[Server verifies proof]
H --> I[Protected request continues]
Challenge issuance
The server renders the challenge page with the challenge data and the active rules as JSON data for the browser. The page also receives the base path, public URL, and version needed to load related assets and build the return request. References: web/index.go• L20-27, web/index.templ#L61-L64
Client computation
The browser selects the algorithm named by the rules and gives it the challenge data and difficulty. It reports work rate and estimated progress while workers search separate nonce lanes for a valid result. References: web/…/main.ts• L150-210, web/…/index.ts• L4-11, web/…/worker.ts• L146-169
Verification handoff
After a worker finds a result, the browser submits the challenge ID, response hash, nonce, elapsed time, and return URL to the pass-challenge endpoint. The server checks the proof against the issued challenge and rule before allowing the request to continue. References: web/…/main.ts• L211-264, lib/anubis.go• L615-655, lib/…/proofofwork.go• L36-94, lib/…/wasm.go• L53-106
Browser challenge experience
The challenge page is a temporary browser step between a blocked request and its target. It checks the browser features needed for the task, gives the user visible progress, and shows a failure state instead of leaving the page waiting when a required step fails.
For the page delivery model and its user-facing structure, see Challenge UI delivery.
Runtime readiness
The runtime requires cookies and Web Workers. WebAssembly-capable browsers use the native WebAssembly path; browsers without that support use a JavaScript form of the same work. Asset fetches use retry and backoff because the challenge assets come from the server under load. References: web/…/main.ts• L90-147, web/…/wasm.ts• L37-56, web/…/wasm-supported.ts• L1-20, web/…/backoff.ts• L1-12
Progress and completion
Workers send periodic work counts and one worker sends the completed result. The page turns those counts into a speed display and an estimated progress bar. Once work is complete, registered challenge extensions get a short window to finish before the browser submits the proof. References: web/…/main.ts• L162-210, web/…/worker.ts• L250-272, web/…/extensions.ts• L8-30
Return navigation
The pass-challenge request carries a validated return target rather than sending the browser back blindly. The server then uses the accepted result to restore access to the protected request, while a missing verification cookie can cause a fresh challenge or a clear cookie error. References: web/…/main.ts• L238-263, lib/anubis.go• L623-649
WebAssembly work runtime
The WebAssembly runtime performs the costly search in isolated browser workers so the page can remain responsive. It chooses a compatible module variant, shares the compiled work definition with workers, and returns the first valid hash and nonce.
For the proof-of-work algorithms and their shared verification contract, see WebAssembly proof of work.
Algorithm selection
The server rule names one supported work algorithm. The browser maps that name to the matching WebAssembly module and selects a SIMD-enabled or baseline module when native WebAssembly is available. References: web/…/index.ts• L4-11, web/…/wasm.ts• L45-70, lib/…/wasm.go• L20-24
Worker search
The runtime starts a group of workers based on available hardware and divides the nonce space into lanes. Each worker runs the same work module with a different starting nonce and step, so a result from any worker can end the search. References: web/…/worker.ts• L146-180, web/…/worker.ts• L228-347, web/…/wasm.ts• L8-64
Runtime fallback
The runtime has two fallback boundaries. It can use generated JavaScript when the browser cannot run WebAssembly, and it can load workers directly when preloading a worker source or using a blob URL fails. These fallbacks preserve the challenge contract but can change performance and network load. References: web/…/wasm.ts• L47-70, web/…/wasm2js.ts• L18-72, web/…/worker.ts• L45-131
Proof acceptance
The browser result is only a claim until the server checks it. The server reconstructs or runs the matching algorithm with the issued challenge, nonce, and difficulty, then records the time and accepts the request only when the result meets the rule.
Proof fields
The client and server share a small handoff contract:
ididentifies the issued challenge.responsecontains the computed result.nonceidentifies the successful search position.elapsedTimerecords the client-side work time.rediridentifies the protected destination.
The server treats missing or malformed proof fields as validation failures. References: lib/…/proofofwork.go• L36-68, lib/…/wasm.go• L53-83
Server verification
The server validates the response with the same challenge algorithm that the client used. The simple proof-of-work path checks the hash and required leading zeros, while the WebAssembly path runs the matching verifier over the challenge bytes and returned result. References: lib/…/proofofwork.go• L70-94, lib/…/wasm.go• L84-106
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the algorithm names aligned between the server registration and the browser algorithm map.
- Keep the client submission fields aligned with both server validation paths.
- Keep the native WebAssembly modules and generated JavaScript fallback set aligned when adding or removing an algorithm.
- Keep worker progress messages compatible with the page progress and completion handling.
- Keep the return URL rules aligned with the server redirect checks.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Cookies are disabled | The server cannot complete verification and the user sees a cookie error or a retry. | The page checks cookie support and the server checks the verification cookie. |
| Web Workers are unavailable | The browser cannot run the challenge worker pool. | The page stops with a missing-feature error. |
| WebAssembly or its module asset cannot load | The runtime uses the generated JavaScript path when possible or shows a calculation error. | Feature detection, asset backoff, and the wasm2js fallback. |
| A worker dies before producing output | The challenge can fail because the nonce search is incomplete. | Worker demotion, worker restart, and an explicit all-workers-failed error. |
| The proof fields or return target are invalid | The server rejects the handoff and does not restore the protected request. | Server-side field validation and redirect validation. |
Key files
| File | Why to read it |
|---|---|
| web/…/main.ts | Shows the browser challenge lifecycle from readiness checks through proof submission. |
| web/…/worker.ts | Defines worker pooling, nonce lanes, progress messages, and worker failure handling. |
| web/…/wasm.ts | Shows module selection and the native WebAssembly entry path. |
| web/…/wasm.ts | Shows how a worker runs the module and returns a proof. |
| web/…/wasm2js.ts | Shows the browser fallback when native WebAssembly is not available. |
web/index.go and web/index.templ | Show how the server places challenge data and rules into the page. |
| lib/…/wasm.go | Shows the server-side validation contract for WebAssembly proofs. |
| lib/anubis.go | Shows the protected-request handoff and return navigation checks. |