# Proof-of-work challenges: how Anubis-style bot checks work

> A proof-of-work challenge makes the browser find a number that, combined with a challenge from the server, gives a SHA-256 hash starting with a set number of zeros. Finding it takes many tries and checking it takes one hash. Anubis uses this in front of websites to make mass crawling expensive. It costs bots CPU time but says nothing about who the visitor is.

Category: CAPTCHA and challenges. Level: Advanced. Updated: 2026-11-24.
Canonical page: https://stopbots.io/learn/captcha/proof-of-work-challenges/

Proof of work as a defence against abuse is older than the web's bot problem. Cynthia Dwork and Moni Naor proposed pricing email by computation in 1992, and Adam Back's Hashcash (1997) made the idea practical: the sender attaches a stamp that took real work to find and takes almost none to check. Bot checks apply the same trick to page requests. Each visitor pays a small fee in CPU time, which is cheap for one person and expensive for a crawler requesting millions of pages.

## How does a hashcash-style puzzle work?

1. The server sends a random challenge string and a difficulty, and remembers the challenge or signs it so it can recognise it later.
2. The browser tries nonces (counters) 0, 1, 2 and so on. For each one it computes SHA-256 of the challenge plus the nonce, and it stops when the hex digest starts with the required number of zeros.
3. The browser sends the winning nonce. The server computes one hash, checks the prefix and checks that the challenge is fresh and unused.

Each hex digit carries 4 bits, so a random hash starts with d zeros with a probability of 1 in 16^d. The expected number of tries is 4,096 at difficulty 3, 65,536 at difficulty 4 and 1,048,576 at difficulty 5. Each extra zero multiplies the work by 16, so difficulty moves in large steps. The number of tries also varies a lot between visitors. Some find a nonce early, others take several times the average.

A minimal solver for the browser:

```js
async function solve(challenge, difficulty) {
  const prefix = "0".repeat(difficulty);
  const enc = new TextEncoder();
  for (let nonce = 0; ; nonce++) {
    const digest = await crypto.subtle.digest("SHA-256", enc.encode(challenge + nonce));
    const hex = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
    if (hex.startsWith(prefix)) return { nonce, hash: hex };
  }
}
```

And the check on the server (Node.js):

```js
import { createHash } from "node:crypto";

function verify(challenge, nonce, difficulty) {
  const hex = createHash("sha256").update(`${challenge}${nonce}`).digest("hex");
  return hex.startsWith("0".repeat(difficulty));
}
```

Production implementations run the search in web workers across several CPU cores and also track used challenges, so one solution cannot be replayed.

## How does Anubis bot protection work?

