aboutsummaryrefslogtreecommitdiff
path: root/spec/hspow-spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec/hspow-spec')
-rw-r--r--spec/hspow-spec/analysis-discussion.md416
-rw-r--r--spec/hspow-spec/common-protocol.md203
-rw-r--r--spec/hspow-spec/index.md5
-rw-r--r--spec/hspow-spec/motivation.md85
-rw-r--r--spec/hspow-spec/v1-equix.md176
5 files changed, 885 insertions, 0 deletions
diff --git a/spec/hspow-spec/analysis-discussion.md b/spec/hspow-spec/analysis-discussion.md
new file mode 100644
index 0000000..6585d3f
--- /dev/null
+++ b/spec/hspow-spec/analysis-discussion.md
@@ -0,0 +1,416 @@
+# Analysis and discussion
+
+*Warning*: Take all the PoW performance numbers on this page with a large grain of salt. Most of this is based on very early analysis that has not been updated for the current state of implementation.
+
+For current performance numbers on a specific piece of hardware, please run `cargo bench` from the [`equix/bench`](https://gitlab.torproject.org/tpo/core/arti/-/tree/main/crates/equix/bench) crate within [Arti](https://gitlab.torproject.org/tpo/core/arti/). This framework tests both the C and Rust implementations side-by-side.
+
+## Attacker strategies {#attacker-strategies}
+
+To design a protocol and choose its parameters, we first need to understand a few high-level attacker strategies to see what we are fighting against.
+
+### Overwhelm PoW verification ("top half") {#attack-top-half}
+
+A basic attack here is the adversary spamming with bogus INTRODUCE messages so that the service does not have computing capacity to even verify the proof-of-work. This adversary tries to overwhelm the procedure in the [`v1` verification algorithm](./v1-equix.md#service-verify) section.
+
+That's why we need the PoW algorithm to have a cheap verification time so that this attack is not possible: we explore this PoW parameter below in the section on [PoW verification](#pow-tuning-verification).
+
+### Overwhelm rendezvous capacity ("bottom half") {#attack-bottom-half}
+
+Given the way [the introduction queue](./common-protocol.md#intro-queue) works, a very effective strategy for the attacker is to totally overwhelm the queue processing by sending more high-effort introductions than the onion service can handle at any given tick.
+This adversary tries to overwhelm the process of [handling queued introductions](./common-protocol.md#handling-queue).
+
+To do so, the attacker would have to send at least 20 high-effort INTRODUCE messages every 100ms, where high-effort is a PoW which is above the estimated level of ["the motivated user"](./motivation.md#user-profiles).
+
+An easier attack for the adversary, is the same strategy but with INTRODUCE messages that are all above the comfortable level of ["the standard user"](./motivation.md#user-profiles).
+This would block out all standard users and only allow motivated users to pass.
+
+### Hybrid overwhelm strategy {#attack-hybrid}
+
+If both the top- and bottom- halves are processed by the same thread, this opens up the possibility for a "hybrid" attack.
+Given the performance figures for the bottom half (0.31 ms/req.) and the top half (5.5 ms/req.), the attacker can optimally deny service by submitting 91 high-effort requests and 1520 invalid requests per second.
+This will completely saturate the main loop because:
+
+```text
+ 0.31*(1520+91) ~ 0.5 sec.
+ 5.5*91 ~ 0.5 sec.
+```
+
+This attack only has half the bandwidth requirement of a [top-half attack](#attack-top-half) and half the compute requirement of a [bottom-half attack](#attack-bottom-half)..
+
+Alternatively, the attacker can adjust the ratio between invalid and high-effort requests depending on their bandwidth and compute capabilities.
+
+### Gaming the effort control logic {#attack-effort}
+
+Another way to beat this system is for the attacker to game the [effort control logic](./common-protocol.md#effort-control). Essentially, there are two attacks that we are trying to avoid:
+
+- Attacker sets descriptor suggested-effort to a very high value effectively making it impossible for most clients to produce a PoW token in a reasonable timeframe.
+- Attacker sets descriptor suggested-effort to a very small value so that most clients aim for a small value while the attacker comfortably launches an [bottom-half attack](#attack-bottom-half) using medium effort PoW (see [this post by tevador on tor-dev from May 2020](https://lists.torproject.org/pipermail/tor-dev/2020-May/014268.html)).
+
+### Precomputed PoW attack {#attack-precomputed}
+
+The attacker may precompute many valid PoW nonces and submit them all at once before the current seed expires, overwhelming the service temporarily even using a single computer.
+The current scheme gives the attackers 4 hours to launch this attack since each seed lasts 2 hours and the service caches two seeds.
+
+An attacker with this attack might be aiming to DoS the service for a limited amount of time, or to cause an [effort control attack](#attack-effort).
+
+## Parameter tuning {#parameter-tuning}
+
+There are various parameters in this PoW system that need to be tuned:
+
+We first start by tuning the time it takes to verify a PoW token.
+We do this first because it's fundamental to the performance of onion services and can turn into a DoS vector of its own. We will do this tuning in a way that's agnostic to the chosen PoW function.
+
+We previously considered the concept of a nonzero starting difficulty setting. This analysis still references such a concept, even though the currently recommended implementation uses a starting effort of zero. (We now expect early increases in effort during an attack to be driven primarily by client retry behavior.)
+
+At the end of this section we will estimate the resources that an attacker needs to overwhelm the onion service, the resources that the service needs to verify introduction requests, and the resources that legitimate clients need to get to the onion service.
+
+### PoW verification {#pow-tuning-verification}
+
+Verifying a PoW token is the first thing that a service does when it receives an INTRODUCE2 message. Our current implementation is described by the [`v1` verification algorithm](./v1-equix.md#service-verify) specification.
+
+Verification time is a critical performance parameter. Actual times can be measured by `cargo bench` now, and the verification speeds we achieve are more like 50-120 microseconds. The specific numbers below are dated, but the analysys below is preserved as an illustration of the design space we are optimizing within.
+
+To defend against a [top-half attack](#attack-top-half) it's important that we can quickly perform all the steps in-between receiving an introduction request over the network and adding it to our effort-prioritized queue.
+
+All time spent verifying PoW adds overhead to the already existing "top half" part of handling an INTRODUCE message.
+Hence we should be careful to add minimal overhead here.
+
+During our [performance measurements on tor](#tor-measurements) we learned that the "top half" takes about 0.26 msecs in average, without doing any sort of PoW verification.
+Using that value we compute the following table, that describes the number of requests we can queue per second (aka times we can perform the "top half" process) for different values of PoW verification time:
+
+| PoW Verification Time | Total "top half" time | Requests Queued per second
+| --------------------- | --------------------- | -----------------------
+| 0 msec | 0.26 msec | 3846
+| 1 msec | 1.26 msec | 793
+| 2 msec | 2.26 msec | 442
+| 3 msec | 3.26 msec | 306
+| 4 msec | 4.26 msec | 234
+| 5 msec | 5.26 msec | 190
+| 6 msec | 6.26 msec | 159
+| 7 msec | 7.26 msec | 137
+| 8 msec | 8.26 msec | 121
+| 9 msec | 9.26 msec | 107
+| 10 msec | 10.26 msec | 97
+
+Here is how you can read the table above:
+
+- For a PoW function with a 1ms verification time, an attacker needs to send 793 dummy introduction requests per second to succeed in a [top-half attack](#attack-top-half).
+- For a PoW function with a 2ms verification time, an attacker needs to send 442 dummy requests per second to succeed in a [top-half attack](#attack-top-half).
+- For a PoW function with a 10ms verification time, an attacker needs to send 97 dummy requests per second to succeed in a [top-half attack](#attack-top-half).
+
+Whether an attacker can succeed at that depends on the attacker's resources, but also on the network's capacity.
+
+Our purpose here is to have the smallest PoW verification overhead possible that also allows us to achieve all our other goals.
+
+Note that the table above is simply the result of a naive multiplication and does not take into account all the auxiliary overheads that happen every second like the time to invoke the mainloop, the bottom-half processes, or pretty much anything other than the "top-half" processing.
+
+During our measurements the time to handle introduction requests dominates any other action time:
+There might be events that require a long processing time, but these are pretty infrequent (like uploading a new HS descriptor) and hence over a long time they smooth out.
+Hence extrapolating the total introduction requests queued per second based on a single "top half" time seems like good enough to get some initial intuition.
+That said, the values of "Requests queued per second" from the table above, are likely much smaller than displayed above because of all the auxiliary overheads.
+
+### PoW difficulty analysis {#pow-difficulty-analysis}
+
+The difficulty setting of our PoW basically dictates how difficult it should be to get a success in our PoW system.
+An attacker who can get many successes per second can pull a successful [bottom-half attack](#attack-bottom-half) against our system.
+
+In classic PoW systems, "success" is defined as getting a hash output below the "target".
+However, since our system is dynamic, we define "success" as an abstract high-effort computation.
+
+The original analysis here concluded that we still need a starting difficulty setting that will be used for bootstrapping the system.
+The client and attacker can still aim higher or lower but for UX purposes and for analysis purposes it was useful to define a starting difficulty, to minimize retries by clients.
+
+In current use it was found that an effort of 1 makes a fine minimum, so we don't normally have a concept of minimum effort. Consider the actual "minimum effort" in `v1` now to simply be the expected runtime of one single Equi-X solve.
+
+#### Analysis based on adversary power {#pow-difficulty-adversary}
+
+In this section we will try to do an analysis of PoW difficulty without using any sort of Tor-related or PoW-related benchmark numbers.
+
+We created the table (see `[REF_TABLE]`) below which shows how much time a legitimate client with a single machine should expect to burn before they get a single success.
+
+The x-axis is how many successes we want the attacker to be able to do per second:
+the more successes we allow the adversary, the more they can overwhelm our introduction queue.
+The y-axis is how many machines the adversary has in her disposal, ranging from just 5 to 1000.
+
+```text
+ ===============================================================
+ | Expected Time (in seconds) Per Success For One Machine |
+ ===========================================================================
+ | |
+ | Attacker Succeses 1 5 10 20 30 50 |
+ | per second |
+ | |
+ | 5 5 1 0 0 0 0 |
+ | 50 50 10 5 2 1 1 |
+ | 100 100 20 10 5 3 2 |
+ | Attacker 200 200 40 20 10 6 4 |
+ | Boxes 300 300 60 30 15 10 6 |
+ | 400 400 80 40 20 13 8 |
+ | 500 500 100 50 25 16 10 |
+ | 1000 1000 200 100 50 33 20 |
+ | |
+ ============================================================================
+```
+
+Here is how you can read the table above:
+
+- If an adversary has a botnet with 1000 boxes, and we want to limit her to 1 success per second, then a legitimate client with a single box should be expected to spend 1000 seconds getting a single success.
+- If an adversary has a botnet with 1000 boxes, and we want to limit her to 5 successes per second, then a legitimate client with a single box should be expected to spend 200 seconds getting a single success.
+- If an adversary has a botnet with 500 boxes, and we want to limit her to 5 successes per second, then a legitimate client with a single box should be expected to spend 100 seconds getting a single success.
+- If an adversary has access to 50 boxes, and we want to limit her to 5 successes per second, then a legitimate client with a single box should be expected to spend 10 seconds getting a single success.
+- If an adversary has access to 5 boxes, and we want to limit her to 5 successes per second, then a legitimate client with a single box should be expected to spend 1 seconds getting a single success.
+
+With the above table we can create some profiles for starting values of our PoW difficulty.
+
+#### Analysis based on Tor's performance {#pow-difficulty-tor}
+
+To go deeper here, we can use the [performance measurements on tor](#tor-measurements) to get a more specific intuition on the starting difficulty.
+In particular, we learned that completely handling an introduction request takes 5.55 msecs in average.
+Using that value, we can compute the following table, that describes the number of introduction requests we can handle per second for different values of PoW verification:
+
+| PoW Verification Time | Total time to handle request | Requests handled per second
+| --------------------- | ---------------------------- | ------------------------
+| 0 msec | 5.55 msec | 180.18
+| 1 msec | 6.55 msec | 152.67
+| 2 msec | 7.55 msec | 132.45
+| 3 msec | 8.55 msec | 116.96
+| 4 msec | 9.55 mesc | 104.71
+| 5 msec | 10.55 msec | 94.79
+| 6 msec | 11.55 msec | 86.58
+| 7 msec | 12.55 msec | 79.68
+| 8 msec | 13.55 msec | 73.80
+| 9 msec | 14.55 msec | 68.73
+| 10 msec | 15.55 msec | 64.31
+
+Here is how you can read the table above:
+
+- For a PoW function with a 1ms verification time, an attacker needs to send 152 high-effort introduction requests per second to succeed in a [bottom-half attack](#attack-bottom-half) attack.
+- For a PoW function with a 10ms verification time, an attacker needs to send 64 high-effort introduction requests per second to succeed in a [bottom-half attack](#attack-bottom-half) attack.
+
+We can use this table to specify a starting difficulty that won't allow our target adversary to succeed in an [bottom-half attack](#attack-bottom-half) attack.
+
+Note that in practice verification times are much lower; the scale of the above table does not match the current implementation's reality.
+
+## User experience {#ux}
+
+This proposal has user facing UX consequences.
+
+When the client first attempts a pow, it can note how long iterations of the hash function take, and then use this to determine an estimation of the duration of the PoW.
+This estimation could be communicated via the control port or other mechanism, such that the browser could display how long the PoW is expected to take on their device.
+If the device is a mobile platform, and this time estimation is large, it could recommend that the user try from a desktop machine.
+
+## Future work {#future-work}
+
+### Incremental improvements to this proposal
+
+There are various improvements that can be done in this proposal, and while we are trying to keep this `v1` version simple, we need to keep the design extensible so that we build more features into it. In particular:
+
+- End-to-end introduction ACKs
+
+ This proposal suffers from various UX issues because there is no end-to-end
+ mechanism for an onion service to inform the client about its introduction
+ request.
+ If we had end-to-end introduction ACKs many of the problems seen in [client-side effort estimation](./common-protocol.md#client-effort) would be alleviated.
+ The problem here is that end-to-end ACKs require modifications on the introduction point code and a network update which is a lengthy process.
+
+- Multithreading scheduler
+
+ Our scheduler is pretty limited by the fact that Tor has a single-threaded design.
+ If we improve our multithreading support we could handle a much greater amount of introduction requests per second.
+
+### Future designs {#future-designs}
+
+This is just the beginning in DoS defences for Tor and there are various future designs and schemes that we can investigate. Here is a brief summary of these:
+
+- "More advanced PoW schemes" --
+ We could use more advanced memory-hard PoW schemes like MTP-argon2 or Itsuku to make it even harder for adversaries to create successful PoWs. Unfortunately these schemes have much bigger proof sizes, and they won't fit in INTRODUCE1 messages. See #31223 for more details.
+
+- "Third-party anonymous credentials" --
+ We can use anonymous credentials and a third-party token issuance server on the clearnet to issue tokens based on PoW or CAPTCHA and then use those tokens to get access to the service. See `[REF_CREDS]` for more details.
+
+- "PoW + Anonymous Credentials" --
+ We can make a hybrid of the above ideas where we present a hard puzzle to the user when connecting to the onion service, and if they solve it we then give the user a bunch of anonymous tokens that can be used in the future.
+ This can all happen between the client and the service without a need for a third party.
+
+All of the above approaches are much more complicated than the `v1` design, and hence we want to start easy before we get into more serious projects.
+The current implementation requires complexity within the Equi-X implementation but its impact on the overall tor network can be relatively simple.
+
+## Environment {#environment}
+
+This algorithm shares a broad concept, proof of work, with some notoriously power hungry and wasteful software. We love the environment, and we too are concerned with how proof of work schemes typically waste huge amounts of energy by doing useless hash iterations.
+
+Nevertheless, there are some massive differences in both the scale and the dynamics of what we are doing here: we are performing fairly small amounts of computation, and it's used as part of a scheme to disincentivize attacks entirely. If we do our job well, people stop computing these proof-of-work functions entirely and find something else to attack.
+
+We think we aren't making a bad situation worse: DoS attacks on the Tor network are already happening and attackers are already burning energy to carry them out.
+As we see in the [denial-of-service overview](../dos-spec/overview.md#hs-intro), attacks on onion services are in a position to cause downstream resource consumption of nearly every type.
+Each relay involved experiences increased CPU load from the circuit floods they process.
+We think that asking legitimate clients to carry out PoW computations doesn't affect the equation too much, since an attacker right now can very quickly use the same resources that hundreds of legitimate clients do in a whole day.
+
+We hope to make things better: The hope is that systems like this will make the DoS actors go away and hence the PoW system will not be used.
+As long as DoS is happening there will be a waste of energy, but if we manage to demotivate them with technical means, the network as a whole will less wasteful.
+Also see [The DoS Catch-22](./motivation.md#catch22).
+
+## Acknowledgements {#acknowledgements}
+
+Thanks a lot to tevador for the various improvements to the proposal and for helping us understand and tweak the RandomX scheme.
+
+Thanks to Solar Designer for the help in understanding the current PoW landscape, the various approaches we could take, and teaching us a few neat tricks.
+
+## Scheduler implementation for C tor {#tor-scheduler}
+
+This section describes how we will implement this proposal in the "tor" software (little-t tor).
+
+The following should be read as if tor is an onion service and thus the end point of all inbound data.
+
+### The Main Loop {#tor-main-loop}
+
+Tor uses libevent for its mainloop.
+For network I/O operations, a mainloop event is used to inform tor if it can read on a certain socket, or a connection object in tor.
+
+From there, this event will empty the connection input buffer (inbuf) by extracting and processing a request at a time.
+The mainloop is single threaded and thus each request is handled sequentially.
+
+Processing an INTRODUCE2 message at the onion service means a series of operations (in order):
+
+1. Unpack relay cell from inbuf to local buffer.
+2. Decrypt cell (AES operations).
+3. Parse relay message and process it depending on its RELAY_COMMAND.
+4. INTRODUCE2 handling which means building a rendezvous circuit:
+ - Path selection
+ - Launch circuit to first hop.
+5. Return to mainloop event which essentially means back to step (1).
+
+Tor will read at most 32 messages out of the inbuf per mainloop round.
+
+### Requirements for PoW {#tor-pow-queue}
+
+With this proposal, in order to prioritize requests by the amount of PoW work
+it has done, requests can *not* be processed sequentially as described above.
+
+Thus, we need a way to queue a certain number of requests, prioritize them and then process some request(s) from the top of the queue (that is, the requests that have done the most PoW effort).
+
+We thus require a new request processing flow that is *not* compatible with current tor design. The elements are:
+
+- Validate PoW and place requests in a priority queue of introduction requests ([the introduction queue](./common-protocol.md#intro-queue)).
+- Defer "bottom half" request processing for after requests have been queued into the priority queue.
+
+### Proposed scheduler {#tor-scheduler}
+
+The intuitive way to address the [queueing requirements](#tor-pow-queue) above would be to do this simple and naive approach:
+
+1. Mainloop: Empty inbuf of introduction requests into priority queue
+2. Process all requests in pqueue
+3. Goto (1)
+
+However, we are worried that handling all those requests before returning to the mainloop opens possibilities of attack by an adversary since the priority queue is not gonna be kept up to date while we process all those requests.
+This means that we might spend lots of time dealing with introductions that don't deserve it.
+
+We thus propose to split the INTRODUCE2 handling into two different steps: "top half" and "bottom half" process.
+
+#### Top half and bottom half {#top-half-bottom-half}
+
+The top half process is responsible for queuing introductions into the priority queue as follows:
+
+1. Unpack cell from inbuf to local buffer.
+2. Decrypt cell (AES operations).
+3. Parse INTRODUCE2 message and validate PoW.
+4. Return to mainloop event which essentially means step (1).
+
+The top-half basically does all operations from the [main loop](#tor-main-loop) section above, excepting (4).
+
+An then, the bottom-half process is responsible for handling introductions and doing rendezvous.
+To achieve this we introduce a new mainloop event to process the priority queue _after_ the top-half event has completed.
+This new event would do these operations sequentially:
+
+1. Pop INTRODUCE2 message from priority queue.
+2. Parse and process INTRODUCE2 message.
+3. End event and yield back to mainloop.
+
+#### Scheduling the bottom half process {#sched-bottom-half}
+
+The question now becomes: when should the "bottom half" event get triggered from the mainloop?
+
+We propose that this event is scheduled in when the network I/O event queues at least 1 request into the priority queue. Then, as long as it has a request in the queue, it would re-schedule itself for immediate execution meaning at the next mainloop round, it would execute again.
+
+The idea is to try to empty the queue as fast as it can in order to provide a fast response time to an introduction request but always leave a chance for more requests to appear between request processing by yielding back to the mainloop.
+With this we are aiming to always have the most up-to-date version of the priority queue when we are completing introductions:
+this way we are prioritizing clients that spent a lot of time and effort completing their PoW.
+
+If the size of the queue drops to 0, it stops scheduling itself in order to not create a busy loop.
+The network I/O event will re-schedule it in time.
+
+Notice that the proposed solution will make the service handle 1 single introduction request at every main loop event.
+However, when we do performance measurements we might learn that it's preferable to bump the number of requests in the future from 1 to N where N <= 32.
+
+## Performance measurements
+
+This section will detail the performance measurements we've done on `tor.git` for handling an INTRODUCE2 message and then a discussion on how much more CPU time we can add (for PoW validation) before it badly degrades our performance.
+
+### Tor measurements {#tor-measurements}
+
+In this section we will derive measurement numbers for the "top half" and "bottom half" parts of handling an introduction request.
+
+These measurements have been done on tor.git at commit
+`80031db32abebaf4d0a91c01db258fcdbd54a471`.
+
+We've measured several set of actions of the INTRODUCE2 message handling process on Intel(R) Xeon(R) CPU E5-2650 v4.
+Our service was accessed by an array of clients that sent introduction requests for a period of 60 seconds.
+
+1. Full Mainloop Event
+
+ We start by measuring the full time it takes for a mainloop event to process an inbuf containing INTRODUCE2 messages. The mainloop event processed 2.42 messages per invocation on average during our measurements.
+
+ ```text
+ Total measurements: 3279
+
+ Min: 0.30 msec - 1st Q.: 5.47 msec - Median: 5.91 msec
+ Mean: 13.43 msec - 3rd Q.: 16.20 msec - Max: 257.95 msec
+ ```
+
+2. INTRODUCE2 message processing (bottom-half)
+
+ We also measured how much time the "bottom half" part of the process takes.
+ That's the heavy part of processing an introduction request as seen in step (4) of the [main loop](#tor-main-loop) section above:
+
+ ```text
+ Total measurements: 7931
+
+ Min: 0.28 msec - 1st Q.: 5.06 msec - Median: 5.33 msec
+ Mean: 5.29 msec - 3rd Q.: 5.57 msec - Max: 14.64 msec
+ ```
+
+3. Connection data read (top half)
+
+ Now that we have the above pieces, we can use them to measure just the "top half" part of the procedure.
+ That's when bytes are taken from the connection inbound buffer and parsed into an INTRODUCE2 message where basic validation is done.
+
+ There is an average of 2.42 INTRODUCE2 messages per mainloop event and so we divide that by the full mainloop event mean time to get the time for one message.
+ From that we subtract the "bottom half" mean time to get how much the "top half" takes:
+
+ ```text
+ => 13.43 / (7931 / 3279) = 5.55
+ => 5.55 - 5.29 = 0.26
+
+ Mean: 0.26 msec
+ ```
+
+To summarize, during our measurements the average number of INTRODUCE2 messages a mainloop event processed is ~2.42 messages (7931 messages for 3279 mainloop invocations).
+
+This means that, taking the mean of mainloop event times, it takes ~5.55msec (13.43/2.42) to completely process an INTRODUCE2 messages.
+Then if we look deeper we see that the "top half" of INTRODUCE2 message processing takes 0.26 msec in average, whereas the "bottom half" takes around 5.33 msec.
+
+The heavyness of the "bottom half" is to be expected since that's where 95% of the total work takes place: in particular the rendezvous path selection and circuit launch.
+
+## References
+
+```text
+ [REF_EQUIX]: https://github.com/tevador/equix
+ https://github.com/tevador/equix/blob/master/devlog.md
+ [REF_TABLE]: The table is based on the script below plus some manual editing for readability:
+ https://gist.github.com/asn-d6/99a936b0467b0cef88a677baaf0bbd04
+ [REF_BOTNET]: https://media.kasperskycontenthub.com/wp-content/uploads/sites/43/2009/07/01121538/ynam_botnets_0907_en.pdf
+ [REF_CREDS]: https://lists.torproject.org/pipermail/tor-dev/2020-March/014198.html
+ [REF_TARGET]: https://en.bitcoin.it/wiki/Target
+ [REF_TEVADOR_2]: https://lists.torproject.org/pipermail/tor-dev/2020-June/014358.html
+ [REF_TEVADOR_SIM]: https://github.com/mikeperry-tor/scratchpad/blob/master/tor-pow/effort_sim.py#L57
+```
diff --git a/spec/hspow-spec/common-protocol.md b/spec/hspow-spec/common-protocol.md
new file mode 100644
index 0000000..cd98643
--- /dev/null
+++ b/spec/hspow-spec/common-protocol.md
@@ -0,0 +1,203 @@
+# Common protocol
+
+We have made an effort to split the design of the proof-of-work subsystem into an algorithm-specific piece that can be upgraded, and a core protocol that provides queueing and effort adjustment.
+
+Currently there is only one versioned subprotocol defined:
+- [Version 1, Equi-X and Blake2b](./v1-equix.md)
+
+## Overview
+
+```text
+ +----------------------------------+
+ | Onion Service |
+ +-------+ INTRO1 +-----------+ INTRO2 +--------+ |
+ |Client |-------->|Intro Point|------->| PoW |-----------+ |
+ +-------+ +-----------+ |Verifier| | |
+ +--------+ | |
+ | | |
+ | | |
+ | +----------v---------+ |
+ | |Intro Priority Queue| |
+ +---------+--------------------+---+
+ | | |
+ Rendezvous | | |
+ circuits | | |
+ v v v
+```
+
+The proof-of-work scheme specified in this document takes place during the [introduction phase of the onion service protocol](../rend-spec/introduction-protocol.md).
+
+The system described in this proposal is not meant to be on all the time, and it can be entirely disabled for services that do not experience DoS attacks.
+
+When the subsystem is enabled, suggested effort is continuously adjusted and the computational puzzle can be bypassed entirely when the effort reaches zero.
+In these cases, the proof-of-work subsystem can be dormant but still provide the necessary parameters for clients to voluntarily provide effort in order to get better placement in the priority queue.
+
+The protocol involves the following major steps:
+
+1. Service encodes PoW parameters in descriptor: `pow-params` in the [second layer plaintext format](../rend-spec/hsdesc-encrypt.md#second-layer-plaintext).
+2. Client fetches descriptor and begins solving. Currently this must use the [`v1` solver algorithm](../hspow-spec/v1-equix.md#client-solver).
+3. Client finishes solving and sends results using the [proof-of-work extension to INTRODUCE1](../rend-spec/introduction-protocol.md#INTRO1_POW_EXT).
+4. Service verifies the proof and queues an introduction based on proven effort. This currently uses the [`v1` verify algorithm](../hspow-spec/v1-equix.md#service-verify) only.
+5. Requests are continuously drained from the queue, highest effort first, subject to multiple constraints on speed. See below for more on [handling queued requests](#handling-queue).
+
+## Replay protection {#replay-protection}
+
+The service MUST NOT accept introduction requests with the same (seed, nonce) tuple.
+For this reason a replay protection mechanism must be employed.
+
+The simplest way is to use a hash table to check whether a (seed, nonce) tuple has been used before for the active duration of a seed.
+Depending on how long a seed stays active this might be a viable solution with reasonable memory/time overhead.
+
+If there is a worry that we might get too many introductions during the lifetime of a seed, we can use a Bloom filter or similar as our replay cache mechanism. A probabilistic filter means that we will potentially flag some connections as replays even if they are not, with this false positive probability increasing as the number of entries increase. With the right parameter tuning this probability should be negligible, and dropped requests will be retried by the client.
+
+## The introduction queue {#intro-queue}
+
+When proof-of-work is enabled for a service, that service diverts all incoming introduction requests to a priority queue system rather than handling them immediately.
+
+### Adding introductions to the introduction queue {#add-queue}
+
+When PoW is enabled and an introduction request includes a verified proof, the service queues each request in a data structure sorted by effort. Requests including no proof at all MUST be assigned an effort of zero. Requests with a proof that fails to verify MUST be rejected and not enqueued.
+
+Services MUST check whether the queue is overfull when adding to it, not just when processing requests.
+Floods of low-effort and zero-effort introductions need to be efficiently discarded when the queue is growing faster than it's draining.
+
+The C implementation chooses a maximum number of queued items based on its configured dequeue rate limit multiplied by the circuit timeout.
+In effect, items past this threshold are expected not to be reachable by the time they will timeout.
+When this limit is exceeded, the queue experiences a mass trim event where the lowest effort half of all items are discarded.
+
+### Handling queued introductions {#handling-queue}
+
+When deciding which introduction request to consider next, the service chooses the highest available effort. When efforts are equivalent, the oldest queued request is chosen.
+
+The service should handle introductions only by pulling from the introduction queue.
+We call this part of introduction handling the "bottom half" because most of the computation happens in this stage.
+
+For more on how we expect such a system to work in Tor, see the [scheduler analysis and discussion](./analysis-discussion.md#tor-scheduler) section.
+
+## Effort control {#effort-control}
+
+### Overall strategy for effort determination {#effort-strategy}
+
+Denial-of-service is a dynamic problem where the attacker's capabilities constantly change, and hence we want our proof-of-work system to be dynamic and not stuck with a static difficulty setting.
+Instead of forcing clients to go below a static target configured by the service operator, we ask clients to "bid" using their PoW effort.
+Effectively, a client gets higher priority the higher effort they put into their proof-of-work.
+Clients automatically increase their bid when retrying, and services regularly offer a suggested starting point based on the recent queue status.
+
+[Motivated users](./motivation.md#user-profiles) can spend a high amount of effort in their PoW computation, which should guarantee access to the service given reasonable adversary models.
+
+An effective effort control algorithm will improve reachability and UX by suggesting values that reduce overall service load to tolerable values while also leaving users with a tolerable overall delay.
+
+The service starts with a default suggested-effort value of 0, which keeps the PoW defenses dormant until we notice signs of queue overload.
+
+The entire process of determining effort can be thought of as a set of multiple coupled feedback loops.
+Clients perform their own effort adjustments via [timeout retry](#client-timeout) atop a base effort suggested by the service.
+That suggestion incorporates the service's control adjustments atop a base effort calculated using a sum of currently-queued client effort.
+
+Each feedback loop has an opportunity to cover different time scales.
+Clients can make adjustments at every single circuit creation request, whereas services are limited by the extra load that frequent updates would place on HSDir nodes.
+
+In the combined client/service system these client-side increases are expected to provide the most effective quick response to an emerging DoS attack.
+After early clients increase the effort using timeouts, later clients benefit from the service detecting this increased queued effort and publishing a larger suggested effort.
+
+Effort increases and decreases both have a cost.
+Increasing effort will make the service more expensive to contact,
+and decreasing effort makes new requests likely to become backlogged behind older requests.
+The steady state condition is preferable to either of these side-effects, but ultimately it's expected that the control loop always oscillates to some degree.
+
+### Service-side effort control {#service-effort}
+
+Services keep an internal suggested effort target which updates on a regular periodic timer in response to measurements made on queue behavior in the previous period.
+These internal effort changes can optionally trigger client-visible [descriptor changes](#service-effort-update) when the difference is great enough to warrant republication to the [HSDir](../rend-spec/hsdesc.md).
+
+This evaluation and update period is referred to as `HS_UPDATE_PERIOD`.
+The service-side effort control loop takes inspiration from TCP congestion control's additive increase / multiplicative decrease approach, but unlike a typical AIMD this algorithm is fixed-rate and doesn't update immediately in response to events.
+
+TODO: `HS_UPDATE_PERIOD` is hardcoded to 300 (5 minutes) currently, but it should be configurable in some way.
+Is it more appropriate to use the service's torrc here or a consensus parameter?
+
+#### Per-period service state {#service-effort-periodic}
+
+During each update period, the service maintains some state:
+
+1. `TOTAL_EFFORT`, a sum of all effort values for rendezvous requests that were successfully validated and enqueued.
+2. `REND_HANDLED`, a count of rendezvous requests that were actually launched. Requests that made it to dequeueing but were too old to launch by then are not included.
+3. `HAD_QUEUE`, a flag which is set if at any time in the update period we saw the priority queue filled with more than a minimum amount of work, greater than we would expect to process in approximately 1/4 second using the configured dequeue rate.
+4. `MAX_TRIMMED_EFFORT`, the largest observed single request effort that we discarded during the period. Requests are discarded either due to age (timeout) or during culling events that discard the bottom half of the entire queue when it's too full.
+
+#### Service AIMD conditions {#service-effort-aimd}
+
+At the end of each period, the service may decide to increase effort, decrease effort, or make no changes, based on these accumulated state values:
+
+1. If `MAX_TRIMMED_EFFORT` > our previous internal `suggested_effort`, always INCREASE.
+ Requests that follow our latest advice are being dropped.
+2. If the `HAD_QUEUE` flag was set and the queue still contains at least one item with effort >= our previous internal `suggested_effort`, INCREASE.
+ Even if we haven't yet reached the point of dropping requests, this signal indicates that our latest suggestion isn't high enough and requests will build up in the queue.
+3. If neither condition 1 or 2 are taking place and the queue is below a level we would expect to process in approximately 1/4 second, choose to DECREASE.
+4. If none of these conditions match, the `suggested_effort` is unchanged.
+
+When we INCREASE, the internal `suggested_effort` is increased to either its previous value + 1, or (`TOTAL_EFFORT` / `REND_HANDLED`), whichever is larger.
+
+When we DECREASE, the internal `suggested_effort` is scaled by 2/3rds.
+
+Over time, this will continue to decrease our effort suggestion any time the service is fully processing its request queue.
+If the queue stays empty, the effort suggestion decreases to zero and clients should no longer submit a proof-of-work solution with their first connection attempt.
+
+It's worth noting that the `suggested_effort` is not a hard limit to the efforts that are accepted by the service, and it's only meant to serve as a guideline for clients to reduce the number of unsuccessful requests that get to the service.
+When [adding requests to the queue](#add-queue), services do accept valid solutions with efforts higher or lower than the published values from `pow-params`.
+
+#### Updating descriptor with new suggested effort {#service-effort-update}
+
+The service descriptors may be updated for multiple reasons including introduction point rotation common to all v3 onion services, scheduled seed rotations like the one described for [`v1` parameters](./v1-equix.md#parameter-descriptor), and updates to the effort suggestion.
+Even though the internal effort value updates on a regular timer, we avoid propagating those changes into the descriptor and the HSDir hosts unless there is a significant change.
+
+If the PoW params otherwise match but the seed has changed by less than 15 percent, services SHOULD NOT upload a new descriptor.
+
+### Client-side effort control {#client-effort}
+
+Clients are responsible for making their own effort adjustments in response to connection trouble, to allow the system a chance to react before the service has published new effort values.
+This is an important tool to uphold UX expectations without relying on excessively frequent updates through the HSDir.
+
+TODO: This is the weak link in user experience for our current implementation. The C tor implementation does not detect and retry onion service connections as reliably as we would like. Currently our best strategy to improve retry behavior is the Arti rewrite.
+
+#### Failure ambiguity {#client-failure-ambiguity}
+
+The first challenge in reacting to failure, in our case, is to even accurately and quickly understand when a failure has occurred.
+
+This proposal introduces a bunch of new ways where a legitimate client can fail to reach the onion service.
+Furthermore, there is currently no end-to-end way for the onion service to inform the client that the introduction failed.
+The INTRODUCE_ACK message is not end-to-end (it's from the introduction point to the client) and hence it does not allow the service to inform the client that the rendezvous is never gonna occur.
+
+From the client's perspective there's no way to attribute this failure to the service itself rather than the introduction point, so error accounting is performed separately for each introduction-point.
+Prior mechanisms will discard an introduction point that's required too many retries.
+
+#### Clients handling timeouts {#client-timeout}
+
+Alice can fail to reach the onion service if her introduction request gets trimmed off the priority queue when [enqueueing new requests](#add-queue), or if the service does not get through its priority queue in time and the connection times out.
+
+This section presents a heuristic method for the client getting service even in such scenarios.
+
+If the rendezvous request times out, the client SHOULD fetch a new descriptor for the service to make sure that it's using the right suggested-effort for the PoW and the right PoW seed.
+If the fetched descriptor includes a new suggested effort or seed, it should first retry the request with these parameters.
+
+TODO: This is not actually implemented yet, but we should do it.
+How often should clients at most try to fetch new descriptors?
+Determined by a consensus parameter?
+This change will also allow clients to retry effectively in cases where the service has just been reconfigured to enable PoW defenses.
+
+Every time the client retries the connection, it will count these failures per-introduction-point. These counts of previous retries are combined with the service's `suggested_effort` when calculating the actual effort to spend on any individual request to a service that advertises PoW support, even when the currently advertised `suggested_effort` is zero.
+
+On each retry, the client modifies its solver effort:
+
+1. If the effort is below `CLIENT_POW_EFFORT_DOUBLE_UNTIL` (= 1000) it will be doubled.
+2. Otherwise, multiply the effort by `CLIENT_POW_RETRY_MULTIPLIER` (= 1.5).
+3. Constrain the effort to no less than `CLIENT_MIN_RETRY_POW_EFFORT` (= 8). Note that this limit is specific to retries only. Clients may use a lower effort for their first connection attempt.
+3. Apply the maximum effort limit [described below](#client-limits).
+
+#### Client-imposed effort limits {#client-limits}
+
+There isn't a practical upper limit on effort defined by the protocol itself, but clients may choose a maximum effort limit to enforce.
+It may be desirable to do this in some cases to improve responsiveness, but the main reason for this limit currently is as a workaround for weak cancellation support in our implementation.
+
+Effort values used for both initial connections and retries are currently limited to no greater than `CLIENT_MAX_POW_EFFORT` (= 10000).
+
+TODO: This hardcoded limit should be replaced by timed limits and/or an unlimited solver with robust cancellation. This is [issue 40787](https://gitlab.torproject.org/tpo/core/tor/-/issues/40787) in C tor.
diff --git a/spec/hspow-spec/index.md b/spec/hspow-spec/index.md
new file mode 100644
index 0000000..14db248
--- /dev/null
+++ b/spec/hspow-spec/index.md
@@ -0,0 +1,5 @@
+# Proof of Work for onion service introduction
+
+The overall denial-of-service prevention strategies in Tor are described in the [Denial-of-service prevention mechanisms in Tor](../dos-spec/index.md) document. This document describes one specific mitigation, the proof-of-work client puzzle for onion service introduction.
+
+This was originally [proposal 327, A First Take at PoW Over Introduction Circuits](../proposals/327-pow-over-intro.txt) authored by George Kadianakis, Mike Perry, David Goulet, and tevador.
diff --git a/spec/hspow-spec/motivation.md b/spec/hspow-spec/motivation.md
new file mode 100644
index 0000000..8fffe3f
--- /dev/null
+++ b/spec/hspow-spec/motivation.md
@@ -0,0 +1,85 @@
+# Motivation
+
+See the [denial-of-service overview](../dos-spec/overview.md) for the big-picture view.
+Here we are focusing on a mitigation for attacks on one specific resource: onion service introductions.
+
+Attackers can generate low-effort floods of introductions which cause the onion service and all involved relays to perform a disproportionate amount of work, leading to a denial-of-service opportunity.
+This proof-of-work scheme intends to make introduction floods unattractive to attackers, reducing the network-wide impact of this activity.
+
+Previous to this work, our attempts at limiting the impact of introduction flooding DoS attacks on onion services has been focused on horizontal scaling with Onionbalance, optimizing the CPU usage of Tor and applying rate limiting.
+While these measures move the goalpost forward, a core problem with onion service DoS is that building rendezvous circuits is a costly procedure both for the service and for the network.
+
+For more information on the limitations of rate-limiting when defending against DDoS, see [`draft-nygren-tls-client-puzzles-02`](https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt).
+
+If we ever hope to have truly reachable global onion services, we need to make it harder for attackers to overload the service with introduction requests.
+This proposal achieves this by allowing onion services to specify an optional dynamic proof-of-work scheme that its clients need to participate in if they want to get served.
+
+With the right parameters, this proof-of-work scheme acts as a gatekeeper to block amplification attacks by attackers while letting legitimate clients through.
+
+## Related work {#related-work}
+
+For a similar concept, see the three internet drafts that have been proposed for defending against TLS-based DDoS attacks using client puzzles:
+
+- [`draft-nygren-tls-client-puzzles-02`](https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt)
+- [`draft-nir-tls-puzzles-00`](https://www.ietf.org/archive/id/draft-nir-tls-puzzles-00.txt)
+- [`draft-ietf-ipsecme-ddos-protection-10`](https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10)
+
+## Threat model
+
+### Attacker profiles {#attacker-profiles}
+
+This mitigation is written to thwart specific attackers. The current protocol is not intended to defend against all and every DoS attack on the Internet, but there are adversary models we can defend against.
+
+Let's start with some adversary profiles:
+
+- "The script-kiddie"
+
+ The script-kiddie has a single computer and pushes it to its limits.
+ Perhaps it also has a VPS and a pwned server.
+ We are talking about an attacker with total access to 10 GHz of CPU and 10 GB of RAM.
+ We consider the total cost for this attacker to be zero $.
+
+- "The small botnet"
+
+ The small botnet is a bunch of computers lined up to do an introduction flooding attack.
+ Assuming 500 medium-range computers, we are talking about an attacker with total access to 10 THz of CPU and 10 TB of RAM.
+ We consider the upfront cost for this attacker to be about $400.
+
+- "The large botnet"
+
+ The large botnet is a serious operation with many thousands of computers organized to do this attack.
+ Assuming 100k medium-range computers, we are talking about an attacker with total access to 200 THz of CPU and 200 TB of RAM.
+ The upfront cost for this attacker is about $36k.
+
+We hope that this proposal can help us defend against the script-kiddie attacker and small botnets.
+To defend against a large botnet we would need more tools at our disposal (see the [discussion on future designs](./analysis-discussion.md#future-designs)).
+
+### User profiles {#user-profiles}
+
+We have attackers and we have users. Here are a few user profiles:
+
+- "The standard web user"
+
+ This is a standard laptop/desktop user who is trying to browse the web.
+ They don't know how these defences work and they don't care to configure or tweak them.
+ If the site doesn't load, they are gonna close their browser and be sad at Tor.
+ They run a 2GHz computer with 4GB of RAM.
+
+- "The motivated user"
+
+ This is a user that really wants to reach their destination.
+ They don't care about the journey; they just want to get there.
+ They know what's going on; they are willing to make their computer do expensive multi-minute PoW computations to get where they want to be.
+
+- "The mobile user"
+
+ This is a motivated user on a mobile phone.
+ Even tho they want to read the news article, they don't have much leeway on stressing their machine to do more computation.
+
+We hope that this proposal will allow the motivated user to always connect where they want to connect to, and also give more chances to the other user groups to reach the destination.
+
+### The DoS Catch-22 {#catch22}
+
+This proposal is not perfect and it does not cover all the use cases.
+Still, we think that by covering some use cases and giving reachability to the people who really need it, we will severely demotivate the attackers from continuing the DoS attacks and hence stop the DoS threat all together.
+Furthermore, by increasing the cost to launch a DoS attack, a big class of DoS attackers will disappear from the map, since the expected ROI will decrease.
diff --git a/spec/hspow-spec/v1-equix.md b/spec/hspow-spec/v1-equix.md
new file mode 100644
index 0000000..f49086a
--- /dev/null
+++ b/spec/hspow-spec/v1-equix.md
@@ -0,0 +1,176 @@
+# Onion service proof-of-work: Scheme v1, Equi-X and Blake2b
+
+## Implementations {#implementations}
+
+For our `v1` proof-of-work function we use the Equi-X asymmetric client puzzle algorithm by tevador.
+The concept and the C implementation were developed specifically for our use case by tevador, based on a survey of existing work and an analysis of Tor's requirements.
+
+- [Original Equi-X source repository](https://github.com/tevador/equix)
+- [Development log](https://github.com/tevador/equix/blob/master/devlog.md)
+
+Equi-X is an asymmetric PoW function based on Equihash<60,3>, using HashX as the underlying layer.
+It features lightning fast verification speed, and also aims to minimize the asymmetry between CPU and GPU.
+Furthermore, it's designed for this particular use-case and hence cryptocurrency miners are not incentivized to make optimized ASICs for it.
+
+At this point there is no formal specification for Equi-X or the underlying HashX function.
+We have two actively maintained implementations of both components, which we subject to automated cross-compatibility and fuzz testing:
+
+- A fork of tevador's implementation is maintained within the C tor repository.
+
+ This is the [`src/ext/equix` subdirectory](https://gitlab.torproject.org/tpo/core/tor/-/tree/main/src/ext/equix).
+ Currently this contains important fixes for security, portability, and testability which have not been merged upstream!
+ This implementation is released under the LGPL license.
+ When `tor` is built with the required `--enable-gpl` option this code will be statically linked.
+
+- As part of Arti, a new Rust re-implementation was written based loosely on tevador's original.
+
+ This is the [`equix` crate](https://tpo.pages.torproject.net/core/doc/rust/equix/index.html).
+ This implementation currently has somewhat lower verification performance than the original but otherwise offers equivalent features.
+
+## Algorithm overview {#overview}
+
+The overall scheme consists of several layers that provide different pieces of this functionality:
+
+1. At the lowest layers, Blake2b and siphash are used as hashing and PRNG algorithms that are well suited to common 64-bit CPUs.
+2. A custom hash function family, HashX, randomizes its implementation for each new seed value.
+ These functions are tuned to utilize the pipelined integer performance on a modern 64-bit CPU.
+ This layer provides the strongest ASIC resistance, since a hardware reimplementation would need to include a CPU-like pipelined execution unit to keep up.
+3. The Equi-X layer itself builds on HashX and adds an algorithmic puzzle that's designed to be strongly asymmetric and to require RAM to solve efficiently.
+4. The PoW protocol itself builds on this Equi-X function with a particular construction of the challenge input and particular constraints on the allowed Blake2b hash of the solution.
+ This layer provides a linearly adjustable effort that we can verify.
+5. At this point, all further layers are part of the [common protocol](./common-protocol.md). Above the level of individual PoW handshakes, the client and service form a closed-loop system that adjusts the effort of future handshakes.
+
+Equi-X itself provides two functions that will be used in this proposal:
+- `equix_solve`(`challenge`) which solves a puzzle instance, returning a variable number of solutions per invocation depending on the specific challenge value.
+- `equix_verify`(`challenge`, `solution`) which verifies a puzzle solution quickly.
+ Verification still depends on executing the HashX function, but far fewer times than when searching for a solution.
+
+For the purposes of this proposal, all cryptographic algorithms are assumed to produce and consume byte strings, even if internally they operate on some other data type like 64-bit words.
+This is conventionally little endian order for Blake2b, which contrasts with Tor's typical use of big endian.
+HashX itself is configured with an 8-byte output but its input is a single 64-bit word of undefined byte order, of which only the low 16 bits are used by Equi-X in its solution output.
+We treat Equi-X solution arrays as byte arrays using their packed little endian 16-bit representation.
+
+## Linear effort adjustment {#effort}
+
+The underlying Equi-X puzzle has an approximately fixed computational cost.
+Adjustable effort comes from the construction of the overlying Blake2b layer, which requires clients to test a variable number of Equi-X solutions in order to find answers which also satisfy this layer's effort constraint.
+
+It's common for proof-of-work systems to define an exponential effort function based on a particular number of leading zero bits or equivalent.
+For the benefit of our effort control system, it's quite useful if we have a linear scale instead. We use the first 32 bits of a hashed version of the Equi-X solution as a uniformly distributed random value.
+
+Conceptually we could define a function:
+```text
+unsigned effort(uint8_t *token)
+```
+which takes as its argument a hashed solution, interprets it as a bitstring, and returns the quotient of dividing a bitstring of 1s by it.
+
+So for example:
+```text
+effort(00000001100010101101) = 11111111111111111111
+ / 00000001100010101101
+```
+or the same in decimal:
+```text
+effort(6317) = 1048575 / 6317 = 165.
+```
+
+In practice we can avoid even having to perform this division, performing just one multiply instead to see if a request's claimed effort is supported by the smallness of the resulting 32-bit hash prefix.
+This assumes we send the desired effort explicitly as part of each PoW solution.
+We do want to force clients to pick a specific effort before looking for a solution, otherwise a client could opportunistically claim a very large effort any time a lucky hash prefix comes up.
+Thus the effort is communicated explicitly in our protocol, and it forms part of the concatenated Equi-X challenge.
+
+## Parameter descriptor {#parameter-descriptor}
+
+This whole protocol starts with the service encoding its parameters in a `pow-params` line within the 'encrypted' (inner) part of the v3 descriptor. The [second layer plaintext format](../rend-spec/hsdesc-encrypt.md#second-layer-plaintext) describes it canonically. The parameters offered are:
+- `scheme`, always `v1` for the algorithm described here
+- `seed-b64`, a periodically updated 32-byte random seed, base64 encoded
+- `suggested-effort`, the latest output from the [service-side effort controller](./common-protocol.md#service-effort)
+- `expiration-time`, a timestamp when we plan to replace the seed.
+
+Seed expiration and rotation allows used nonces to expire from the anti-replay memory.
+At every seed rotation, a new expiration time is chosen uniformly at random from the recommended range:
+- At the earliest, 105 minutes in the future
+- At the latest, 2 hours in the future (15 minutes later)
+
+The service SHOULD refresh its seed when expiration-time passes.
+The service SHOULD keep its previous seed in memory and accept PoWs using it to avoid race-conditions with clients that have an old seed.
+The service SHOULD avoid generating two consequent seeds that have a common 4 bytes prefix; see the usage of seed headings below in the [introduction extension](#intro-ext).
+
+## Client computes a solution {#client-solver}
+
+If a client receives a descriptor with `pow-params`, it should assume that the service is prepared to receive PoW solutions as part of the introduction protocol.
+
+The client parses the descriptor and extracts the PoW parameters.
+It makes sure that the `expiration-time` has not expired.
+If it has, the descriptor may be out of date.
+Clients SHOULD fetch a fresh descriptor if the descriptor is stale and the seed is expired.
+
+Inputs to the solver:
+
+1. Effort `E`, the [client-side effort choice](./common-protocol.md#client-effort) made based on the server's `suggested-effort` and the client's connection attempt history. This is a 32-bit unsigned integer.
+2. Constant personalization string `P`, equal to the following nul-terminated ASCII text: `"Tor hs intro v1\0"`.
+3. Identity string `ID`, a 32-byte value unique to the specific onion service. This is the blinded public ID key `KP_hs_blind_id`.
+4. Seed `C`, a 32-byte random value decoded from `seed-b64` above.
+5. Initial nonce `N`, a 16-byte value generated using a secure random generator.
+
+The solver itself is iterative; the following steps are repeated until they succeed:
+
+1. Construct the *challenge string* by concatenating `P || ID || C || N || htonl(E)`.
+2. Calculate a candidate proof `S` by passing this challenge to Equi-X.
+
+ `S = equix_solve(P || ID || C || N || htonl(E))`
+3. Calculate a 32-bit check value by interpreting a 32-bit Blake2b hash of the concatenated challenge and solution as an integer in network byte order.
+
+ `R = ntohl(blake2b_32(P || ID || C || N || htonl(E) || S))`
+4. Check if 32-bit multiplication of `R * E` would overflow
+
+ If `R * E` overflows (the result would be greater than `UINT32_MAX`) the solver must retry with another nonce value. The client interprets N as a 16-byte little-endian integer, increments it by 1, and goes back to step 1.
+
+ If there is no overflow (the result is less than or equal to `UINT32_MAX`) this is a valid solution. The client can submit final nonce `N`, effort `E`, the first 4 bytes of seed `C`, and proof `S`.
+
+Note that the Blake2b hash includes the output length parameter in its initial state vector, so a `blake2b_32` is not equivalent to the prefix of a `blake2b_512`.
+We calculate the 32-bit Blake2b specifically, and interpret it in network byte order as an unsigned integer.
+
+At the end of the above procedure, the client should have calculated a proof `S` and final nonce `N` that satisfies both the Equi-X proof conditions and the Blake2b effort test.
+The time taken, on average, is linearly proportional with the target effort `E` parameter.
+
+The algorithm as described is suitable for single-threaded computation.
+Optionally, a client may choose multiple nonces and attempt several solutions in parallel on separate CPU cores.
+The specific choice of nonce is entirely up to the client, so parallelization choices like this do not impact the network protocol's interoperability at all.
+
+## Client sends its proof in an INTRO1 extension {#intro-ext}
+
+Now that the client has an answer to the puzzle it's time to encode it into an INTRODUCE1 message.
+To do so the client adds an extension to the encrypted portion of the INTRODUCE1 message by using the EXTENSIONS field. The encrypted portion of the INTRODUCE1 message only gets read by the onion service and is ignored by the introduction point.
+
+This extension includes the chosen nonce and effort in full, as well as the actual Equi-X proof.
+Clients provide only the first 4 bytes of the seed, enough to disambiguate between multiple recent seeds offered by the service.
+
+This format is defined canonically as the [proof-of-work extension to INTRODUCE1](../rend-spec/introduction-protocol.md#INTRO1_POW_EXT).
+
+## Service verifies PoW and handles the introduction {#service-verify}
+
+When a service receives an INTRODUCE1 with the `PROOF_OF_WORK` extension, it should check its configuration on whether proof-of-work is enabled on the service.
+If it's not enabled, the extension SHOULD BE ignored.
+If enabled, even if the suggested effort is currently zero, the service follows the procedure detailed in this section.
+
+If the service requires the `PROOF_OF_WORK` extension but received an INTRODUCE1 message without any embedded proof-of-work, the service SHOULD consider this message as a zero-effort introduction for the purposes of the [priority queue](./common-protocol.md#intro-queue).
+
+To verify the client's proof-of-work the service MUST do the following steps:
+
+1. Find a valid seed `C` that starts with `POW_SEED`.
+ Fail if no such seed exists.
+2. Fail if `N = POW_NONCE` is present in the [replay protection data structure](./common-protocol.md#replay-protection).
+3. Construct the *challenge string* as above by concatenating `P || ID || C || N || htonl(E)`. In this case, `E` and `N` are values provided by the client.
+4. Calculate `R = ntohl(blake2b_32(P || ID || C || N || htonl(E) || S))`, as above
+5. Fail if the the effort test overflows (`R * E > UINT32_MAX`).
+6. Fail if Equi-X reports that the proof `S` is malformed or not applicable (`equix_verify(P || ID || C || N || htonl(E), S) != EQUIX_OK`)
+7. If both the Blake2b and Equi-X tests pass, the request can be enqueued with priority `E`.
+
+It's a minor performance optimization for services to compute the effort test before invoking `equix_verify`.
+Blake2b verification is cheaper than Equi-X verification, so this ordering slightly raises the minimum effort required to perform a [top-half attack](./analysis-discussion.md#attack-top-half).
+
+If any of these steps fail the service MUST ignore this introduction request and abort the protocol.
+
+In this document we call the above steps the "top half" of introduction handling.
+If all the steps of the "top half" have passed, then the circuit is added to the [introduction queue](./common-protocol.md#intro-queue).