[Anubis](https://github.com/TecharoHQ/anubis) is an open source reverse proxy written in Go. It sits between your web server and your application, and its README describes it as protecting upstream resources from scraper bots, especially AI crawlers. It has been widely adopted by open source projects and smaller sites whose code forges, wikis and archives were overloaded by crawlers.

Its documentation describes this flow:

- A policy file, in YAML or JSON, matches each request by path, User-Agent, headers or IP range and gives it an action: `ALLOW`, `DENY`, `CHALLENGE` or `WEIGH` (adjust a suspicion score). Rules are checked in order, and the first allow, deny or challenge match decides.
- In the default policy, requests whose User-Agent contains "Mozilla" get a suspicion weight and are challenged. That covers every mainstream browser and the bots that pretend to be one. Paths such as `/.well-known`, `/robots.txt`, `/favicon.ico` and feed URLs are not challenged, and clients without "Mozilla" in their User-Agent, such as git clients, pass.
- The challenge page runs a worker that finds a nonce for a challenge derived from request metadata. Difficulty is the number of leading hex zeros and can be set per rule.
- After a valid answer, Anubis sets a cookie holding a signed JWT (a signed JSON token) with the challenge, nonce, hash and expiry. Later requests with a valid cookie go straight through.
- A no-JavaScript challenge based on a meta refresh exists. The default policy uses it only for low-suspicion clients, and the documentation warns of a higher false positive rate.
- Requests that match no rule are allowed.

A minimal policy, adapted from the documentation, with an extra rule placed first. On the search and archive pages, any client without a valid Anubis cookie gets a challenge at difficulty 5, including clients with a non-browser User-Agent:

```yaml
bots:
  - name: expensive-pages
    path_regex: ^/(search|archive)/
    action: CHALLENGE
    challenge:
      difficulty: 5
      algorithm: fast
  - name: well-known
    path_regex: ^/.well-known/.*$
    action: ALLOW
  - name: robots-txt
    path_regex: ^/robots.txt$
    action: ALLOW
  - name: generic-browser
    user_agent_regex: Mozilla
    action: CHALLENGE
```

## What does proof of work cost, and who pays?

- Crawlers pay CPU time for each fresh pass. A crawler that keeps its cookie pays once per cookie lifetime and then requests pages freely until it expires. The cost adds up for crawlers that throw cookies away, rotate identities or run at very large scale.
- Attackers with native code pay less. SHA-256 in compiled code or on GPUs runs much faster than JavaScript in a phone browser. Difficulty has to suit the slowest real device you serve, which caps how much it can cost a well-equipped bot. Memory-hard functions such as Argon2id or scrypt narrow that gap, and [ALTCHA](https://github.com/altcha-org/altcha) offers them as options.
- Real visitors pay in time and battery, more on low-end phones. They see an interstitial page, and visitors with JavaScript disabled are stuck unless you enable a no-JavaScript method.
- Nobody proves who they are. A pass shows that CPU time was spent. It does not show that the client is a person or the same visitor as before. A [headless browser](https://stopbots.io/learn/detection/headless-browser-detection.md) pays the cost and passes. Invisible challenges that check the browser environment add that evidence (see [how invisible JavaScript challenges work](https://stopbots.io/learn/captcha/javascript-challenges-explained.md)).

## What gaps do you need to cover with your own rules?

- The default trigger is the User-Agent. Clients that send a non-browser User-Agent are not challenged unless a rule says so. Add path rules for expensive pages, as in the policy above, and deny clients you never want.
- The default action is allow. Anything your rules do not match goes through.
- Search engines need explicit rules. Allow them by their published IP ranges with `remote_addresses`, not by User-Agent alone. See [how to verify Googlebot and other good bots](https://stopbots.io/learn/scraping/how-to-verify-good-bots.md).
- One solved cookie can be copied to many workers. Limit requests per cookie and per IP address at your web server.
- Feeds and APIs are left open on purpose, so protect them with authentication and quotas.

## Where does proof of work fit?

It fits public content sites, code forges, documentation, wikis and archives whose problem is crawler volume and server load. It also suits teams that want something self-hosted and open source, with no visitor data sent to a third party. [How to block AI crawlers](https://stopbots.io/learn/scraping/how-to-block-ai-crawlers.md) covers the robots.txt and edge rules that go with it.

It fits poorly on login, signup and checkout. In credential stuffing or card testing each request is worth more to the attacker than a few seconds of CPU time, and those flows need identity signals that a proof of work does not give. It also fits poorly where most visitors use low-end phones or need an accessible flow with no waiting page, and on APIs, whose clients cannot run the challenge.

## Tools that help

_StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking._
- [Anubis](https://github.com/TecharoHQ/anubis): an open source reverse proxy that challenges browsers with SHA-256 proof of work, free and self-hosted, for sites under AI crawler load.
- [ALTCHA](https://github.com/altcha-org/altcha): an MIT-licensed proof-of-work widget for forms, self-hosted, with memory-hard algorithm options.
- [Friendly Captcha](https://friendlycaptcha.com/): a hosted widget that combines proof of work with risk signals, for teams that want a managed service.
- [Kairal](https://www.kairal.io/product/bot-protection/): for login, signup and checkout, where proof of work alone is not enough, it links device, network and behaviour signals and verifies suspicious visitors with invisible challenges.

## Common questions

### Does Anubis block Googlebot?

It can, if your policy does not allow it. Googlebot's User-Agent contains 'Mozilla', which Anubis treats as suspicious and challenges by default. The default policy has an allowlist for known crawlers, and a custom policy file can allow a named crawler only from its published IP ranges, so check that yours covers the search engines you rely on.

### Is proof of work better than a CAPTCHA?

It is easier on people: there is no image or text to read, and a slow device only waits longer. It is weaker evidence, because a CAPTCHA service's hidden checks look at the browser and network, while a proof of work only measures spent computation.

### Is there self-hosted bot protection?

Yes. Anubis and ALTCHA are open source and run on your own servers, and CrowdSec and fail2ban block abusive IP addresses based on your logs. Self-hosting keeps visitor data away from a vendor, but you maintain the rules and the search engine allowlists yourself.

## Related

- [CAPTCHA alternatives: how to stop bots without a puzzle](https://stopbots.io/learn/captcha/captcha-alternatives.md)
- [How to block AI crawlers: robots.txt, Cloudflare and nginx](https://stopbots.io/learn/scraping/how-to-block-ai-crawlers.md)
- [How invisible JavaScript challenges work](https://stopbots.io/learn/captcha/javascript-challenges-explained.md)
- [How to detect headless Chrome and automated browsers](https://stopbots.io/learn/detection/headless-browser-detection.md)
