From 0f3a2d9d8cd9e79a25594f19e8122e202e344b5c Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:15:36 -0800 Subject: Move dos-spec down a level to dos-spec/memory-exhaustion --- spec/dos-spec.md | 96 -------------------------------------- spec/dos-spec/memory-exhaustion.md | 96 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 96 deletions(-) delete mode 100644 spec/dos-spec.md create mode 100644 spec/dos-spec/memory-exhaustion.md diff --git a/spec/dos-spec.md b/spec/dos-spec.md deleted file mode 100644 index d37649f..0000000 --- a/spec/dos-spec.md +++ /dev/null @@ -1,96 +0,0 @@ -# Denial-of-service prevention mechanisms in Tor - -This document is incomplete; it describes some mechanisms that Tor -uses to avoid different kinds of denial-of-service attacks. - -## Handling low-memory conditions { #oom } - -(See also `tor-spec.txt`, section 8.1.) - -The Tor protocol requires clients, onion services, relays, and -authorities to store various kind of information in buffers and -caches. But an attacker can use these buffers and queues to queues -to exhaust the memory of the a targeted Tor process, and force the -operating system to kill that process. - -Worse still, the ability to kill targeted Tor instances can be used -to facilitate traffic analysis. (For example, see -[the "Sniper Attack" paper](https://www.freehaven.net/anonbib/#sniper14) -by Jansen, Tschorsch, Johnson, and Scheuermann. - -With this in mind, any Tor implementation—especially one that -runs as a relay or onion service—must take steps to prevent -memory-based denial-of-service attacks. - -### Detecting low memory { #oom-detection } - -The easiest way to notice you're out of memory would, in theory, be -getting an error when you try to allocate more. Unfortunately, some -systems (e.g. Linux) won't actually give you an "out of memory" -error when you're low on memory. Instead, they overcommit and -promise you memory that they can't actually provide… and then later on, -they might kill processes that actually try to use more memory than -they wish they'd given out. - -So in practice, the mainline Tor implementation uses a different -strategy. It uses a self-imposed "MaxMemInQueues" value as an -upper bound for how much memory it's willing to allocate to certain -kinds of queued usages. This value can either be set by the user, -or derived from a fraction of the total amount of system RAM. - -As of Tor 0.4.7.x, the MaxMemInQueues mechanism tracks the following -kinds of allocation: - -- Cells queued on circuits. -- Per-connection read or write buffers. -- On-the-fly compression or decompression state. -- Half-open stream records. -- Cached onion service descriptors (hsdir only). -- Cached DNS resolves (relay only). -- GEOIP-based usage activity statistics. - -Note that directory caches aren't counted, since those are stored on -disk and accessed via mmap. - -### Responding to low memory { #oom-response } - -If our allocations exceed MaxMemInQueues, then we take the following -steps to reduce our memory allocation. - -*Freeing from caches*: For each of our onion service descriptor -cache, our DNS cache, and our GEOIP statistics cache, we check -whether they account for greater than 20% of our total allocation. -If they do, we free memory from the offending cache until the total -remaining is no more than 10% of our total allocation. - -When freeing entries from a cache, we aim to free (approximately) -the oldest entries first. - -*Freeing from buffers*: After freeing data from caches, we see -whether allocations are still above 90% of MaxMemInQueues. If they -are, we try to close circuits and connections until we are below 90% -of MaxMemInQueues. - -When deciding to what circuits to free, we sort them based on the -age of the oldest data in their queues, and free the ones with the -oldest data. (For example, a circuit on which a single cell has -been queued for 5 minutes would be freed before a circuit where 100 -cells have been queued for 5 seconds.) "Data queued on a circuit" -includes all data that we could drop if the circuit were destroyed: -not only the cells on the circuit's cell queue, but also any bytes -queued in buffers associated with streams or half-stream records -attached to the circuit. - -We free non-tunneled directory connections according to a similar -rule, according to the age of their oldest queued data. - -Upon freeing a circuit, a "DESTROY cell" must be sent in both -directions. - -### Reporting low memory { #oom-reporting } - -We define a "low threshold" equal to 3/4 of MaxMemInQueues. Every -time our memory usage is above the low threshold, we record -ourselves as being "under memory pressure". - -(This is not currently reported.) diff --git a/spec/dos-spec/memory-exhaustion.md b/spec/dos-spec/memory-exhaustion.md new file mode 100644 index 0000000..d37649f --- /dev/null +++ b/spec/dos-spec/memory-exhaustion.md @@ -0,0 +1,96 @@ +# Denial-of-service prevention mechanisms in Tor + +This document is incomplete; it describes some mechanisms that Tor +uses to avoid different kinds of denial-of-service attacks. + +## Handling low-memory conditions { #oom } + +(See also `tor-spec.txt`, section 8.1.) + +The Tor protocol requires clients, onion services, relays, and +authorities to store various kind of information in buffers and +caches. But an attacker can use these buffers and queues to queues +to exhaust the memory of the a targeted Tor process, and force the +operating system to kill that process. + +Worse still, the ability to kill targeted Tor instances can be used +to facilitate traffic analysis. (For example, see +[the "Sniper Attack" paper](https://www.freehaven.net/anonbib/#sniper14) +by Jansen, Tschorsch, Johnson, and Scheuermann. + +With this in mind, any Tor implementation—especially one that +runs as a relay or onion service—must take steps to prevent +memory-based denial-of-service attacks. + +### Detecting low memory { #oom-detection } + +The easiest way to notice you're out of memory would, in theory, be +getting an error when you try to allocate more. Unfortunately, some +systems (e.g. Linux) won't actually give you an "out of memory" +error when you're low on memory. Instead, they overcommit and +promise you memory that they can't actually provide… and then later on, +they might kill processes that actually try to use more memory than +they wish they'd given out. + +So in practice, the mainline Tor implementation uses a different +strategy. It uses a self-imposed "MaxMemInQueues" value as an +upper bound for how much memory it's willing to allocate to certain +kinds of queued usages. This value can either be set by the user, +or derived from a fraction of the total amount of system RAM. + +As of Tor 0.4.7.x, the MaxMemInQueues mechanism tracks the following +kinds of allocation: + +- Cells queued on circuits. +- Per-connection read or write buffers. +- On-the-fly compression or decompression state. +- Half-open stream records. +- Cached onion service descriptors (hsdir only). +- Cached DNS resolves (relay only). +- GEOIP-based usage activity statistics. + +Note that directory caches aren't counted, since those are stored on +disk and accessed via mmap. + +### Responding to low memory { #oom-response } + +If our allocations exceed MaxMemInQueues, then we take the following +steps to reduce our memory allocation. + +*Freeing from caches*: For each of our onion service descriptor +cache, our DNS cache, and our GEOIP statistics cache, we check +whether they account for greater than 20% of our total allocation. +If they do, we free memory from the offending cache until the total +remaining is no more than 10% of our total allocation. + +When freeing entries from a cache, we aim to free (approximately) +the oldest entries first. + +*Freeing from buffers*: After freeing data from caches, we see +whether allocations are still above 90% of MaxMemInQueues. If they +are, we try to close circuits and connections until we are below 90% +of MaxMemInQueues. + +When deciding to what circuits to free, we sort them based on the +age of the oldest data in their queues, and free the ones with the +oldest data. (For example, a circuit on which a single cell has +been queued for 5 minutes would be freed before a circuit where 100 +cells have been queued for 5 seconds.) "Data queued on a circuit" +includes all data that we could drop if the circuit were destroyed: +not only the cells on the circuit's cell queue, but also any bytes +queued in buffers associated with streams or half-stream records +attached to the circuit. + +We free non-tunneled directory connections according to a similar +rule, according to the age of their oldest queued data. + +Upon freeing a circuit, a "DESTROY cell" must be sent in both +directions. + +### Reporting low memory { #oom-reporting } + +We define a "low threshold" equal to 3/4 of MaxMemInQueues. Every +time our memory usage is above the low threshold, we record +ourselves as being "under memory pressure". + +(This is not currently reported.) -- cgit v1.2.3-54-g00ecf From 42d6e2ea4a8c120dc0614f4e1e4ed5472f67ee67 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:23:01 -0800 Subject: Denial of service overview and related edits This also moves some text from memory-exhaustion to overview, and it removes the tor-spec/resource-exhaustion section as it's redundant with the description of the same in dos-spec. --- spec/SUMMARY.md | 5 ++- spec/dos-spec/index.md | 7 ++++ spec/dos-spec/memory-exhaustion.md | 26 ++---------- spec/dos-spec/overview.md | 78 ++++++++++++++++++++++++++++++++++++ spec/tor-spec/resource-exhaustion.md | 31 -------------- 5 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 spec/dos-spec/index.md create mode 100644 spec/dos-spec/overview.md delete mode 100644 spec/tor-spec/resource-exhaustion.md diff --git a/spec/SUMMARY.md b/spec/SUMMARY.md index c425ee6..9cd0933 100644 --- a/spec/SUMMARY.md +++ b/spec/SUMMARY.md @@ -29,7 +29,6 @@ - [Closing streams](./tor-spec/closing-streams.md) - [Remote hostname lookup](./tor-spec/remote-hostname-lookup.md) - [Flow control](./tor-spec/flow-control.md) - - [Handling resource exhaustion](./tor-spec/resource-exhaustion.md) - [Subprotocol versioning](./tor-spec/subprotocol-versioning.md) - [`Ed25519 certificates in Tor`](./cert-spec.md) - [`Tor directory protocol, version 3`](./dir-spec/index.md) @@ -95,7 +94,9 @@ - [Connection-level padding](./padding-spec/connection-level-padding.md) - [Circuit-level padding](./padding-spec/circuit-level-padding.md) - [Acknowledgments](./padding-spec/acknowledgments.md) -- [Preventing Denial-Of-Service](./dos-spec.md) +- [`Preventing Denial-Of-Service`](./dos-spec/index.md) + - [Overview](./dos-spec/overview.md) + - [Memory exhaustion](./dos-spec/memory-exhaustion.md) # Additional behaviors for clients diff --git a/spec/dos-spec/index.md b/spec/dos-spec/index.md new file mode 100644 index 0000000..1f88b09 --- /dev/null +++ b/spec/dos-spec/index.md @@ -0,0 +1,7 @@ +# Denial-of-service prevention mechanisms in Tor + +This document covers the strategy, motivation, and implementation for denial-of-service mitigation systems designed into Tor. + +The older `dos-spec` document is now the [Memory exhaustion](./dos-spec/memory-exhaustion.md) section here. + +An in-depth description of the proof of work mechanism for onion services, originally [proposal 327](../../proposals/327-pow-over-intro.txt), is now in the [Proof of Work for onion service introduction](../hspow-spec/index.md) spec. \ No newline at end of file diff --git a/spec/dos-spec/memory-exhaustion.md b/spec/dos-spec/memory-exhaustion.md index d37649f..591d950 100644 --- a/spec/dos-spec/memory-exhaustion.md +++ b/spec/dos-spec/memory-exhaustion.md @@ -1,28 +1,10 @@ -# Denial-of-service prevention mechanisms in Tor +# Memory exhaustion { #oom } -This document is incomplete; it describes some mechanisms that Tor -uses to avoid different kinds of denial-of-service attacks. +Memory exhaustion is a broad issue with many underlying causes. The Tor protocol requires clients, onion services, relays, and authorities to store various kind of information in buffers and caches. But an attacker can use these buffers and queues to exhaust the memory of the a targeted Tor process, and force the operating system to kill that process. -## Handling low-memory conditions { #oom } +With this in mind, any Tor implementation—especially one that runs as a relay or onion service—must take steps to prevent memory-based denial-of-service attacks. -(See also `tor-spec.txt`, section 8.1.) - -The Tor protocol requires clients, onion services, relays, and -authorities to store various kind of information in buffers and -caches. But an attacker can use these buffers and queues to queues -to exhaust the memory of the a targeted Tor process, and force the -operating system to kill that process. - -Worse still, the ability to kill targeted Tor instances can be used -to facilitate traffic analysis. (For example, see -[the "Sniper Attack" paper](https://www.freehaven.net/anonbib/#sniper14) -by Jansen, Tschorsch, Johnson, and Scheuermann. - -With this in mind, any Tor implementation—especially one that -runs as a relay or onion service—must take steps to prevent -memory-based denial-of-service attacks. - -### Detecting low memory { #oom-detection } +## Detecting low memory { #oom-detection } The easiest way to notice you're out of memory would, in theory, be getting an error when you try to allocate more. Unfortunately, some diff --git a/spec/dos-spec/overview.md b/spec/dos-spec/overview.md new file mode 100644 index 0000000..d715b51 --- /dev/null +++ b/spec/dos-spec/overview.md @@ -0,0 +1,78 @@ +# Overview + +As a public and anonymous network, Tor is open to many types of denial-of-service attempts. It's necessary to constantly develop a variety of defenses that mitigate specific types of attacks. + +These mitigations are expected to improve network availability, but DoS mitigation is also important for limiting the avenues an attacker could use to perform active attacks on anonymity. For example, the ability to kill targeted Tor instances can be used to facilitate traffic analysis. See the ["Sniper Attack" paper](https://www.freehaven.net/anonbib/#sniper14) by Jansen, Tschorsch, Johnson, and Scheuermann. + +The attack and defense environment changes over time. +Expect that this document is an attempt to describe the current state of things, but that it may not be complete. + +The defenses here are organized by the type of resource under contention. These can be physical resources (Memory, CPU, Bandwidth) or protocol resources (Connections, Circuits, Introductions). + +In practice there are always overlaps between these resource types. +Connecting to an onion service, for example, puts some strain on every resource type here. + +## Physical resources + +### Memory {#memory} + +[Memory exhaustion](./memory-exhaustion.md) is both one of the most serious denial-of-service avenues and the subject of the most fully developed defense mechanisms so far. We track overall memory use and free the most disposable objects first when usage is over threshold. + +### CPU {#cpu} + +The available CPU time on a router can be exhausted, assuming the implementation is not capable of processing network input at line rate in all circumstances. +This is especially problematic in the single-threaded C implementation. +Certain expensive operations like circuit extension handshakes are deferred to a thread pool, but time on the main thread is still a precious resource. + +We currently don't directly monitor and respond to CPU usage. +Instead C Tor relies on limits for protocol resources, like circuits extensions and onion service introductions, that are associated with this CPU load. + +### Bandwidth {#bandwidth} + +Relay operators can place hard limits on total bandwidth using the `Bandwidth` or `RelayBandwidth` options. These options can help relay operators avoid bandwidth peaks on their network, however they aren't designed as denial of service prevention mechanisms. + +Beyond just shaving off harmful bandwidth peaks it's important that normal service is not disrupted too much, and especially not disrupted in a targetable way. +To approximate this goal we rely on [flow control](../tor-spec/flow-control.md) and fair dequeueing of relayed cells. + +## Protocol resources + +### Channels {#channels} + +All channels to some extent are a limited resource, but we focus specifically on preventing floods of incoming TLS connections. + +Excessive incoming TLS connections consume memory as well as limited network and operating system resources. +Excessive incoming connections typically signal a low-effort denial of service attack. + +The C Tor implementation establishes limits on both the number of concurrent connections per IP address and the rate of new connections, using the `DoSConnection` family of configuration options and their corresponding consensus parameters. + +### Circuits {#circuits} + +Excessive circuit creation can impact the entire path of that circuit, so it's important to reject these attacks any time they can be identified. Ideally we reject them as early as possible, before they have fully built the circuit. + +Because of Tor's anonymity, most affected nodes experience the circuit flood as coming from every direction. The guard position, however, has a chance to notice specific peers that are creating too many circuits. + +The C Tor implementation limits the acceptable rate of circuit creation per client IP address using the `DoSCircuit` configuration options and their corresponding consensus parameters. + +### Onion service introductions {#hs-intro} + +Flooding an onion service with introduction attempts causes significant network load. In addition to the CPU, memory, and bandwidth load experienced by the introduction point and the service, all involved relays experience a circuit creation flood. + +We have two types of onion service DoS mitigations currently. Both are optional, enabled as needed by individual onion servce operators. + +#### Mitigation by rate limiting {#hs-intro-rate} + +Introduction attempts can be rate-limited by each introduction point, at the request of the service. + +This defense is configured by an operator using the `HiddenServiceEnableIntroDos` configuration options. Services use the [introduction DoS extension](../rend-spec/introduction-protocol.html#EST_INTRO_DOS_EXT) to communicate these settings to each introduction point. + +#### Mitigation using proof of work {#hs-intro-pow} + +A short non-interactive computational puzzle can be solved with each connection attempt. Requests provided by the client will be entered into a queue prioritized by their puzzle solution's effort score. Requests are processed by the service at a limited rate, which can be adjusted to a value within the server's capabilities. + +Based on the queue behavior, servers will continuously provide an updated effort suggestion. +Queue backlogs cause the effort to rise, and an idle server will cause the effort to decay. +If the queue is never overfull the effort decays to zero, asking clients not to include a proof-of-work solution at all. + +We may support multiple cryptographic algorithms for this puzzle in the future, but currently we support one type. It's called `v1` in our protocol, and it's based on the Equi-X algorithm developed for this purpose. See `327-pow-over-intro.txt` for more information. + +This defense is configured by an operator using the `HiddenServicePoW` configuration options. Additionally, it requires both the client and the onion service to be compiled with the `pow` module (`--enable-gpl` mode) available. Current versions of the Tor Browser do include `pow` support. diff --git a/spec/tor-spec/resource-exhaustion.md b/spec/tor-spec/resource-exhaustion.md deleted file mode 100644 index 4dddf9f..0000000 --- a/spec/tor-spec/resource-exhaustion.md +++ /dev/null @@ -1,31 +0,0 @@ - - -# Handling resource exhaustion - - - -## Memory exhaustion - -(See also ["Denial-of-service prevention mechanisms in Tor"](../dos-spec.md).) - -If RAM becomes low, an OR should begin destroying circuits until -more memory is free again. We recommend the following algorithm: - -- Set a threshold amount of RAM to recover at 10% of the total RAM. - -- Sort the circuits by their 'staleness', defined as the age of the - oldest data queued on the circuit. This data can be: - - * Bytes that are waiting to flush to or from a stream on that - circuit. - - * Bytes that are waiting to flush from a connection created with - BEGIN_DIR. - - * Cells that are waiting to flush or be processed. - -- While we have not yet recovered enough RAM: - - * Free all memory held by the most stale circuit, and send DESTROY - cells in both directions on that circuit. Count the amount of - memory we recovered towards the total. -- cgit v1.2.3-54-g00ecf From cc698175f987165b4d21cb1ffd948d5b67d7ca41 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:47:34 -0800 Subject: Mark proposal 327 as closed I'm about to merge it in and this is the first step. --- proposals/327-pow-over-intro.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/327-pow-over-intro.txt b/proposals/327-pow-over-intro.txt index 3abffc4..d728781 100644 --- a/proposals/327-pow-over-intro.txt +++ b/proposals/327-pow-over-intro.txt @@ -3,7 +3,7 @@ Filename: 327-pow-over-intro.txt Title: A First Take at PoW Over Introduction Circuits Author: George Kadianakis, Mike Perry, David Goulet, tevador Created: 2 April 2020 -Status: Finished +Status: Closed 0. Abstract -- cgit v1.2.3-54-g00ecf From 49ecdc696262876c3113c48d86c659ce64697b0e Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:49:26 -0800 Subject: Update proposal index for 327 marked closed --- proposals/000-index.txt | 4 ++-- proposals/BY_INDEX.md | 2 +- proposals/BY_STATUS.md | 2 +- proposals/SUMMARY.md | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/proposals/000-index.txt b/proposals/000-index.txt index 0329640..a71b35d 100644 --- a/proposals/000-index.txt +++ b/proposals/000-index.txt @@ -248,7 +248,7 @@ Proposals by number: 324 RTT-based Congestion Control for Tor [FINISHED] 325 Packed relay cells: saving space on small commands [OBSOLETE] 326 The "tor-relay" Well-Known Resource Identifier [OPEN] -327 A First Take at PoW Over Introduction Circuits [FINISHED] +327 A First Take at PoW Over Introduction Circuits [CLOSED] 328 Make Relays Report When They Are Overloaded [CLOSED] 329 Overcoming Tor's Bottlenecks with Traffic Splitting [FINISHED] 330 Modernizing authority contact entries [OPEN] @@ -326,7 +326,6 @@ Proposals by status: 260 Rendezvous Single Onion Services [in 0.2.9.3-alpha] 291 The move to two guard nodes 324 RTT-based Congestion Control for Tor - 327 A First Take at PoW Over Introduction Circuits 329 Overcoming Tor's Bottlenecks with Traffic Splitting CLOSED: 101 Voting on the Tor Directory System [in 0.2.0.x] @@ -431,6 +430,7 @@ Proposals by status: 314 Allow Markdown for proposal format 315 Updating the list of fields required in directory documents [in 0.4.5.1-alpha] 318 Limit protover values to 0-63 [in 0.4.5.1-alpha] + 327 A First Take at PoW Over Introduction Circuits 328 Make Relays Report When They Are Overloaded 332 Ntor protocol with extra data, version 3 333 Vanguards lite [in 0.4.7.1-alpha] diff --git a/proposals/BY_INDEX.md b/proposals/BY_INDEX.md index b60a656..bd84f8f 100644 --- a/proposals/BY_INDEX.md +++ b/proposals/BY_INDEX.md @@ -244,7 +244,7 @@ Below are a list of proposals sorted by their proposal number. See * [`324-rtt-congestion-control.txt`](/proposals/324-rtt-congestion-control.txt): RTT-based Congestion Control for Tor [FINISHED] * [`325-packed-relay-cells.md`](/proposals/325-packed-relay-cells.md): Packed relay cells: saving space on small commands [OBSOLETE] * [`326-tor-relay-well-known-uri-rfc8615.md`](/proposals/326-tor-relay-well-known-uri-rfc8615.md): The "tor-relay" Well-Known Resource Identifier [OPEN] -* [`327-pow-over-intro.txt`](/proposals/327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits [FINISHED] +* [`327-pow-over-intro.txt`](/proposals/327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits [CLOSED] * [`328-relay-overload-report.md`](/proposals/328-relay-overload-report.md): Make Relays Report When They Are Overloaded [CLOSED] * [`329-traffic-splitting.txt`](/proposals/329-traffic-splitting.txt): Overcoming Tor's Bottlenecks with Traffic Splitting [FINISHED] * [`330-authority-contact.md`](/proposals/330-authority-contact.md): Modernizing authority contact entries [OPEN] diff --git a/proposals/BY_STATUS.md b/proposals/BY_STATUS.md index 865fac0..d402822 100644 --- a/proposals/BY_STATUS.md +++ b/proposals/BY_STATUS.md @@ -66,7 +66,6 @@ themselves still need to be merged into the specifications proper. * [`260-rend-single-onion.txt`](/proposals/260-rend-single-onion.txt): Rendezvous Single Onion Services * [`291-two-guard-nodes.txt`](/proposals/291-two-guard-nodes.txt): The move to two guard nodes * [`324-rtt-congestion-control.txt`](/proposals/324-rtt-congestion-control.txt): RTT-based Congestion Control for Tor -* [`327-pow-over-intro.txt`](/proposals/327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits * [`329-traffic-splitting.txt`](/proposals/329-traffic-splitting.txt): Overcoming Tor's Bottlenecks with Traffic Splitting @@ -238,6 +237,7 @@ necessary. * [`314-allow-markdown-proposals.md`](/proposals/314-allow-markdown-proposals.md): Allow Markdown for proposal format * [`315-update-dir-required-fields.txt`](/proposals/315-update-dir-required-fields.txt): Updating the list of fields required in directory documents * [`318-limit-protovers.md`](/proposals/318-limit-protovers.md): Limit protover values to 0-63 +* [`327-pow-over-intro.txt`](/proposals/327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits * [`328-relay-overload-report.md`](/proposals/328-relay-overload-report.md): Make Relays Report When They Are Overloaded * [`332-ntor-v3-with-extra-data.md`](/proposals/332-ntor-v3-with-extra-data.md): Ntor protocol with extra data, version 3 * [`333-vanguards-lite.md`](/proposals/333-vanguards-lite.md): Vanguards lite diff --git a/proposals/SUMMARY.md b/proposals/SUMMARY.md index 15b787b..f66d166 100644 --- a/proposals/SUMMARY.md +++ b/proposals/SUMMARY.md @@ -237,7 +237,7 @@ - [`324-rtt-congestion-control`](./324-rtt-congestion-control.txt): RTT-based Congestion Control for Tor (FINISHED) - [`325-packed-relay-cells`](./325-packed-relay-cells.md): Packed relay cells: saving space on small commands (OBSOLETE) - [`326-tor-relay-well-known-uri-rfc8615`](./326-tor-relay-well-known-uri-rfc8615.md): The "tor-relay" Well-Known Resource Identifier (OPEN) - - [`327-pow-over-intro`](./327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits (FINISHED) + - [`327-pow-over-intro`](./327-pow-over-intro.txt): A First Take at PoW Over Introduction Circuits (CLOSED) - [`328-relay-overload-report`](./328-relay-overload-report.md): Make Relays Report When They Are Overloaded (CLOSED) - [`329-traffic-splitting`](./329-traffic-splitting.txt): Overcoming Tor's Bottlenecks with Traffic Splitting (FINISHED) - [`330-authority-contact`](./330-authority-contact.md): Modernizing authority contact entries (OPEN) -- cgit v1.2.3-54-g00ecf From 93fed8bb455d1d09a4cf0fb6c79e3ed67c302f6e Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:51:36 -0800 Subject: Unmodified copy of final proposal 327 This will be broken up into sections by future commits. --- spec/hspow-spec/index.md | 1217 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1217 insertions(+) create mode 100644 spec/hspow-spec/index.md diff --git a/spec/hspow-spec/index.md b/spec/hspow-spec/index.md new file mode 100644 index 0000000..d728781 --- /dev/null +++ b/spec/hspow-spec/index.md @@ -0,0 +1,1217 @@ +``` +Filename: 327-pow-over-intro.txt +Title: A First Take at PoW Over Introduction Circuits +Author: George Kadianakis, Mike Perry, David Goulet, tevador +Created: 2 April 2020 +Status: Closed + +0. Abstract + + This proposal aims to thwart introduction flooding DoS attacks by introducing + a dynamic Proof-Of-Work protocol that occurs over introduction circuits. + +1. Motivation + + So far 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 [REF_TLS_1]. + + 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. + +1.1. 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 [REF_TLS]. + +1.2. Threat model [THREAT_MODEL] + +1.2.1. Attacker profiles [ATTACKER_MODEL] + + This proposal is written to thwart specific attackers. A simple PoW proposal + cannot 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 [FUTURE_DESIGNS]). + +1.2.2. User profiles [USER_MODEL] + + 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. + +1.2.3. 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. + +2. System Overview + +2.1. Tor protocol overview + + +----------------------------------+ + | 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 proposal takes place during the + introduction phase of the onion service protocol. + + 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 [DESC_POW] + 2) Client fetches descriptor and computes PoW [CLIENT_POW] + 3) Client completes PoW and sends results in INTRO1 cell [INTRO1_POW] + 4) Service verifies PoW and queues introduction based on PoW effort + [SERVICE_VERIFY] + 5) Requests are continuously drained from the queue, highest effort first, + subject to multiple constraints on speed [HANDLE_QUEUE] + +2.2. Proof-of-work overview + +2.2.1. Algorithm overview + + For our proof-of-work function we will use the Equi-X scheme by tevador + [REF_EQUIX]. 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. + + 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) Above the level of individual PoW handshakes, the client and service + form a closed-loop system that adjusts the effort of future handshakes. + + The Equi-X scheme 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. + + We tune Equi-X in section [EQUIX_TUNING]. + +2.2.2. Dynamic PoW + + DoS 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. Hence, instead of forcing clients to go below a + static target like in Bitcoin to be successful, 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. This is similar to how + proof-of-stake works but instead of staking coins, you stake work. + + The benefit here is that legitimate clients who really care about getting + access can spend a big amount of effort into their PoW computation, which + should guarantee access to the service given reasonable adversary models. See + [PARAM_TUNING] for more details about these guarantees and tradeoffs. + + As a way to improve reachability and UX, the service tries to estimate the + effort needed for clients to get access at any given time and places it in + the descriptor. See [EFFORT_ESTIMATION] for more details. + +2.2.3. PoW effort + + 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 estimation system, it's quite useful if we + instead have a linear scale. We use the first 32 bits of a hashed version + of the Equi-X solution as compared to the full 32-bit range. + + Conceptually we could define a function: + 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: + effort(00000001100010101101) = 11111111111111111111 + / 00000001100010101101 + or the same in decimal: + 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. + +3. Protocol specification + +3.1. Service encodes PoW parameters in descriptor [DESC_POW] + + This whole protocol starts with the service encoding the PoW parameters in + the 'encrypted' (inner) part of the v3 descriptor. As follows: + + "pow-params" SP type SP seed-b64 SP suggested-effort + SP expiration-time NL + + [At most once] + + type: The type of PoW system used. We call the one specified here "v1" + + seed-b64: A random seed that should be used as the input to the PoW + hash function. Should be 32 random bytes encoded in base64 + without trailing padding. + + suggested-effort: An unsigned integer specifying an effort value that + clients should aim for when contacting the service. Can be + zero to mean that PoW is available but not currently + suggested for a first connection attempt. See + [EFFORT_ESTIMATION] for more details here. + + expiration-time: A timestamp in "YYYY-MM-DDTHH:MM:SS" format (iso time + with no space) after which the above seed expires and + is no longer valid as the input for PoW. It's needed + so that our replay cache does not grow infinitely. It + should be set to RAND_TIME(now+7200, 900) seconds. + + 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 + [INTRO1_POW] for more info. + + By RAND_TIME(ts, interval) we mean a time between ts-interval and ts, chosen + uniformly at random. + +3.2. Client fetches descriptor and computes PoW [CLIENT_POW] + + 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 has not expired and if it has, it needs to + fetch a new descriptor. + + The client should then extract the field to configure its + PoW 'target' (see [REF_TARGET]). The client SHOULD NOT accept 'target' values + that will cause unacceptably long PoW computation. + + The client uses a "personalization string" P equal to the following + nul-terminated ASCII string: "Tor hs intro v1\0". + + The client looks up `ID`, the current 32-byte blinded public ID + (KP_hs_blind_id) for the onion service. + + To complete the PoW the client follows the following logic: + + a) Client selects a target effort E, based on and past + connection attempt history. + b) Client generates a secure random 16-byte nonce N, as the starting + point for the solution search. + c) Client derives seed C by decoding 'seed-b64'. + d) Client calculates S = equix_solve(P || ID || C || N || E) + e) Client calculates R = ntohl(blake2b_32(P || ID || C || N || E || S)) + f) Client checks if R * E <= UINT32_MAX. + f1) If yes, success! The client can submit N, E, the first 4 bytes of + C, and S. + f2) If no, fail! The client interprets N as a 16-byte little-endian + integer, increments it by 1 and goes back to step d). + + 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 S as the solution + of the Equix-X puzzle with N as the nonce, C as the seed. How quickly this + happens depends solely on 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. + +3.3. Client sends PoW in INTRO1 cell [INTRO1_POW] + + Now that the client has an answer to the puzzle it's time to encode it into + an INTRODUCE1 cell. To do so the client adds an extension to the encrypted + portion of the INTRODUCE1 cell by using the EXTENSIONS field (see + [PROCESS_INTRO2] section in rend-spec-v3.txt). The encrypted portion of the + INTRODUCE1 cell only gets read by the onion service and is ignored by the + introduction point. + + We propose a new EXT_FIELD_TYPE value: + + [02] -- PROOF_OF_WORK + + The EXT_FIELD content format is: + + POW_VERSION [1 byte] + POW_NONCE [16 bytes] + POW_EFFORT [4 bytes] + POW_SEED [4 bytes] + POW_SOLUTION [16 bytes] + + where: + + POW_VERSION is 1 for the protocol specified in this proposal + POW_NONCE is the nonce 'N' from the section above + POW_EFFORT is the 32-bit integer effort value, in network byte order + POW_SEED is the first 4 bytes of the seed used + + This will increase the INTRODUCE1 payload size by 43 bytes since the + extension type and length is 2 extra bytes, the N_EXTENSIONS field is always + present and currently set to 0 and the EXT_FIELD is 41 bytes. According to + ticket #33650, INTRODUCE1 cells currently have more than 200 bytes + available. + +3.4. 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 cell without any embedded proof-of-work, the service SHOULD + consider this cell as a zero-effort introduction for the purposes of the + priority queue (see section [INTRO_QUEUE]). + +3.4.1. PoW verification [POW_VERIFY] + + To verify the client's proof-of-work the service MUST do the following steps: + + a) Find a valid seed C that starts with POW_SEED. Fail if no such seed + exists. + b) Fail if N = POW_NONCE is present in the replay cache + (see [REPLAY_PROTECTION]) + c) Calculate R = ntohl(blake2b_32(P || ID || C || N || E || S)) + d) Fail if R * E > UINT32_MAX + e) Fail if equix_verify(P || ID || C || N || E, S) != EQUIX_OK + f) Put the request in the queue with a priority of E + + If any of these steps fail the service MUST ignore this introduction request + and abort the protocol. + + In this proposal 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 as detailed in section [INTRO_QUEUE]. + +3.4.1.1. 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 simple 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 as our replay cache + mechanism. The probabilistic nature of Bloom filters means that sometimes we + will flag some connections as replays even if they are not; with this false + positive probability increasing as the number of entries increase. However, + with the right parameter tuning this probability should be negligible and + well handled by clients. + + {TODO: Design and specify a suitable bloom filter for this purpose.} + +3.4.2. The Introduction Queue [INTRO_QUEUE] + +3.4.2.1. Adding introductions to the introduction queue [ADD_QUEUE] + + When PoW is enabled and a verified introduction comes through, the service + instead of jumping straight into rendezvous, queues it and prioritizes it + based on how much effort was devoted by the client to PoW. This means that + introduction requests with high effort should be prioritized over those with + low effort. + + To do so, the service maintains an "introduction priority queue" data + structure. Each element in that priority queue is an introduction request, + and its priority is the effort put into its PoW: + + When a verified introduction comes through, the service uses its included + effort commitment value to place each request into the right position of the + priority_queue: The bigger the effort, the more priority it gets in the + queue. If two elements have the same effort, the older one has priority over + the newer one. + +3.4.2.2. Handling introductions from the introduction queue [HANDLE_QUEUE] + + The service should handle introductions 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 a description of how we + expect such a system to work in Tor, see [TOR_SCHEDULER] section. + +3.4.3. PoW effort estimation [EFFORT_ESTIMATION] + +3.4.3.1. High-level description of the effort estimation process + + The service starts with a default suggested-effort value of 0, which keeps + the PoW defenses dormant until we notice signs of overload. + + The overall process of determining effort can be thought of as a set of + multiple coupled feedback loops. Clients perform their own effort + adjustments via [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 [CLIENT_TIMEOUT], + later clients will benefit from the service detecting this increased queued + effort and offering a larger suggested_effort. + + Effort increases and decreases both have an intrinsic 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. + +3.4.3.2. Service-side effort estimation + + Services keep an internal effort estimation which updates on a regular + periodic timer in response to measurements made on the queueing behavior + in the previous period. These internal effort changes can optionally trigger + client-visible suggested_effort changes when the difference is great enough + to warrant republishing to the HSDir. + + This evaluation and update period is referred to as HS_UPDATE_PERIOD. + The service side effort estimation 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?} + +3.4.3.3. Per-period service state + + 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. + +3.4.3.4. Service AIMD conditions + + 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 the 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. The service still adds requests with lower effort than + suggested-effort to the priority queue in [ADD_QUEUE]. + +3.4.3.5. Updating descriptor with new suggested effort + + The service descriptors may be updated for multiple reasons including + introduction point rotation common to all v3 onion services, the scheduled + seed rotations described in [DESC_POW], and updates to the effort suggestion. + Even though the internal effort estimate 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. + +4. Client behavior [CLIENT_BEHAVIOR] + + 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 INTRO_ACK cell 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. Existing mechanisms + will discard an introduction point that's required too many retries. + +4.1. Clients handling timeouts [CLIENT_TIMEOUT] + + Alice can fail to reach the onion service if her introduction request gets + trimmed off the priority queue in [HANDLE_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 new effort to be at least + (CLIENT_MIN_RETRY_POW_EFFORT = 8) and no greater than + (CLIENT_MAX_POW_EFFORT = 10000) + + {TODO: These hardcoded limits should be replaced by timed limits and/or + an unlimited solver with robust cancellation. This is issue tor#40787} + +5. Attacker strategies [ATTACK_META] + + Now that we defined our protocol we need to start tweaking the various + knobs. But before we can do that, we first need to understand a few + high-level attacker strategies to see what we are fighting against. + +5.1.1. Overwhelm PoW verification (aka "Overwhelm top half") [ATTACK_TOP_HALF] + + A basic attack here is the adversary spamming with bogus INTRO cells 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 + [POW_VERIFY] section. + + That's why we need the PoW algorithm to have a cheap verification time so + that this attack is not possible: we tune this PoW parameter in section + [POW_TUNING_VERIFICATION]. + +5.1.2. Overwhelm rendezvous capacity (aka "Overwhelm bottom half") + [ATTACK_BOTTOM_HALF] + + Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure + in the [HANDLE_QUEUE] section. + + To do so, the attacker would have to send at least 20 high-effort + introduction cells every 100ms, where high-effort is a PoW which is above the + estimated level of "the motivated user" (see [USER_MODEL]). + + An easier attack for the adversary, is the same strategy but with + introduction cells that are all above the comfortable level of "the standard + user" (see [USER_MODEL]). This would block out all standard users and only + allow motivated users to pass. + +5.1.3. 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: + + 0.31*(1520+91) ~ 0.5 sec. + 5.5*91 ~ 0.5 sec. + + This attack only has half the bandwidth requirement of [ATTACK_TOP_HALF] and + half the compute requirement of [ATTACK_BOTTOM_HALF]. + + Alternatively, the attacker can adjust the ratio between invalid and + high-effort requests depending on their bandwidth and compute capabilities. + +5.1.4. Gaming the effort estimation logic [ATTACK_EFFORT] + + Another way to beat this system is for the attacker to game the effort + estimation logic (see [EFFORT_ESTIMATION]). 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 [ATTACK_BOTTOM_HALF] using medium effort PoW (see [REF_TEVADOR_1]) + +5.1.4. Precomputed PoW attack + + 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 [ATTACK_EFFORT] attack. + +6. Parameter tuning [POW_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 will then move towards analyzing the client starting difficulty setting + for our PoW system. That defines the expected time for clients to succeed in + our system, and the expected time for attackers to overwhelm our system. Same + as above we will do this in a way that's agnostic to the chosen PoW function. + + Currently, we have hardcoded the initial client starting difficulty at 8, + but this may be too low to ramp up quickly to various on and off attack + patterns. A higher initial difficulty may be needed for these, depending on + their severity. This section gives us an idea of how large such attacks can + be. + + Finally, using those two pieces we will tune our PoW function and pick the + right client starting difficulty setting. At the end of this section we will + know 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. + +6.1. PoW verification [POW_TUNING_VERIFICATION] + + Verifying a PoW token is the first thing that a service does when it receives + an INTRODUCE2 cell and it's detailed in section [POW_VERIFY]. This + verification happens during the "top half" part of the process. Every + millisecond spent verifying PoW adds overhead to the already existing "top + half" part of handling an introduction cell. Hence we should be careful to + add minimal overhead here so that we don't enable attacks like [ATTACK_TOP_HALF]. + + During our performance measurements in [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 cells 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 | Cells 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 cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + - For a PoW function with a 2ms verification time, an attacker needs to send + 442 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + - For a PoW function with a 10ms verification time, an attacker needs to send + 97 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + 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 INTRODUCE2 cells 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 cells + queued per second based on a single "top half" time seems like good enough to + get some initial intuition. That said, the values of "Cells queued per + second" from the table above, are likely much smaller than displayed above + because of all the auxiliary overheads.] + +6.2. 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 [ATTACK_BOTTOM_HALF] attack 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. + + Our system is dynamic but 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 we do need + to define a starting difficulty, to minimize retries by clients. + +6.2.1. Analysis based on adversary power + + 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. + + =============================================================== + | 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. + +6.2.2. Analysis based on Tor's performance [POW_DIFFICULTY_TOR] + + To go deeper here, we can use the performance measurements from + [TOR_MEASUREMENTS] to get a more specific intuition on the starting + difficulty. In particular, we learned that completely handling an + introduction cell takes 5.55 msecs in average. Using that value, we can + compute the following table, that describes the number of introduction cells + we can handle per second for different values of PoW verification: + + +---------------------+-----------------------+--------------+ + |PoW Verification Time| Total time to handle | Cells handled| + | | introduction cell | 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 cells per second to succeed in a + [ATTACK_BOTTOM_HALF] attack. + + - For a PoW function with a 10ms verification time, an attacker needs to send + 64 high-effort introduction cells per second to succeed in a + [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 [ATTACK_BOTTOM_HALF] attack. + + Of course, when it comes to this table, the same disclaimer as in section + [POW_TUNING_VERIFICATION] is valid. That is, the above table is just a + theoretical extrapolation and we expect the real values to be much lower + since they depend on auxiliary processing overheads, and on the network's + capacity. + + +7. Discussion + +7.1. 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. + +7.2. Future work [FUTURE_WORK] + +7.2.1. 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 from + [CLIENT_BEHAVIOR] 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. + +7.2.2. 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 cells. + 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 this proposal, and + hence we want to start easy before we get into more serious projects. + +7.3. Environment + + We love the environment! We are concerned of how PoW schemes can waste energy + by doing useless hash iterations. Here is a few reasons we still decided to + pursue a PoW approach here: + + "We are not making things worse" -- DoS attacks are already happening and + attackers are already burning energy to carry them out both on the + attacker side, on the service side and on the network side. We think that + asking legitimate clients to carry out PoW computations is not gonna + affect the equation too much, since an attacker right now can very + quickly cause the same damage that hundreds of legitimate clients do a + whole day. + + "We hope to make things better" -- The hope is that proposals 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 [CATCH22] for a similar argument. + +8. 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. + +Appendix A. Little-t tor introduction 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. + +A.1. The Main Loop [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 cell at a time. The mainloop is single threaded + and thus each cell is handled sequentially. + + Processing an INTRODUCE2 cell at the onion service means a series of + operations (in order): + + 1) Unpack cell from inbuf to local buffer. + + 2) Decrypt cell (AES operations). + + 3) Parse cell header and process it depending on its RELAY_COMMAND. + + 4) INTRODUCE2 cell handling which means building a rendezvous circuit: + i) Path selection + ii) Launch circuit to first hop. + + 5) Return to mainloop event which essentially means back to step (1). + + Tor will read at most 32 cells out of the inbuf per mainloop round. + +A.2. Requirements for PoW + + With this proposal, in order to prioritize cells by the amount of PoW work + it has done, cells can _not_ be processed sequentially as described above. + + Thus, we need a way to queue a certain number of cells, prioritize them and + then process some cell(s) from the top of the queue (that is, the cells that + have done the most PoW effort). + + We thus require a new cell processing flow that is _not_ compatible with + current tor design. The elements are: + + - Validate PoW and place cells in a priority queue of INTRODUCE2 cells (as + described in section [INTRO_QUEUE]). + + - Defer "bottom half" INTRO2 cell processing for after cells have been + queued into the priority queue. + +A.3. Proposed scheduler [TOR_SCHEDULER] + + The intuitive way to address the A.2 requirements would be to do this + simple and naive approach: + + 1) Mainloop: Empty inbuf INTRODUCE2 cells into priority queue + + 2) Process all cells in pqueue + + 3) Goto (1) + + However, we are worried that handling all those cells 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 cells. This + means that we might spend lots of time dealing with introductions that don't + deserve it. See [BOTTOM_HALF_SCHEDULER] for more details. + + We thus propose to split the INTRODUCE2 handling into two different steps: + "top half" and "bottom half" process, as also mentioned in [POW_VERIFY] + section above. + +A.3.1. Top half and bottom half scheduler + + The top half process is responsible for queuing introductions into the + priority queue as follows: + + a) Unpack cell from inbuf to local buffer. + + b) Decrypt cell (AES operations). + + c) Parse INTRODUCE2 cell header and validate PoW. + + d) Return to mainloop event which essentially means step (1). + + The top-half basically does all operations of section [MAIN_LOOP] except from (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: + + a) Pop INTRODUCE2 cell from priority queue. + + b) Parse and process INTRODUCE2 cell. + + c) End event and yield back to mainloop. + +A.3.2. Scheduling the bottom half process [BOTTOM_HALF_SCHEDULER] + + 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 cell into the priority queue. Then, as long as it has a + cell 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 cells to appear between cell 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 cells in the future from 1 to N where N <= 32. + +A.4 Performance measurements + + This section will detail the performance measurements we've done on tor.git + for handling an INTRODUCE2 cell and then a discussion on how much more CPU + time we can add (for PoW validation) before it badly degrades our + performance. + +A.4.1 Tor measurements [TOR_MEASUREMENTS] + + In this section we will derive measurement numbers for the "top half" and + "bottom half" parts of handling an introduction cell. + + These measurements have been done on tor.git at commit + 80031db32abebaf4d0a91c01db258fcdbd54a471. + + We've measured several set of actions of the INTRODUCE2 cell 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 cells. The mainloop event processed + 2.42 cells per invocation on average during our measurements. + + 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 cell 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] section: + + 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 cell where basic + validation is done. + + There is an average of 2.42 INTRODUCE2 cells per mainloop event and so we + divide that by the full mainloop event mean time to get the time for one + cell. From that we subtract the "bottom half" mean time to get how much + the "top half" takes: + + => 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 cells + a mainloop event processed is ~2.42 cells (7931 cells 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 cell. Then if we look deeper + we see that the "top half" of INTRODUCE2 cell 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. + +A.2. References + + [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_TLS]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt + https://tools.ietf.org/id/draft-nir-tls-puzzles-00.html + https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10 + [REF_TLS_1]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt + [REF_TEVADOR_1]: https://lists.torproject.org/pipermail/tor-dev/2020-May/014268.html + [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 +``` -- cgit v1.2.3-54-g00ecf From dbf045b6d38fa99f19041c926a988a7bc08f59e6 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Tue, 7 Nov 2023 18:59:58 -0800 Subject: Index text and links for the new hspow-spec --- spec/SUMMARY.md | 1 + spec/dos-spec/overview.md | 2 +- spec/hspow-spec/index.md | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/SUMMARY.md b/spec/SUMMARY.md index 9cd0933..562a371 100644 --- a/spec/SUMMARY.md +++ b/spec/SUMMARY.md @@ -128,6 +128,7 @@ - [Appendix G: Managing authorized client data \[CLIENT-AUTH-MGMT\]](./rend-spec/client-authorization.md) - [Appendix F: Two methods for managing revision counters.](./rend-spec/revision-counter-mgt.md) - [Appendix G: Text vectors](./rend-spec/text-vectors.md) +- [`Proof of Work for onion service introduction`](./hspow-spec/index.md) # Anticensorship tools and protocols diff --git a/spec/dos-spec/overview.md b/spec/dos-spec/overview.md index d715b51..e159014 100644 --- a/spec/dos-spec/overview.md +++ b/spec/dos-spec/overview.md @@ -73,6 +73,6 @@ Based on the queue behavior, servers will continuously provide an updated effort Queue backlogs cause the effort to rise, and an idle server will cause the effort to decay. If the queue is never overfull the effort decays to zero, asking clients not to include a proof-of-work solution at all. -We may support multiple cryptographic algorithms for this puzzle in the future, but currently we support one type. It's called `v1` in our protocol, and it's based on the Equi-X algorithm developed for this purpose. See `327-pow-over-intro.txt` for more information. +We may support multiple cryptographic algorithms for this puzzle in the future, but currently we support one type. It's called `v1` in our protocol, and it's based on the Equi-X algorithm developed for this purpose. See the document on [`Proof of Work for onion service introduction`](../hspow-spec/index.md). This defense is configured by an operator using the `HiddenServicePoW` configuration options. Additionally, it requires both the client and the onion service to be compiled with the `pow` module (`--enable-gpl` mode) available. Current versions of the Tor Browser do include `pow` support. diff --git a/spec/hspow-spec/index.md b/spec/hspow-spec/index.md index d728781..aea9c46 100644 --- a/spec/hspow-spec/index.md +++ b/spec/hspow-spec/index.md @@ -1,10 +1,10 @@ -``` -Filename: 327-pow-over-intro.txt -Title: A First Take at PoW Over Introduction Circuits -Author: George Kadianakis, Mike Perry, David Goulet, tevador -Created: 2 April 2020 -Status: Closed +# 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. +```text 0. Abstract This proposal aims to thwart introduction flooding DoS attacks by introducing -- cgit v1.2.3-54-g00ecf From 8489561ae79210fd7561c5a799bd28c6654ffbab Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 11:14:31 -0800 Subject: Split the hspow-spec into sections without making edits This establishes a new outline for the hspow-spec. Otherwise, it's just cut and paste without any content edits. This also does not yet fully disentangling the common and v1-specific pieces of the document. --- spec/SUMMARY.md | 5 + spec/hspow-spec/analysis-discussion.md | 591 ++++++++++++++++ spec/hspow-spec/common-protocol.md | 227 ++++++ spec/hspow-spec/index.md | 1212 -------------------------------- spec/hspow-spec/motivation.md | 106 +++ spec/hspow-spec/overview.md | 68 ++ spec/hspow-spec/v1-equix.md | 233 ++++++ 7 files changed, 1230 insertions(+), 1212 deletions(-) create mode 100644 spec/hspow-spec/analysis-discussion.md create mode 100644 spec/hspow-spec/common-protocol.md create mode 100644 spec/hspow-spec/motivation.md create mode 100644 spec/hspow-spec/overview.md create mode 100644 spec/hspow-spec/v1-equix.md diff --git a/spec/SUMMARY.md b/spec/SUMMARY.md index 562a371..b3b88a8 100644 --- a/spec/SUMMARY.md +++ b/spec/SUMMARY.md @@ -129,6 +129,11 @@ - [Appendix F: Two methods for managing revision counters.](./rend-spec/revision-counter-mgt.md) - [Appendix G: Text vectors](./rend-spec/text-vectors.md) - [`Proof of Work for onion service introduction`](./hspow-spec/index.md) + - [Motivation](./hspow-spec/motivation.md) + - [Overview](./hspow-spec/overview.md) + - [Common Protocol](./hspow-spec/common-protocol.md) + - [Version 1, Equi-X and Blake2b](./hspow-spec/v1-equix.md) + - [Appendix A: Analysis and Discussion](./hspow-spec/analysis-discussion.md) # Anticensorship tools and protocols diff --git a/spec/hspow-spec/analysis-discussion.md b/spec/hspow-spec/analysis-discussion.md new file mode 100644 index 0000000..2c9d43f --- /dev/null +++ b/spec/hspow-spec/analysis-discussion.md @@ -0,0 +1,591 @@ +```text + +5. Attacker strategies [ATTACK_META] + + Now that we defined our protocol we need to start tweaking the various + knobs. But before we can do that, we first need to understand a few + high-level attacker strategies to see what we are fighting against. + +5.1.1. Overwhelm PoW verification (aka "Overwhelm top half") [ATTACK_TOP_HALF] + + A basic attack here is the adversary spamming with bogus INTRO cells 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 + [POW_VERIFY] section. + + That's why we need the PoW algorithm to have a cheap verification time so + that this attack is not possible: we tune this PoW parameter in section + [POW_TUNING_VERIFICATION]. + +5.1.2. Overwhelm rendezvous capacity (aka "Overwhelm bottom half") + [ATTACK_BOTTOM_HALF] + + Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure + in the [HANDLE_QUEUE] section. + + To do so, the attacker would have to send at least 20 high-effort + introduction cells every 100ms, where high-effort is a PoW which is above the + estimated level of "the motivated user" (see [USER_MODEL]). + + An easier attack for the adversary, is the same strategy but with + introduction cells that are all above the comfortable level of "the standard + user" (see [USER_MODEL]). This would block out all standard users and only + allow motivated users to pass. + +5.1.3. 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: + + 0.31*(1520+91) ~ 0.5 sec. + 5.5*91 ~ 0.5 sec. + + This attack only has half the bandwidth requirement of [ATTACK_TOP_HALF] and + half the compute requirement of [ATTACK_BOTTOM_HALF]. + + Alternatively, the attacker can adjust the ratio between invalid and + high-effort requests depending on their bandwidth and compute capabilities. + +5.1.4. Gaming the effort estimation logic [ATTACK_EFFORT] + + Another way to beat this system is for the attacker to game the effort + estimation logic (see [EFFORT_ESTIMATION]). 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 [ATTACK_BOTTOM_HALF] using medium effort PoW (see [REF_TEVADOR_1]) + +5.1.4. Precomputed PoW attack + + 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 [ATTACK_EFFORT] attack. + +6. Parameter tuning [POW_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 will then move towards analyzing the client starting difficulty setting + for our PoW system. That defines the expected time for clients to succeed in + our system, and the expected time for attackers to overwhelm our system. Same + as above we will do this in a way that's agnostic to the chosen PoW function. + + Currently, we have hardcoded the initial client starting difficulty at 8, + but this may be too low to ramp up quickly to various on and off attack + patterns. A higher initial difficulty may be needed for these, depending on + their severity. This section gives us an idea of how large such attacks can + be. + + Finally, using those two pieces we will tune our PoW function and pick the + right client starting difficulty setting. At the end of this section we will + know 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. + +6.1. PoW verification [POW_TUNING_VERIFICATION] + + Verifying a PoW token is the first thing that a service does when it receives + an INTRODUCE2 cell and it's detailed in section [POW_VERIFY]. This + verification happens during the "top half" part of the process. Every + millisecond spent verifying PoW adds overhead to the already existing "top + half" part of handling an introduction cell. Hence we should be careful to + add minimal overhead here so that we don't enable attacks like [ATTACK_TOP_HALF]. + + During our performance measurements in [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 cells 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 | Cells 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 cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + - For a PoW function with a 2ms verification time, an attacker needs to send + 442 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + - For a PoW function with a 10ms verification time, an attacker needs to send + 97 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. + + 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 INTRODUCE2 cells 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 cells + queued per second based on a single "top half" time seems like good enough to + get some initial intuition. That said, the values of "Cells queued per + second" from the table above, are likely much smaller than displayed above + because of all the auxiliary overheads.] + +6.2. 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 [ATTACK_BOTTOM_HALF] attack 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. + + Our system is dynamic but 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 we do need + to define a starting difficulty, to minimize retries by clients. + +6.2.1. Analysis based on adversary power + + 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. + + =============================================================== + | 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. + +6.2.2. Analysis based on Tor's performance [POW_DIFFICULTY_TOR] + + To go deeper here, we can use the performance measurements from + [TOR_MEASUREMENTS] to get a more specific intuition on the starting + difficulty. In particular, we learned that completely handling an + introduction cell takes 5.55 msecs in average. Using that value, we can + compute the following table, that describes the number of introduction cells + we can handle per second for different values of PoW verification: + + +---------------------+-----------------------+--------------+ + |PoW Verification Time| Total time to handle | Cells handled| + | | introduction cell | 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 cells per second to succeed in a + [ATTACK_BOTTOM_HALF] attack. + + - For a PoW function with a 10ms verification time, an attacker needs to send + 64 high-effort introduction cells per second to succeed in a + [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 [ATTACK_BOTTOM_HALF] attack. + + Of course, when it comes to this table, the same disclaimer as in section + [POW_TUNING_VERIFICATION] is valid. That is, the above table is just a + theoretical extrapolation and we expect the real values to be much lower + since they depend on auxiliary processing overheads, and on the network's + capacity. + + +7. Discussion + +7.1. 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. + +7.2. Future work [FUTURE_WORK] + +7.2.1. 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 from + [CLIENT_BEHAVIOR] 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. + +7.2.2. 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 cells. + 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 this proposal, and + hence we want to start easy before we get into more serious projects. + +7.3. Environment + + We love the environment! We are concerned of how PoW schemes can waste energy + by doing useless hash iterations. Here is a few reasons we still decided to + pursue a PoW approach here: + + "We are not making things worse" -- DoS attacks are already happening and + attackers are already burning energy to carry them out both on the + attacker side, on the service side and on the network side. We think that + asking legitimate clients to carry out PoW computations is not gonna + affect the equation too much, since an attacker right now can very + quickly cause the same damage that hundreds of legitimate clients do a + whole day. + + "We hope to make things better" -- The hope is that proposals 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 [CATCH22] for a similar argument. + +8. 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. + +Appendix A. Little-t tor introduction 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. + +A.1. The Main Loop [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 cell at a time. The mainloop is single threaded + and thus each cell is handled sequentially. + + Processing an INTRODUCE2 cell at the onion service means a series of + operations (in order): + + 1) Unpack cell from inbuf to local buffer. + + 2) Decrypt cell (AES operations). + + 3) Parse cell header and process it depending on its RELAY_COMMAND. + + 4) INTRODUCE2 cell handling which means building a rendezvous circuit: + i) Path selection + ii) Launch circuit to first hop. + + 5) Return to mainloop event which essentially means back to step (1). + + Tor will read at most 32 cells out of the inbuf per mainloop round. + +A.2. Requirements for PoW + + With this proposal, in order to prioritize cells by the amount of PoW work + it has done, cells can _not_ be processed sequentially as described above. + + Thus, we need a way to queue a certain number of cells, prioritize them and + then process some cell(s) from the top of the queue (that is, the cells that + have done the most PoW effort). + + We thus require a new cell processing flow that is _not_ compatible with + current tor design. The elements are: + + - Validate PoW and place cells in a priority queue of INTRODUCE2 cells (as + described in section [INTRO_QUEUE]). + + - Defer "bottom half" INTRO2 cell processing for after cells have been + queued into the priority queue. + +A.3. Proposed scheduler [TOR_SCHEDULER] + + The intuitive way to address the A.2 requirements would be to do this + simple and naive approach: + + 1) Mainloop: Empty inbuf INTRODUCE2 cells into priority queue + + 2) Process all cells in pqueue + + 3) Goto (1) + + However, we are worried that handling all those cells 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 cells. This + means that we might spend lots of time dealing with introductions that don't + deserve it. See [BOTTOM_HALF_SCHEDULER] for more details. + + We thus propose to split the INTRODUCE2 handling into two different steps: + "top half" and "bottom half" process, as also mentioned in [POW_VERIFY] + section above. + +A.3.1. Top half and bottom half scheduler + + The top half process is responsible for queuing introductions into the + priority queue as follows: + + a) Unpack cell from inbuf to local buffer. + + b) Decrypt cell (AES operations). + + c) Parse INTRODUCE2 cell header and validate PoW. + + d) Return to mainloop event which essentially means step (1). + + The top-half basically does all operations of section [MAIN_LOOP] except from (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: + + a) Pop INTRODUCE2 cell from priority queue. + + b) Parse and process INTRODUCE2 cell. + + c) End event and yield back to mainloop. + +A.3.2. Scheduling the bottom half process [BOTTOM_HALF_SCHEDULER] + + 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 cell into the priority queue. Then, as long as it has a + cell 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 cells to appear between cell 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 cells in the future from 1 to N where N <= 32. + +A.4 Performance measurements + + This section will detail the performance measurements we've done on tor.git + for handling an INTRODUCE2 cell and then a discussion on how much more CPU + time we can add (for PoW validation) before it badly degrades our + performance. + +A.4.1 Tor measurements [TOR_MEASUREMENTS] + + In this section we will derive measurement numbers for the "top half" and + "bottom half" parts of handling an introduction cell. + + These measurements have been done on tor.git at commit + 80031db32abebaf4d0a91c01db258fcdbd54a471. + + We've measured several set of actions of the INTRODUCE2 cell 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 cells. The mainloop event processed + 2.42 cells per invocation on average during our measurements. + + 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 cell 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] section: + + 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 cell where basic + validation is done. + + There is an average of 2.42 INTRODUCE2 cells per mainloop event and so we + divide that by the full mainloop event mean time to get the time for one + cell. From that we subtract the "bottom half" mean time to get how much + the "top half" takes: + + => 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 cells + a mainloop event processed is ~2.42 cells (7931 cells 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 cell. Then if we look deeper + we see that the "top half" of INTRODUCE2 cell 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. + +A.2. References + + [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_TLS]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt + https://tools.ietf.org/id/draft-nir-tls-puzzles-00.html + https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10 + [REF_TLS_1]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt + [REF_TEVADOR_1]: https://lists.torproject.org/pipermail/tor-dev/2020-May/014268.html + [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..0aa9df5 --- /dev/null +++ b/spec/hspow-spec/common-protocol.md @@ -0,0 +1,227 @@ +```text + +3. Protocol specification + +3.4.1.1. 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 simple 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 as our replay cache + mechanism. The probabilistic nature of Bloom filters means that sometimes we + will flag some connections as replays even if they are not; with this false + positive probability increasing as the number of entries increase. However, + with the right parameter tuning this probability should be negligible and + well handled by clients. + + {TODO: Design and specify a suitable bloom filter for this purpose.} + +3.4.2. The Introduction Queue [INTRO_QUEUE] + +3.4.2.1. Adding introductions to the introduction queue [ADD_QUEUE] + + When PoW is enabled and a verified introduction comes through, the service + instead of jumping straight into rendezvous, queues it and prioritizes it + based on how much effort was devoted by the client to PoW. This means that + introduction requests with high effort should be prioritized over those with + low effort. + + To do so, the service maintains an "introduction priority queue" data + structure. Each element in that priority queue is an introduction request, + and its priority is the effort put into its PoW: + + When a verified introduction comes through, the service uses its included + effort commitment value to place each request into the right position of the + priority_queue: The bigger the effort, the more priority it gets in the + queue. If two elements have the same effort, the older one has priority over + the newer one. + +3.4.2.2. Handling introductions from the introduction queue [HANDLE_QUEUE] + + The service should handle introductions 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 a description of how we + expect such a system to work in Tor, see [TOR_SCHEDULER] section. + +3.4.3. PoW effort estimation [EFFORT_ESTIMATION] + +3.4.3.1. High-level description of the effort estimation process + + The service starts with a default suggested-effort value of 0, which keeps + the PoW defenses dormant until we notice signs of overload. + + The overall process of determining effort can be thought of as a set of + multiple coupled feedback loops. Clients perform their own effort + adjustments via [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 [CLIENT_TIMEOUT], + later clients will benefit from the service detecting this increased queued + effort and offering a larger suggested_effort. + + Effort increases and decreases both have an intrinsic 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. + +3.4.3.2. Service-side effort estimation + + Services keep an internal effort estimation which updates on a regular + periodic timer in response to measurements made on the queueing behavior + in the previous period. These internal effort changes can optionally trigger + client-visible suggested_effort changes when the difference is great enough + to warrant republishing to the HSDir. + + This evaluation and update period is referred to as HS_UPDATE_PERIOD. + The service side effort estimation 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?} + +3.4.3.3. Per-period service state + + 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. + +3.4.3.4. Service AIMD conditions + + 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 the 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. The service still adds requests with lower effort than + suggested-effort to the priority queue in [ADD_QUEUE]. + +3.4.3.5. Updating descriptor with new suggested effort + + The service descriptors may be updated for multiple reasons including + introduction point rotation common to all v3 onion services, the scheduled + seed rotations described in [DESC_POW], and updates to the effort suggestion. + Even though the internal effort estimate 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. + +4. Client behavior [CLIENT_BEHAVIOR] + + 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 INTRO_ACK cell 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. Existing mechanisms + will discard an introduction point that's required too many retries. + +4.1. Clients handling timeouts [CLIENT_TIMEOUT] + + Alice can fail to reach the onion service if her introduction request gets + trimmed off the priority queue in [HANDLE_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 new effort to be at least + (CLIENT_MIN_RETRY_POW_EFFORT = 8) and no greater than + (CLIENT_MAX_POW_EFFORT = 10000) + + {TODO: These hardcoded limits should be replaced by timed limits and/or + an unlimited solver with robust cancellation. This is issue tor#40787} + +``` \ No newline at end of file diff --git a/spec/hspow-spec/index.md b/spec/hspow-spec/index.md index aea9c46..14db248 100644 --- a/spec/hspow-spec/index.md +++ b/spec/hspow-spec/index.md @@ -3,1215 +3,3 @@ 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. - -```text -0. Abstract - - This proposal aims to thwart introduction flooding DoS attacks by introducing - a dynamic Proof-Of-Work protocol that occurs over introduction circuits. - -1. Motivation - - So far 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 [REF_TLS_1]. - - 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. - -1.1. 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 [REF_TLS]. - -1.2. Threat model [THREAT_MODEL] - -1.2.1. Attacker profiles [ATTACKER_MODEL] - - This proposal is written to thwart specific attackers. A simple PoW proposal - cannot 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 [FUTURE_DESIGNS]). - -1.2.2. User profiles [USER_MODEL] - - 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. - -1.2.3. 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. - -2. System Overview - -2.1. Tor protocol overview - - +----------------------------------+ - | 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 proposal takes place during the - introduction phase of the onion service protocol. - - 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 [DESC_POW] - 2) Client fetches descriptor and computes PoW [CLIENT_POW] - 3) Client completes PoW and sends results in INTRO1 cell [INTRO1_POW] - 4) Service verifies PoW and queues introduction based on PoW effort - [SERVICE_VERIFY] - 5) Requests are continuously drained from the queue, highest effort first, - subject to multiple constraints on speed [HANDLE_QUEUE] - -2.2. Proof-of-work overview - -2.2.1. Algorithm overview - - For our proof-of-work function we will use the Equi-X scheme by tevador - [REF_EQUIX]. 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. - - 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) Above the level of individual PoW handshakes, the client and service - form a closed-loop system that adjusts the effort of future handshakes. - - The Equi-X scheme 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. - - We tune Equi-X in section [EQUIX_TUNING]. - -2.2.2. Dynamic PoW - - DoS 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. Hence, instead of forcing clients to go below a - static target like in Bitcoin to be successful, 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. This is similar to how - proof-of-stake works but instead of staking coins, you stake work. - - The benefit here is that legitimate clients who really care about getting - access can spend a big amount of effort into their PoW computation, which - should guarantee access to the service given reasonable adversary models. See - [PARAM_TUNING] for more details about these guarantees and tradeoffs. - - As a way to improve reachability and UX, the service tries to estimate the - effort needed for clients to get access at any given time and places it in - the descriptor. See [EFFORT_ESTIMATION] for more details. - -2.2.3. PoW effort - - 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 estimation system, it's quite useful if we - instead have a linear scale. We use the first 32 bits of a hashed version - of the Equi-X solution as compared to the full 32-bit range. - - Conceptually we could define a function: - 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: - effort(00000001100010101101) = 11111111111111111111 - / 00000001100010101101 - or the same in decimal: - 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. - -3. Protocol specification - -3.1. Service encodes PoW parameters in descriptor [DESC_POW] - - This whole protocol starts with the service encoding the PoW parameters in - the 'encrypted' (inner) part of the v3 descriptor. As follows: - - "pow-params" SP type SP seed-b64 SP suggested-effort - SP expiration-time NL - - [At most once] - - type: The type of PoW system used. We call the one specified here "v1" - - seed-b64: A random seed that should be used as the input to the PoW - hash function. Should be 32 random bytes encoded in base64 - without trailing padding. - - suggested-effort: An unsigned integer specifying an effort value that - clients should aim for when contacting the service. Can be - zero to mean that PoW is available but not currently - suggested for a first connection attempt. See - [EFFORT_ESTIMATION] for more details here. - - expiration-time: A timestamp in "YYYY-MM-DDTHH:MM:SS" format (iso time - with no space) after which the above seed expires and - is no longer valid as the input for PoW. It's needed - so that our replay cache does not grow infinitely. It - should be set to RAND_TIME(now+7200, 900) seconds. - - 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 - [INTRO1_POW] for more info. - - By RAND_TIME(ts, interval) we mean a time between ts-interval and ts, chosen - uniformly at random. - -3.2. Client fetches descriptor and computes PoW [CLIENT_POW] - - 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 has not expired and if it has, it needs to - fetch a new descriptor. - - The client should then extract the field to configure its - PoW 'target' (see [REF_TARGET]). The client SHOULD NOT accept 'target' values - that will cause unacceptably long PoW computation. - - The client uses a "personalization string" P equal to the following - nul-terminated ASCII string: "Tor hs intro v1\0". - - The client looks up `ID`, the current 32-byte blinded public ID - (KP_hs_blind_id) for the onion service. - - To complete the PoW the client follows the following logic: - - a) Client selects a target effort E, based on and past - connection attempt history. - b) Client generates a secure random 16-byte nonce N, as the starting - point for the solution search. - c) Client derives seed C by decoding 'seed-b64'. - d) Client calculates S = equix_solve(P || ID || C || N || E) - e) Client calculates R = ntohl(blake2b_32(P || ID || C || N || E || S)) - f) Client checks if R * E <= UINT32_MAX. - f1) If yes, success! The client can submit N, E, the first 4 bytes of - C, and S. - f2) If no, fail! The client interprets N as a 16-byte little-endian - integer, increments it by 1 and goes back to step d). - - 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 S as the solution - of the Equix-X puzzle with N as the nonce, C as the seed. How quickly this - happens depends solely on 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. - -3.3. Client sends PoW in INTRO1 cell [INTRO1_POW] - - Now that the client has an answer to the puzzle it's time to encode it into - an INTRODUCE1 cell. To do so the client adds an extension to the encrypted - portion of the INTRODUCE1 cell by using the EXTENSIONS field (see - [PROCESS_INTRO2] section in rend-spec-v3.txt). The encrypted portion of the - INTRODUCE1 cell only gets read by the onion service and is ignored by the - introduction point. - - We propose a new EXT_FIELD_TYPE value: - - [02] -- PROOF_OF_WORK - - The EXT_FIELD content format is: - - POW_VERSION [1 byte] - POW_NONCE [16 bytes] - POW_EFFORT [4 bytes] - POW_SEED [4 bytes] - POW_SOLUTION [16 bytes] - - where: - - POW_VERSION is 1 for the protocol specified in this proposal - POW_NONCE is the nonce 'N' from the section above - POW_EFFORT is the 32-bit integer effort value, in network byte order - POW_SEED is the first 4 bytes of the seed used - - This will increase the INTRODUCE1 payload size by 43 bytes since the - extension type and length is 2 extra bytes, the N_EXTENSIONS field is always - present and currently set to 0 and the EXT_FIELD is 41 bytes. According to - ticket #33650, INTRODUCE1 cells currently have more than 200 bytes - available. - -3.4. 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 cell without any embedded proof-of-work, the service SHOULD - consider this cell as a zero-effort introduction for the purposes of the - priority queue (see section [INTRO_QUEUE]). - -3.4.1. PoW verification [POW_VERIFY] - - To verify the client's proof-of-work the service MUST do the following steps: - - a) Find a valid seed C that starts with POW_SEED. Fail if no such seed - exists. - b) Fail if N = POW_NONCE is present in the replay cache - (see [REPLAY_PROTECTION]) - c) Calculate R = ntohl(blake2b_32(P || ID || C || N || E || S)) - d) Fail if R * E > UINT32_MAX - e) Fail if equix_verify(P || ID || C || N || E, S) != EQUIX_OK - f) Put the request in the queue with a priority of E - - If any of these steps fail the service MUST ignore this introduction request - and abort the protocol. - - In this proposal 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 as detailed in section [INTRO_QUEUE]. - -3.4.1.1. 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 simple 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 as our replay cache - mechanism. The probabilistic nature of Bloom filters means that sometimes we - will flag some connections as replays even if they are not; with this false - positive probability increasing as the number of entries increase. However, - with the right parameter tuning this probability should be negligible and - well handled by clients. - - {TODO: Design and specify a suitable bloom filter for this purpose.} - -3.4.2. The Introduction Queue [INTRO_QUEUE] - -3.4.2.1. Adding introductions to the introduction queue [ADD_QUEUE] - - When PoW is enabled and a verified introduction comes through, the service - instead of jumping straight into rendezvous, queues it and prioritizes it - based on how much effort was devoted by the client to PoW. This means that - introduction requests with high effort should be prioritized over those with - low effort. - - To do so, the service maintains an "introduction priority queue" data - structure. Each element in that priority queue is an introduction request, - and its priority is the effort put into its PoW: - - When a verified introduction comes through, the service uses its included - effort commitment value to place each request into the right position of the - priority_queue: The bigger the effort, the more priority it gets in the - queue. If two elements have the same effort, the older one has priority over - the newer one. - -3.4.2.2. Handling introductions from the introduction queue [HANDLE_QUEUE] - - The service should handle introductions 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 a description of how we - expect such a system to work in Tor, see [TOR_SCHEDULER] section. - -3.4.3. PoW effort estimation [EFFORT_ESTIMATION] - -3.4.3.1. High-level description of the effort estimation process - - The service starts with a default suggested-effort value of 0, which keeps - the PoW defenses dormant until we notice signs of overload. - - The overall process of determining effort can be thought of as a set of - multiple coupled feedback loops. Clients perform their own effort - adjustments via [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 [CLIENT_TIMEOUT], - later clients will benefit from the service detecting this increased queued - effort and offering a larger suggested_effort. - - Effort increases and decreases both have an intrinsic 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. - -3.4.3.2. Service-side effort estimation - - Services keep an internal effort estimation which updates on a regular - periodic timer in response to measurements made on the queueing behavior - in the previous period. These internal effort changes can optionally trigger - client-visible suggested_effort changes when the difference is great enough - to warrant republishing to the HSDir. - - This evaluation and update period is referred to as HS_UPDATE_PERIOD. - The service side effort estimation 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?} - -3.4.3.3. Per-period service state - - 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. - -3.4.3.4. Service AIMD conditions - - 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 the 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. The service still adds requests with lower effort than - suggested-effort to the priority queue in [ADD_QUEUE]. - -3.4.3.5. Updating descriptor with new suggested effort - - The service descriptors may be updated for multiple reasons including - introduction point rotation common to all v3 onion services, the scheduled - seed rotations described in [DESC_POW], and updates to the effort suggestion. - Even though the internal effort estimate 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. - -4. Client behavior [CLIENT_BEHAVIOR] - - 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 INTRO_ACK cell 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. Existing mechanisms - will discard an introduction point that's required too many retries. - -4.1. Clients handling timeouts [CLIENT_TIMEOUT] - - Alice can fail to reach the onion service if her introduction request gets - trimmed off the priority queue in [HANDLE_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 new effort to be at least - (CLIENT_MIN_RETRY_POW_EFFORT = 8) and no greater than - (CLIENT_MAX_POW_EFFORT = 10000) - - {TODO: These hardcoded limits should be replaced by timed limits and/or - an unlimited solver with robust cancellation. This is issue tor#40787} - -5. Attacker strategies [ATTACK_META] - - Now that we defined our protocol we need to start tweaking the various - knobs. But before we can do that, we first need to understand a few - high-level attacker strategies to see what we are fighting against. - -5.1.1. Overwhelm PoW verification (aka "Overwhelm top half") [ATTACK_TOP_HALF] - - A basic attack here is the adversary spamming with bogus INTRO cells 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 - [POW_VERIFY] section. - - That's why we need the PoW algorithm to have a cheap verification time so - that this attack is not possible: we tune this PoW parameter in section - [POW_TUNING_VERIFICATION]. - -5.1.2. Overwhelm rendezvous capacity (aka "Overwhelm bottom half") - [ATTACK_BOTTOM_HALF] - - Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure - in the [HANDLE_QUEUE] section. - - To do so, the attacker would have to send at least 20 high-effort - introduction cells every 100ms, where high-effort is a PoW which is above the - estimated level of "the motivated user" (see [USER_MODEL]). - - An easier attack for the adversary, is the same strategy but with - introduction cells that are all above the comfortable level of "the standard - user" (see [USER_MODEL]). This would block out all standard users and only - allow motivated users to pass. - -5.1.3. 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: - - 0.31*(1520+91) ~ 0.5 sec. - 5.5*91 ~ 0.5 sec. - - This attack only has half the bandwidth requirement of [ATTACK_TOP_HALF] and - half the compute requirement of [ATTACK_BOTTOM_HALF]. - - Alternatively, the attacker can adjust the ratio between invalid and - high-effort requests depending on their bandwidth and compute capabilities. - -5.1.4. Gaming the effort estimation logic [ATTACK_EFFORT] - - Another way to beat this system is for the attacker to game the effort - estimation logic (see [EFFORT_ESTIMATION]). 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 [ATTACK_BOTTOM_HALF] using medium effort PoW (see [REF_TEVADOR_1]) - -5.1.4. Precomputed PoW attack - - 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 [ATTACK_EFFORT] attack. - -6. Parameter tuning [POW_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 will then move towards analyzing the client starting difficulty setting - for our PoW system. That defines the expected time for clients to succeed in - our system, and the expected time for attackers to overwhelm our system. Same - as above we will do this in a way that's agnostic to the chosen PoW function. - - Currently, we have hardcoded the initial client starting difficulty at 8, - but this may be too low to ramp up quickly to various on and off attack - patterns. A higher initial difficulty may be needed for these, depending on - their severity. This section gives us an idea of how large such attacks can - be. - - Finally, using those two pieces we will tune our PoW function and pick the - right client starting difficulty setting. At the end of this section we will - know 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. - -6.1. PoW verification [POW_TUNING_VERIFICATION] - - Verifying a PoW token is the first thing that a service does when it receives - an INTRODUCE2 cell and it's detailed in section [POW_VERIFY]. This - verification happens during the "top half" part of the process. Every - millisecond spent verifying PoW adds overhead to the already existing "top - half" part of handling an introduction cell. Hence we should be careful to - add minimal overhead here so that we don't enable attacks like [ATTACK_TOP_HALF]. - - During our performance measurements in [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 cells 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 | Cells 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 cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - - For a PoW function with a 2ms verification time, an attacker needs to send - 442 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - - For a PoW function with a 10ms verification time, an attacker needs to send - 97 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - 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 INTRODUCE2 cells 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 cells - queued per second based on a single "top half" time seems like good enough to - get some initial intuition. That said, the values of "Cells queued per - second" from the table above, are likely much smaller than displayed above - because of all the auxiliary overheads.] - -6.2. 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 [ATTACK_BOTTOM_HALF] attack 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. - - Our system is dynamic but 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 we do need - to define a starting difficulty, to minimize retries by clients. - -6.2.1. Analysis based on adversary power - - 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. - - =============================================================== - | 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. - -6.2.2. Analysis based on Tor's performance [POW_DIFFICULTY_TOR] - - To go deeper here, we can use the performance measurements from - [TOR_MEASUREMENTS] to get a more specific intuition on the starting - difficulty. In particular, we learned that completely handling an - introduction cell takes 5.55 msecs in average. Using that value, we can - compute the following table, that describes the number of introduction cells - we can handle per second for different values of PoW verification: - - +---------------------+-----------------------+--------------+ - |PoW Verification Time| Total time to handle | Cells handled| - | | introduction cell | 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 cells per second to succeed in a - [ATTACK_BOTTOM_HALF] attack. - - - For a PoW function with a 10ms verification time, an attacker needs to send - 64 high-effort introduction cells per second to succeed in a - [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 [ATTACK_BOTTOM_HALF] attack. - - Of course, when it comes to this table, the same disclaimer as in section - [POW_TUNING_VERIFICATION] is valid. That is, the above table is just a - theoretical extrapolation and we expect the real values to be much lower - since they depend on auxiliary processing overheads, and on the network's - capacity. - - -7. Discussion - -7.1. 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. - -7.2. Future work [FUTURE_WORK] - -7.2.1. 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 from - [CLIENT_BEHAVIOR] 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. - -7.2.2. 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 cells. - 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 this proposal, and - hence we want to start easy before we get into more serious projects. - -7.3. Environment - - We love the environment! We are concerned of how PoW schemes can waste energy - by doing useless hash iterations. Here is a few reasons we still decided to - pursue a PoW approach here: - - "We are not making things worse" -- DoS attacks are already happening and - attackers are already burning energy to carry them out both on the - attacker side, on the service side and on the network side. We think that - asking legitimate clients to carry out PoW computations is not gonna - affect the equation too much, since an attacker right now can very - quickly cause the same damage that hundreds of legitimate clients do a - whole day. - - "We hope to make things better" -- The hope is that proposals 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 [CATCH22] for a similar argument. - -8. 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. - -Appendix A. Little-t tor introduction 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. - -A.1. The Main Loop [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 cell at a time. The mainloop is single threaded - and thus each cell is handled sequentially. - - Processing an INTRODUCE2 cell at the onion service means a series of - operations (in order): - - 1) Unpack cell from inbuf to local buffer. - - 2) Decrypt cell (AES operations). - - 3) Parse cell header and process it depending on its RELAY_COMMAND. - - 4) INTRODUCE2 cell handling which means building a rendezvous circuit: - i) Path selection - ii) Launch circuit to first hop. - - 5) Return to mainloop event which essentially means back to step (1). - - Tor will read at most 32 cells out of the inbuf per mainloop round. - -A.2. Requirements for PoW - - With this proposal, in order to prioritize cells by the amount of PoW work - it has done, cells can _not_ be processed sequentially as described above. - - Thus, we need a way to queue a certain number of cells, prioritize them and - then process some cell(s) from the top of the queue (that is, the cells that - have done the most PoW effort). - - We thus require a new cell processing flow that is _not_ compatible with - current tor design. The elements are: - - - Validate PoW and place cells in a priority queue of INTRODUCE2 cells (as - described in section [INTRO_QUEUE]). - - - Defer "bottom half" INTRO2 cell processing for after cells have been - queued into the priority queue. - -A.3. Proposed scheduler [TOR_SCHEDULER] - - The intuitive way to address the A.2 requirements would be to do this - simple and naive approach: - - 1) Mainloop: Empty inbuf INTRODUCE2 cells into priority queue - - 2) Process all cells in pqueue - - 3) Goto (1) - - However, we are worried that handling all those cells 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 cells. This - means that we might spend lots of time dealing with introductions that don't - deserve it. See [BOTTOM_HALF_SCHEDULER] for more details. - - We thus propose to split the INTRODUCE2 handling into two different steps: - "top half" and "bottom half" process, as also mentioned in [POW_VERIFY] - section above. - -A.3.1. Top half and bottom half scheduler - - The top half process is responsible for queuing introductions into the - priority queue as follows: - - a) Unpack cell from inbuf to local buffer. - - b) Decrypt cell (AES operations). - - c) Parse INTRODUCE2 cell header and validate PoW. - - d) Return to mainloop event which essentially means step (1). - - The top-half basically does all operations of section [MAIN_LOOP] except from (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: - - a) Pop INTRODUCE2 cell from priority queue. - - b) Parse and process INTRODUCE2 cell. - - c) End event and yield back to mainloop. - -A.3.2. Scheduling the bottom half process [BOTTOM_HALF_SCHEDULER] - - 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 cell into the priority queue. Then, as long as it has a - cell 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 cells to appear between cell 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 cells in the future from 1 to N where N <= 32. - -A.4 Performance measurements - - This section will detail the performance measurements we've done on tor.git - for handling an INTRODUCE2 cell and then a discussion on how much more CPU - time we can add (for PoW validation) before it badly degrades our - performance. - -A.4.1 Tor measurements [TOR_MEASUREMENTS] - - In this section we will derive measurement numbers for the "top half" and - "bottom half" parts of handling an introduction cell. - - These measurements have been done on tor.git at commit - 80031db32abebaf4d0a91c01db258fcdbd54a471. - - We've measured several set of actions of the INTRODUCE2 cell 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 cells. The mainloop event processed - 2.42 cells per invocation on average during our measurements. - - 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 cell 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] section: - - 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 cell where basic - validation is done. - - There is an average of 2.42 INTRODUCE2 cells per mainloop event and so we - divide that by the full mainloop event mean time to get the time for one - cell. From that we subtract the "bottom half" mean time to get how much - the "top half" takes: - - => 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 cells - a mainloop event processed is ~2.42 cells (7931 cells 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 cell. Then if we look deeper - we see that the "top half" of INTRODUCE2 cell 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. - -A.2. References - - [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_TLS]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt - https://tools.ietf.org/id/draft-nir-tls-puzzles-00.html - https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10 - [REF_TLS_1]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt - [REF_TEVADOR_1]: https://lists.torproject.org/pipermail/tor-dev/2020-May/014268.html - [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/motivation.md b/spec/hspow-spec/motivation.md new file mode 100644 index 0000000..1c77f58 --- /dev/null +++ b/spec/hspow-spec/motivation.md @@ -0,0 +1,106 @@ +```text + +0. Abstract + + This proposal aims to thwart introduction flooding DoS attacks by introducing + a dynamic Proof-Of-Work protocol that occurs over introduction circuits. + +1. Motivation + + So far 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 [REF_TLS_1]. + + 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. + +1.1. 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 [REF_TLS]. + +1.2. Threat model [THREAT_MODEL] + +1.2.1. Attacker profiles [ATTACKER_MODEL] + + This proposal is written to thwart specific attackers. A simple PoW proposal + cannot 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 [FUTURE_DESIGNS]). + +1.2.2. User profiles [USER_MODEL] + + 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. + +1.2.3. 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. + +``` \ No newline at end of file diff --git a/spec/hspow-spec/overview.md b/spec/hspow-spec/overview.md new file mode 100644 index 0000000..cb4ea7e --- /dev/null +++ b/spec/hspow-spec/overview.md @@ -0,0 +1,68 @@ +```text + +2. System Overview + +2.1. Tor protocol overview + + +----------------------------------+ + | 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 proposal takes place during the + introduction phase of the onion service protocol. + + 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 [DESC_POW] + 2) Client fetches descriptor and computes PoW [CLIENT_POW] + 3) Client completes PoW and sends results in INTRO1 cell [INTRO1_POW] + 4) Service verifies PoW and queues introduction based on PoW effort + [SERVICE_VERIFY] + 5) Requests are continuously drained from the queue, highest effort first, + subject to multiple constraints on speed [HANDLE_QUEUE] + +2.2. Proof-of-work overview + +2.2.2. Dynamic PoW + + DoS 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. Hence, instead of forcing clients to go below a + static target like in Bitcoin to be successful, 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. This is similar to how + proof-of-stake works but instead of staking coins, you stake work. + + The benefit here is that legitimate clients who really care about getting + access can spend a big amount of effort into their PoW computation, which + should guarantee access to the service given reasonable adversary models. See + [PARAM_TUNING] for more details about these guarantees and tradeoffs. + + As a way to improve reachability and UX, the service tries to estimate the + effort needed for clients to get access at any given time and places it in + the descriptor. See [EFFORT_ESTIMATION] for more details. + +``` diff --git a/spec/hspow-spec/v1-equix.md b/spec/hspow-spec/v1-equix.md new file mode 100644 index 0000000..2756e39 --- /dev/null +++ b/spec/hspow-spec/v1-equix.md @@ -0,0 +1,233 @@ +```text + +2.2.1. Algorithm overview + + For our proof-of-work function we will use the Equi-X scheme by tevador + [REF_EQUIX]. 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. + + 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) Above the level of individual PoW handshakes, the client and service + form a closed-loop system that adjusts the effort of future handshakes. + + The Equi-X scheme 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. + + We tune Equi-X in section [EQUIX_TUNING]. + +2.2.3. PoW effort + + 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 estimation system, it's quite useful if we + instead have a linear scale. We use the first 32 bits of a hashed version + of the Equi-X solution as compared to the full 32-bit range. + + Conceptually we could define a function: + 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: + effort(00000001100010101101) = 11111111111111111111 + / 00000001100010101101 + or the same in decimal: + 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. + +3.1. Service encodes PoW parameters in descriptor [DESC_POW] + + This whole protocol starts with the service encoding the PoW parameters in + the 'encrypted' (inner) part of the v3 descriptor. As follows: + + "pow-params" SP type SP seed-b64 SP suggested-effort + SP expiration-time NL + + [At most once] + + type: The type of PoW system used. We call the one specified here "v1" + + seed-b64: A random seed that should be used as the input to the PoW + hash function. Should be 32 random bytes encoded in base64 + without trailing padding. + + suggested-effort: An unsigned integer specifying an effort value that + clients should aim for when contacting the service. Can be + zero to mean that PoW is available but not currently + suggested for a first connection attempt. See + [EFFORT_ESTIMATION] for more details here. + + expiration-time: A timestamp in "YYYY-MM-DDTHH:MM:SS" format (iso time + with no space) after which the above seed expires and + is no longer valid as the input for PoW. It's needed + so that our replay cache does not grow infinitely. It + should be set to RAND_TIME(now+7200, 900) seconds. + + 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 + [INTRO1_POW] for more info. + + By RAND_TIME(ts, interval) we mean a time between ts-interval and ts, chosen + uniformly at random. + +3.2. Client fetches descriptor and computes PoW [CLIENT_POW] + + 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 has not expired and if it has, it needs to + fetch a new descriptor. + + The client should then extract the field to configure its + PoW 'target' (see [REF_TARGET]). The client SHOULD NOT accept 'target' values + that will cause unacceptably long PoW computation. + + The client uses a "personalization string" P equal to the following + nul-terminated ASCII string: "Tor hs intro v1\0". + + The client looks up `ID`, the current 32-byte blinded public ID + (KP_hs_blind_id) for the onion service. + + To complete the PoW the client follows the following logic: + + a) Client selects a target effort E, based on and past + connection attempt history. + b) Client generates a secure random 16-byte nonce N, as the starting + point for the solution search. + c) Client derives seed C by decoding 'seed-b64'. + d) Client calculates S = equix_solve(P || ID || C || N || E) + e) Client calculates R = ntohl(blake2b_32(P || ID || C || N || E || S)) + f) Client checks if R * E <= UINT32_MAX. + f1) If yes, success! The client can submit N, E, the first 4 bytes of + C, and S. + f2) If no, fail! The client interprets N as a 16-byte little-endian + integer, increments it by 1 and goes back to step d). + + 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 S as the solution + of the Equix-X puzzle with N as the nonce, C as the seed. How quickly this + happens depends solely on 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. + +3.3. Client sends PoW in INTRO1 cell [INTRO1_POW] + + Now that the client has an answer to the puzzle it's time to encode it into + an INTRODUCE1 cell. To do so the client adds an extension to the encrypted + portion of the INTRODUCE1 cell by using the EXTENSIONS field (see + [PROCESS_INTRO2] section in rend-spec-v3.txt). The encrypted portion of the + INTRODUCE1 cell only gets read by the onion service and is ignored by the + introduction point. + + We propose a new EXT_FIELD_TYPE value: + + [02] -- PROOF_OF_WORK + + The EXT_FIELD content format is: + + POW_VERSION [1 byte] + POW_NONCE [16 bytes] + POW_EFFORT [4 bytes] + POW_SEED [4 bytes] + POW_SOLUTION [16 bytes] + + where: + + POW_VERSION is 1 for the protocol specified in this proposal + POW_NONCE is the nonce 'N' from the section above + POW_EFFORT is the 32-bit integer effort value, in network byte order + POW_SEED is the first 4 bytes of the seed used + + This will increase the INTRODUCE1 payload size by 43 bytes since the + extension type and length is 2 extra bytes, the N_EXTENSIONS field is always + present and currently set to 0 and the EXT_FIELD is 41 bytes. According to + ticket #33650, INTRODUCE1 cells currently have more than 200 bytes + available. + +3.4. 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 cell without any embedded proof-of-work, the service SHOULD + consider this cell as a zero-effort introduction for the purposes of the + priority queue (see section [INTRO_QUEUE]). + +3.4.1. PoW verification [POW_VERIFY] + + To verify the client's proof-of-work the service MUST do the following steps: + + a) Find a valid seed C that starts with POW_SEED. Fail if no such seed + exists. + b) Fail if N = POW_NONCE is present in the replay cache + (see [REPLAY_PROTECTION]) + c) Calculate R = ntohl(blake2b_32(P || ID || C || N || E || S)) + d) Fail if R * E > UINT32_MAX + e) Fail if equix_verify(P || ID || C || N || E, S) != EQUIX_OK + f) Put the request in the queue with a priority of E + + If any of these steps fail the service MUST ignore this introduction request + and abort the protocol. + + In this proposal 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 as detailed in section [INTRO_QUEUE]. + +``` -- cgit v1.2.3-54-g00ecf From 3087655aae0d5834cd53f18979e4eef9e944ec17 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 16:49:01 -0800 Subject: Proof of work data types for rend-spec This moves the description of data formats used by proof of work into their home locations in rend-spec: the 'pow-params' line is in hsdesc-encrypt, and the introduction extension is explained inline with the introduction protocol. Made some small edits to contextualize the text but it's mostly the same as the proposal 327 description still. --- spec/rend-spec/hsdesc-encrypt.md | 31 +++++++++++++++++- spec/rend-spec/introduction-protocol.md | 57 ++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/spec/rend-spec/hsdesc-encrypt.md b/spec/rend-spec/hsdesc-encrypt.md index 06713a2..09aacbd 100644 --- a/spec/rend-spec/hsdesc-encrypt.md +++ b/spec/rend-spec/hsdesc-encrypt.md @@ -239,13 +239,42 @@ list of intro points etc. The plaintext has the following format: "single-onion-service" - [None or at most once] + [At most once] If present, this line indicates that the service is a Single Onion Service (see prop260 for more details about that type of service). This field has been introduced in 0.3.0 meaning 0.2.9 service don't include this. + "pow-params" SP type SP seed-b64 SP suggested-effort + SP expiration-time NL + + [At most once per "type"] + + If present, this line provides parameters for an optional proof-of-work + client puzzle. A client that supports an offered scheme can include a + corresponding solution in its introduction request to improve priority + in the service's processing queue. + + Only version 1 is currently defined. + Other versions may have a different format. + Introduced in tor-0.4.8.1-alpha. + + type: The type of PoW system used. We call the one specified here "v1". + + seed-b64: A random seed that should be used as the input to the PoW + hash function. Should be 32 random bytes encoded in base64 + without trailing padding. + + suggested-effort: An unsigned integer specifying an effort value that + clients should aim for when contacting the service. Can be + zero to mean that PoW is available but not currently + suggested for a first connection attempt. + + expiration-time: A timestamp in "YYYY-MM-DDTHH:MM:SS" format (iso time + with no space) after which the above seed expires and + is no longer valid as the input for PoW. + Followed by zero or more introduction points as follows (see section [NUM_INTRO_POINT] below for accepted values): diff --git a/spec/rend-spec/introduction-protocol.md b/spec/rend-spec/introduction-protocol.md index 98e71a2..3c0ba0c 100644 --- a/spec/rend-spec/introduction-protocol.md +++ b/spec/rend-spec/introduction-protocol.md @@ -34,7 +34,7 @@ the introduction request to the client. -### Extensible ESTABLISH_INTRO protocol. {#EST_INTRO} +### Extensible ESTABLISH_INTRO protocol {#EST_INTRO} When a hidden service is establishing a new introduction point, it sends an ESTABLISH_INTRO cell with the following contents: @@ -115,15 +115,17 @@ later in INTRODUCE1 cells. -#### Denial-of-Service Defense Extension. {#EST_INTRO_DOS_EXT} +#### Denial-of-Service defense extension {#EST_INTRO_DOS_EXT} This extension can be used to send Denial-of-Service (DoS) parameters to the introduction point in order for it to apply them for the introduction circuit. +This is for the [rate limiting DoS mitigation](../dos-spec/overview.md#hs-intro-rate) specifically. + If used, it needs to be encoded within the N_EXTENSIONS field of the ESTABLISH_INTRO cell defined in the previous section. The content is -defined as follow: +defined as follows: EXT_FIELD_TYPE: @@ -240,7 +242,7 @@ apply to the extension fields here as described \[EST_INTRO\] above. -## Sending an INTRODUCE1 cell to the introduction point. {#SEND_INTRO1} +## Sending an INTRODUCE1 cell to the introduction point {#SEND_INTRO1} In order to participate in the introduction protocol, a client must know the following: @@ -267,7 +269,7 @@ or that its request will not succeed. -### INTRODUCE1 cell format {#FMT_INTRO1} +### Extensible INTRODUCE1 cell format {#FMT_INTRO1} When a client is connecting to an introduction point, INTRODUCE1 cells should be of the form: @@ -310,6 +312,51 @@ client.) The same rules for multiplicity, ordering, and handling unknown types apply to the extension fields here as described \[EST_INTRO\] above. +#### Proof-of-work extension to INTRODUCE1 {#INTRO1_POW_EXT} + +This extension can be used to optionally attach a proof of work to the introduction request. +The proof must be calculated using unique parameters appropriate for this specific service. +An acceptable proof will raise the priority of this introduction request according to the proof's verified computational effort. + +This is for the [proof-of-work DoS mitigation](../dos-spec/overview.md#hs-intro-pow), described in depth by the [Proof of Work for onion service introduction](../hspow-spec/index.md) specification. + +If used, it needs to be encoded within the N_EXTENSIONS field of the +ESTABLISH_INTRO cell defined in the previous section. The content is +defined as follows: + +EXT_FIELD_TYPE: + +\[02\] -- `PROOF_OF_WORK` + +```text +The EXT_FIELD content format is: + + POW_VERSION [1 byte] + POW_NONCE [16 bytes] + POW_EFFORT [4 bytes] + POW_SEED [4 bytes] + POW_SOLUTION [16 bytes] + +where: + +POW_VERSION is 1 for the protocol specified here +POW_NONCE is the nonce value chosen by the client's solver +POW_EFFORT is the effort value chosen by the client, + as a 32-bit integer in network byte order +POW_SEED identifies which seed was in use, by its first 4 bytes +POW_SOLUTION is a matching proof computed by the client's solver +``` + +Only version 1 is currently defined. +Other versions may have a different format. +A correctly functioning client should only submit solutions with a version and seed which at some point were advertised by the server. +An extension with an unknown version or seed is suspicious and SHOULD result in introduction failure. + +This will increase the INTRODUCE1 payload size by 43 bytes since the extension type and length is 2 extra bytes, the N_EXTENSIONS field is always present and currently set to 0 and the EXT_FIELD is 41 bytes. +According to ticket #33650, INTRODUCE1 cells currently have more than 200 bytes available. + +Introduced in tor-0.4.8.1-alpha. + ### INTRODUCE_ACK cell format. {#INTRO_ACK} -- cgit v1.2.3-54-g00ecf From 1be2d06540cc20e22d7413888ac2c794d85d7d0c Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 17:08:28 -0800 Subject: Markdown formatting and link updates for hspow-spec/motivation --- spec/hspow-spec/motivation.md | 129 ++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 75 deletions(-) diff --git a/spec/hspow-spec/motivation.md b/spec/hspow-spec/motivation.md index 1c77f58..a79bac7 100644 --- a/spec/hspow-spec/motivation.md +++ b/spec/hspow-spec/motivation.md @@ -1,106 +1,85 @@ -```text +# Motivation -0. Abstract +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. - This proposal aims to thwart introduction flooding DoS attacks by introducing - a dynamic Proof-Of-Work protocol that occurs over introduction circuits. +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. -1. Motivation +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. - So far 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 [REF_TLS_1]. +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. +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. +With the right parameters, this proof-of-work scheme acts as a gatekeeper to block amplification attacks by attackers while letting legitimate clients through. -1.1. Related work +## 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 [REF_TLS]. +For a similar concept, see the three internet drafts that have been proposed for defending against TLS-based DDoS attacks using client puzzles: -1.2. Threat model [THREAT_MODEL] +- [`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://tools.ietf.org/id/draft-nir-tls-puzzles-00.html) +- [`draft-ietf-ipsecme-ddos-protection-10`](https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10) -1.2.1. Attacker profiles [ATTACKER_MODEL] +## Threat model - This proposal is written to thwart specific attackers. A simple PoW proposal - cannot defend against all and every DoS attack on the Internet, but there are - adversary models we can defend against. +### Attacker profiles {#attacker-profiles} - Let's start with some adversary 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. - "The script-kiddie" +Let's start with some adversary profiles: - 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 script-kiddie" - "The small botnet" + 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 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 small botnet" - "The large 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 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. +- "The large botnet" - 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 [FUTURE_DESIGNS]). + 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. -1.2.2. User profiles [USER_MODEL] +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)). - We have attackers and we have users. Here are a few user profiles: +### User profiles {#user-profiles} - "The standard web user" +We have attackers and we have users. Here are a few user profiles: - 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 standard web user" - "The motivated 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. - 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 motivated user" - "The mobile 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. - 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. +- "The mobile user" - 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. + 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. -1.2.3. The DoS Catch-22 [CATCH22] +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. - 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. +### The DoS Catch-22 {#catch22} -``` \ No newline at end of file +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. -- cgit v1.2.3-54-g00ecf From 6feed93b692693e288bbbda64b3240394a542812 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 20:53:55 -0800 Subject: Markdown formatting, links, and editing pass for hspow-spec/v1-equix This retains the overall structure and order from before, but everything is reformatted into Markdown, with some minor edits and some fresh context and fresh hyperlinks. The data formats for the descriptor the and intro extension have moved out of the PoW spec entirely back into the main Tor spec, so those sections have been replaced by terse descriptions and links. --- spec/hspow-spec/v1-equix.md | 381 ++++++++++++++++++-------------------------- 1 file changed, 158 insertions(+), 223 deletions(-) diff --git a/spec/hspow-spec/v1-equix.md b/spec/hspow-spec/v1-equix.md index 2756e39..ccaf055 100644 --- a/spec/hspow-spec/v1-equix.md +++ b/spec/hspow-spec/v1-equix.md @@ -1,233 +1,168 @@ -```text +# Onion service proof-of-work: Version 1, 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. -2.2.1. Algorithm overview - - For our proof-of-work function we will use the Equi-X scheme by tevador - [REF_EQUIX]. 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. - - 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) Above the level of individual PoW handshakes, the client and service - form a closed-loop system that adjusts the effort of future handshakes. - - The Equi-X scheme 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. - - We tune Equi-X in section [EQUIX_TUNING]. - -2.2.3. PoW effort - - 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 estimation system, it's quite useful if we - instead have a linear scale. We use the first 32 bits of a hashed version - of the Equi-X solution as compared to the full 32-bit range. - - Conceptually we could define a function: - 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: - effort(00000001100010101101) = 11111111111111111111 - / 00000001100010101101 - or the same in decimal: - 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. - -3.1. Service encodes PoW parameters in descriptor [DESC_POW] - - This whole protocol starts with the service encoding the PoW parameters in - the 'encrypted' (inner) part of the v3 descriptor. As follows: - - "pow-params" SP type SP seed-b64 SP suggested-effort - SP expiration-time NL - - [At most once] - - type: The type of PoW system used. We call the one specified here "v1" - - seed-b64: A random seed that should be used as the input to the PoW - hash function. Should be 32 random bytes encoded in base64 - without trailing padding. - - suggested-effort: An unsigned integer specifying an effort value that - clients should aim for when contacting the service. Can be - zero to mean that PoW is available but not currently - suggested for a first connection attempt. See - [EFFORT_ESTIMATION] for more details here. - - expiration-time: A timestamp in "YYYY-MM-DDTHH:MM:SS" format (iso time - with no space) after which the above seed expires and - is no longer valid as the input for PoW. It's needed - so that our replay cache does not grow infinitely. It - should be set to RAND_TIME(now+7200, 900) seconds. - - 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 - [INTRO1_POW] for more info. - - By RAND_TIME(ts, interval) we mean a time between ts-interval and ts, chosen - uniformly at random. - -3.2. Client fetches descriptor and computes PoW [CLIENT_POW] - - 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 has not expired and if it has, it needs to - fetch a new descriptor. - - The client should then extract the field to configure its - PoW 'target' (see [REF_TARGET]). The client SHOULD NOT accept 'target' values - that will cause unacceptably long PoW computation. - - The client uses a "personalization string" P equal to the following - nul-terminated ASCII string: "Tor hs intro v1\0". - - The client looks up `ID`, the current 32-byte blinded public ID - (KP_hs_blind_id) for the onion service. - - To complete the PoW the client follows the following logic: - - a) Client selects a target effort E, based on and past - connection attempt history. - b) Client generates a secure random 16-byte nonce N, as the starting - point for the solution search. - c) Client derives seed C by decoding 'seed-b64'. - d) Client calculates S = equix_solve(P || ID || C || N || E) - e) Client calculates R = ntohl(blake2b_32(P || ID || C || N || E || S)) - f) Client checks if R * E <= UINT32_MAX. - f1) If yes, success! The client can submit N, E, the first 4 bytes of - C, and S. - f2) If no, fail! The client interprets N as a 16-byte little-endian - integer, increments it by 1 and goes back to step d). - - 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 S as the solution - of the Equix-X puzzle with N as the nonce, C as the seed. How quickly this - happens depends solely on 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. - -3.3. Client sends PoW in INTRO1 cell [INTRO1_POW] - - Now that the client has an answer to the puzzle it's time to encode it into - an INTRODUCE1 cell. To do so the client adds an extension to the encrypted - portion of the INTRODUCE1 cell by using the EXTENSIONS field (see - [PROCESS_INTRO2] section in rend-spec-v3.txt). The encrypted portion of the - INTRODUCE1 cell only gets read by the onion service and is ignored by the - introduction point. +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: - We propose a new EXT_FIELD_TYPE value: +- A fork of tevador's implementation is maintained within the C tor repository, in 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 implementation currently has somewhat lower verification performance than the original but otherwise offers equivalent features. + This is the [`equix` crate](https://tpo.pages.torproject.net/core/doc/rust/equix/index.html). - [02] -- PROOF_OF_WORK +## Algorithm overview {#overview} - The EXT_FIELD content format is: +The overall scheme consists of several layers that provide different pieces of this functionality: - POW_VERSION [1 byte] - POW_NONCE [16 bytes] - POW_EFFORT [4 bytes] - POW_SEED [4 bytes] - POW_SOLUTION [16 bytes] +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. - where: - - POW_VERSION is 1 for the protocol specified in this proposal - POW_NONCE is the nonce 'N' from the section above - POW_EFFORT is the 32-bit integer effort value, in network byte order - POW_SEED is the first 4 bytes of the seed used - - This will increase the INTRODUCE1 payload size by 43 bytes since the - extension type and length is 2 extra bytes, the N_EXTENSIONS field is always - present and currently set to 0 and the EXT_FIELD is 41 bytes. According to - ticket #33650, INTRODUCE1 cells currently have more than 200 bytes - available. - -3.4. 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 cell without any embedded proof-of-work, the service SHOULD - consider this cell as a zero-effort introduction for the purposes of the - priority queue (see section [INTRO_QUEUE]). +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. -3.4.1. PoW verification [POW_VERIFY] +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. - To verify the client's proof-of-work the service MUST do the following steps: - - a) Find a valid seed C that starts with POW_SEED. Fail if no such seed - exists. - b) Fail if N = POW_NONCE is present in the replay cache - (see [REPLAY_PROTECTION]) - c) Calculate R = ntohl(blake2b_32(P || ID || C || N || E || S)) - d) Fail if R * E > UINT32_MAX - e) Fail if equix_verify(P || ID || C || N || E, S) != EQUIX_OK - f) Put the request in the queue with a priority of E - - If any of these steps fail the service MUST ignore this introduction request - and abort the protocol. - - In this proposal 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 as detailed in section [INTRO_QUEUE]. +## 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 estimation 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: +- `type`, always `v1` for the algorithm described here +- `seed-b64`, a periodically updated 32-byte random seed, base64 encoded +- `suggested-effort`, the latest output from [service-side effort estimation](./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. +How quickly this happens, on average, depends mainly on 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 cell. +To do so the client adds an extension to the encrypted portion of the INTRODUCE1 cell by using the EXTENSIONS field. The encrypted portion of the INTRODUCE1 cell 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 cell without any embedded proof-of-work, the service SHOULD consider this cell 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). -- cgit v1.2.3-54-g00ecf From 95d3aa57c11c651237b69bd3d848f59a10d498ef Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 20:57:53 -0800 Subject: Markdown, editing, and fresh context for hspow-spec/analysis-discussion This started as a formatting-oriented edit pass, but much of this was badly in need of fresh context now that the protocol is implemented and we have a more fully developed idea of what performance characteristics to expect. --- spec/hspow-spec/analysis-discussion.md | 727 +++++++++++++-------------------- 1 file changed, 274 insertions(+), 453 deletions(-) diff --git a/spec/hspow-spec/analysis-discussion.md b/spec/hspow-spec/analysis-discussion.md index 2c9d43f..483bd31 100644 --- a/spec/hspow-spec/analysis-discussion.md +++ b/spec/hspow-spec/analysis-discussion.md @@ -1,199 +1,134 @@ -```text +# Analysis and discussion -5. Attacker strategies [ATTACK_META] +## Attacker strategies {#attacker-strategies} - Now that we defined our protocol we need to start tweaking the various - knobs. But before we can do that, we first need to understand a few - high-level attacker strategies to see what we are fighting against. +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. -5.1.1. Overwhelm PoW verification (aka "Overwhelm top half") [ATTACK_TOP_HALF] +### Overwhelm PoW verification (aka "Overwhelm top half") {#attack-top-half} - A basic attack here is the adversary spamming with bogus INTRO cells 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 - [POW_VERIFY] section. +A basic attack here is the adversary spamming with bogus INTRO cells 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 [POW_VERIFY] section. - That's why we need the PoW algorithm to have a cheap verification time so - that this attack is not possible: we tune this PoW parameter in section - [POW_TUNING_VERIFICATION]. +That's why we need the PoW algorithm to have a cheap verification time so that this attack is not possible: we tune this PoW parameter in section [POW_TUNING_VERIFICATION]. -5.1.2. Overwhelm rendezvous capacity (aka "Overwhelm bottom half") - [ATTACK_BOTTOM_HALF] +### Overwhelm rendezvous capacity (aka "Overwhelm bottom half") {#attack-bottom-half} - Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure - in the [HANDLE_QUEUE] section. +Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure in the [HANDLE_QUEUE] section. - To do so, the attacker would have to send at least 20 high-effort - introduction cells every 100ms, where high-effort is a PoW which is above the - estimated level of "the motivated user" (see [USER_MODEL]). +To do so, the attacker would have to send at least 20 high-effort introduction cells every 100ms, where high-effort is a PoW which is above the estimated level of "the motivated user" (see [USER_MODEL]). - An easier attack for the adversary, is the same strategy but with - introduction cells that are all above the comfortable level of "the standard - user" (see [USER_MODEL]). This would block out all standard users and only - allow motivated users to pass. +An easier attack for the adversary, is the same strategy but with introduction cells that are all above the comfortable level of "the standard user" (see [USER_MODEL]). +This would block out all standard users and only allow motivated users to pass. -5.1.3. Hybrid overwhelm strategy [ATTACK_HYBRID] +### 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: +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 cell. 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 introduction cell. +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 cells 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 | Cells 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 cells 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 introduction cells 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 introduction cells 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 INTRODUCE2 cells 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 cells queued per second based on a single "top half" time seems like good enough to get some initial intuition. +That said, the values of "Cells queued per second" from the table above, are likely much smaller than displayed above because of all the auxiliary overheads. - This attack only has half the bandwidth requirement of [ATTACK_TOP_HALF] and - half the compute requirement of [ATTACK_BOTTOM_HALF]. - - Alternatively, the attacker can adjust the ratio between invalid and - high-effort requests depending on their bandwidth and compute capabilities. - -5.1.4. Gaming the effort estimation logic [ATTACK_EFFORT] - - Another way to beat this system is for the attacker to game the effort - estimation logic (see [EFFORT_ESTIMATION]). 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 [ATTACK_BOTTOM_HALF] using medium effort PoW (see [REF_TEVADOR_1]) - -5.1.4. Precomputed PoW attack - - 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 [ATTACK_EFFORT] attack. - -6. Parameter tuning [POW_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 will then move towards analyzing the client starting difficulty setting - for our PoW system. That defines the expected time for clients to succeed in - our system, and the expected time for attackers to overwhelm our system. Same - as above we will do this in a way that's agnostic to the chosen PoW function. - - Currently, we have hardcoded the initial client starting difficulty at 8, - but this may be too low to ramp up quickly to various on and off attack - patterns. A higher initial difficulty may be needed for these, depending on - their severity. This section gives us an idea of how large such attacks can - be. - - Finally, using those two pieces we will tune our PoW function and pick the - right client starting difficulty setting. At the end of this section we will - know 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. - -6.1. PoW verification [POW_TUNING_VERIFICATION] - - Verifying a PoW token is the first thing that a service does when it receives - an INTRODUCE2 cell and it's detailed in section [POW_VERIFY]. This - verification happens during the "top half" part of the process. Every - millisecond spent verifying PoW adds overhead to the already existing "top - half" part of handling an introduction cell. Hence we should be careful to - add minimal overhead here so that we don't enable attacks like [ATTACK_TOP_HALF]. - - During our performance measurements in [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 cells 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 | Cells 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 cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - - For a PoW function with a 2ms verification time, an attacker needs to send - 442 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - - For a PoW function with a 10ms verification time, an attacker needs to send - 97 dummy introduction cells per second to succeed in a [ATTACK_TOP_HALF] attack. - - 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 INTRODUCE2 cells 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 cells - queued per second based on a single "top half" time seems like good enough to - get some initial intuition. That said, the values of "Cells queued per - second" from the table above, are likely much smaller than displayed above - because of all the auxiliary overheads.] - -6.2. 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 [ATTACK_BOTTOM_HALF] attack 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. - - Our system is dynamic but 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 we do need - to define a starting difficulty, to minimize retries by clients. - -6.2.1. Analysis based on adversary power - - 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. +### 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 | =========================================================================== @@ -211,368 +146,260 @@ | 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. - -6.2.2. Analysis based on Tor's performance [POW_DIFFICULTY_TOR] - - To go deeper here, we can use the performance measurements from - [TOR_MEASUREMENTS] to get a more specific intuition on the starting - difficulty. In particular, we learned that completely handling an - introduction cell takes 5.55 msecs in average. Using that value, we can - compute the following table, that describes the number of introduction cells - we can handle per second for different values of PoW verification: - - +---------------------+-----------------------+--------------+ - |PoW Verification Time| Total time to handle | Cells handled| - | | introduction cell | 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 cells per second to succeed in a - [ATTACK_BOTTOM_HALF] attack. - - - For a PoW function with a 10ms verification time, an attacker needs to send - 64 high-effort introduction cells per second to succeed in a - [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 [ATTACK_BOTTOM_HALF] attack. - - Of course, when it comes to this table, the same disclaimer as in section - [POW_TUNING_VERIFICATION] is valid. That is, the above table is just a - theoretical extrapolation and we expect the real values to be much lower - since they depend on auxiliary processing overheads, and on the network's - capacity. - - -7. Discussion - -7.1. UX - - This proposal has user facing UX consequences. +Here is how you can read the table above: - 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. +- 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. -7.2. Future work [FUTURE_WORK] +With the above table we can create some profiles for starting values of our PoW difficulty. -7.2.1. Incremental improvements to this proposal +#### Analysis based on Tor's performance {#pow-difficulty-tor} - 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: +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 cell takes 5.55 msecs in average. +Using that value, we can compute the following table, that describes the number of introduction cells we can handle per second for different values of PoW verification: - - End-to-end introduction ACKs +| PoW Verification Time | Total time to handle introduction cell | Cells 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 - 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 from - [CLIENT_BEHAVIOR] 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. +Here is how you can read the table above: - - Multithreading scheduler +- For a PoW function with a 1ms verification time, an attacker needs to send 152 high-effort introduction cells 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 cells per second to succeed in a [bottom-half attack](#attack-bottom-half) attack. - 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. +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. -7.2.2. Future designs [FUTURE_DESIGNS] +Note that in practice verification times are much lower; the scale of the above table does not match the current implementation's reality. - 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: +## User experience {#ux} - "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 cells. - See #31223 for more details. +This proposal has user facing UX consequences. - "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. +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. - "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. +## Future work {#future-work} - All of the above approaches are much more complicated than this proposal, and - hence we want to start easy before we get into more serious projects. +### Incremental improvements to this proposal -7.3. Environment +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: - We love the environment! We are concerned of how PoW schemes can waste energy - by doing useless hash iterations. Here is a few reasons we still decided to - pursue a PoW approach here: +- End-to-end introduction ACKs - "We are not making things worse" -- DoS attacks are already happening and - attackers are already burning energy to carry them out both on the - attacker side, on the service side and on the network side. We think that - asking legitimate clients to carry out PoW computations is not gonna - affect the equation too much, since an attacker right now can very - quickly cause the same damage that hundreds of legitimate clients do a - whole day. + 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. - "We hope to make things better" -- The hope is that proposals 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 [CATCH22] for a similar argument. +- Multithreading scheduler -8. Acknowledgements + 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. - Thanks a lot to tevador for the various improvements to the proposal and for - helping us understand and tweak the RandomX scheme. +### Future designs {#future-designs} - 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. +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: -Appendix A. Little-t tor introduction scheduler +- "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 cells. See #31223 for more details. - This section describes how we will implement this proposal in the "tor" - software (little-t tor). +- "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. - The following should be read as if tor is an onion service and thus the end - point of all inbound data. +- "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. -A.1. The Main Loop [MAIN_LOOP] +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. - 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. +## Environment {#environment} - From there, this event will empty the connection input buffer (inbuf) by - extracting and processing a cell at a time. The mainloop is single threaded - and thus each cell is handled sequentially. +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. - Processing an INTRODUCE2 cell at the onion service means a series of - operations (in order): +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. - 1) Unpack cell from inbuf to local buffer. +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 is not gonna 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. - 2) Decrypt cell (AES operations). +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) for a similar argument. - 3) Parse cell header and process it depending on its RELAY_COMMAND. +## Acknowledgements {#acknowledgements} - 4) INTRODUCE2 cell handling which means building a rendezvous circuit: - i) Path selection - ii) Launch circuit to first hop. +Thanks a lot to tevador for the various improvements to the proposal and for helping us understand and tweak the RandomX scheme. - 5) Return to mainloop event which essentially means back to step (1). +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. - Tor will read at most 32 cells out of the inbuf per mainloop round. +## Scheduler implementation for C tor {#tor-scheduler} -A.2. Requirements for PoW +This section describes how we will implement this proposal in the "tor" software (little-t tor). - With this proposal, in order to prioritize cells by the amount of PoW work - it has done, cells can _not_ be processed sequentially as described above. +The following should be read as if tor is an onion service and thus the end point of all inbound data. - Thus, we need a way to queue a certain number of cells, prioritize them and - then process some cell(s) from the top of the queue (that is, the cells that - have done the most PoW effort). +### The Main Loop {#tor-main-loop} - We thus require a new cell processing flow that is _not_ compatible with - current tor design. The elements are: +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. - - Validate PoW and place cells in a priority queue of INTRODUCE2 cells (as - described in section [INTRO_QUEUE]). +From there, this event will empty the connection input buffer (inbuf) by extracting and processing a cell at a time. +The mainloop is single threaded and thus each cell is handled sequentially. - - Defer "bottom half" INTRO2 cell processing for after cells have been - queued into the priority queue. +Processing an INTRODUCE2 cell at the onion service means a series of operations (in order): -A.3. Proposed scheduler [TOR_SCHEDULER] +1. Unpack cell from inbuf to local buffer. +2. Decrypt cell (AES operations). +3. Parse cell header and process it depending on its RELAY_COMMAND. +4. INTRODUCE2 cell 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). - The intuitive way to address the A.2 requirements would be to do this - simple and naive approach: +Tor will read at most 32 cells out of the inbuf per mainloop round. - 1) Mainloop: Empty inbuf INTRODUCE2 cells into priority queue +### Requirements for PoW {#tor-pow-queue} - 2) Process all cells in pqueue +With this proposal, in order to prioritize cells by the amount of PoW work +it has done, cells can *not* be processed sequentially as described above. - 3) Goto (1) +Thus, we need a way to queue a certain number of cells, prioritize them and then process some cell(s) from the top of the queue (that is, the cells that have done the most PoW effort). - However, we are worried that handling all those cells 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 cells. This - means that we might spend lots of time dealing with introductions that don't - deserve it. See [BOTTOM_HALF_SCHEDULER] for more details. +We thus require a new cell processing flow that is *not* compatible with current tor design. The elements are: - We thus propose to split the INTRODUCE2 handling into two different steps: - "top half" and "bottom half" process, as also mentioned in [POW_VERIFY] - section above. +- Validate PoW and place cells in a priority queue of INTRODUCE2 cells ([the introduction queue](./common-protocol.md#intro-queue)). +- Defer "bottom half" INTRO2 cell processing for after cells have been queued into the priority queue. -A.3.1. Top half and bottom half scheduler +### Proposed scheduler {#tor-scheduler} - The top half process is responsible for queuing introductions into the - priority queue as follows: +The intuitive way to address the [queueing requirements](#tor-pow-queue) above would be to do this simple and naive approach: - a) Unpack cell from inbuf to local buffer. +1. Mainloop: Empty inbuf INTRODUCE2 cells into priority queue +2. Process all cells in pqueue +3. Goto (1) - b) Decrypt cell (AES operations). +However, we are worried that handling all those cells 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 cells. +This means that we might spend lots of time dealing with introductions that don't deserve it. - c) Parse INTRODUCE2 cell header and validate PoW. +We thus propose to split the INTRODUCE2 handling into two different steps: "top half" and "bottom half" process. - d) Return to mainloop event which essentially means step (1). +#### Top half and bottom half {#top-half-bottom-half} - The top-half basically does all operations of section [MAIN_LOOP] except from (4). +The top half process is responsible for queuing introductions into the priority queue as follows: - 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. Unpack cell from inbuf to local buffer. +2. Decrypt cell (AES operations). +3. Parse INTRODUCE2 cell header and validate PoW. +4. Return to mainloop event which essentially means step (1). - a) Pop INTRODUCE2 cell from priority queue. +The top-half basically does all operations from the [main loop](#tor-main-loop) section above, excepting (4). - b) Parse and process INTRODUCE2 cell. +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: - c) End event and yield back to mainloop. +1. Pop INTRODUCE2 cell from priority queue. +2. Parse and process INTRODUCE2 cell. +3. End event and yield back to mainloop. -A.3.2. Scheduling the bottom half process [BOTTOM_HALF_SCHEDULER] +#### Scheduling the bottom half process {#sched-bottom-half} - The question now becomes: when should the "bottom half" event get triggered - from the mainloop? +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 cell into the priority queue. Then, as long as it has a - cell in the queue, it would re-schedule itself for immediate execution - meaning at the next mainloop round, it would execute again. +We propose that this event is scheduled in when the network I/O event queues at least 1 cell into the priority queue. Then, as long as it has a cell 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 cells to appear between cell 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. +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 cells to appear between cell 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. +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 cells in the future from 1 to N where N <= 32. +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 cells in the future from 1 to N where N <= 32. -A.4 Performance measurements +## Performance measurements - This section will detail the performance measurements we've done on tor.git - for handling an INTRODUCE2 cell and then a discussion on how much more CPU - time we can add (for PoW validation) before it badly degrades our - performance. +This section will detail the performance measurements we've done on `tor.git` for handling an INTRODUCE2 cell and then a discussion on how much more CPU time we can add (for PoW validation) before it badly degrades our performance. -A.4.1 Tor measurements [TOR_MEASUREMENTS] +### Tor measurements {#tor-measurements} - In this section we will derive measurement numbers for the "top half" and - "bottom half" parts of handling an introduction cell. +In this section we will derive measurement numbers for the "top half" and "bottom half" parts of handling an introduction cell. - These measurements have been done on tor.git at commit - 80031db32abebaf4d0a91c01db258fcdbd54a471. +These measurements have been done on tor.git at commit +`80031db32abebaf4d0a91c01db258fcdbd54a471`. - We've measured several set of actions of the INTRODUCE2 cell 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. +We've measured several set of actions of the INTRODUCE2 cell 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 +1. Full Mainloop Event - We start by measuring the full time it takes for a mainloop event to - process an inbuf containing INTRODUCE2 cells. The mainloop event processed - 2.42 cells per invocation on average during our measurements. + We start by measuring the full time it takes for a mainloop event to process an inbuf containing INTRODUCE2 cells. The mainloop event processed 2.42 cells 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 cell processing (bottom-half) +2. INTRODUCE2 cell 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] section: + 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) +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 cell where basic - validation is done. + 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 cell where basic validation is done. - There is an average of 2.42 INTRODUCE2 cells per mainloop event and so we - divide that by the full mainloop event mean time to get the time for one - cell. From that we subtract the "bottom half" mean time to get how much - the "top half" takes: + There is an average of 2.42 INTRODUCE2 cells per mainloop event and so we divide that by the full mainloop event mean time to get the time for one cell. + From that we subtract the "bottom half" mean time to get how much the "top half" takes: - => 13.43 / (7931 / 3279) = 5.55 - => 5.55 - 5.29 = 0.26 + ```text + => 13.43 / (7931 / 3279) = 5.55 + => 5.55 - 5.29 = 0.26 - Mean: 0.26 msec + Mean: 0.26 msec + ``` - To summarize, during our measurements the average number of INTRODUCE2 cells - a mainloop event processed is ~2.42 cells (7931 cells for 3279 mainloop - invocations). +To summarize, during our measurements the average number of INTRODUCE2 cells a mainloop event processed is ~2.42 cells (7931 cells 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 cell. Then if we look deeper - we see that the "top half" of INTRODUCE2 cell processing takes 0.26 msec in - average, whereas the "bottom half" takes around 5.33 msec. +This means that, taking the mean of mainloop event times, it takes ~5.55msec (13.43/2.42) to completely process an INTRODUCE2 cell. +Then if we look deeper we see that the "top half" of INTRODUCE2 cell 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. +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. -A.2. References +## 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: @@ -580,12 +407,6 @@ A.2. References [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_TLS]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt - https://tools.ietf.org/id/draft-nir-tls-puzzles-00.html - https://tools.ietf.org/html/draft-ietf-ipsecme-ddos-protection-10 - [REF_TLS_1]: https://www.ietf.org/archive/id/draft-nygren-tls-client-puzzles-02.txt - [REF_TEVADOR_1]: https://lists.torproject.org/pipermail/tor-dev/2020-May/014268.html [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 - ``` -- cgit v1.2.3-54-g00ecf From 3781ff1039e8d6b48f11e6c5e2e99222ea25d75d Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Wed, 8 Nov 2023 21:00:05 -0800 Subject: Structural and formatting edits for hspow-spec/common-protocol Formatting and structural edits to try and make the common-protocol section go together. Ended up repurposing parts of 'overview' for an introduction here, and deleting the separate overview section. --- spec/SUMMARY.md | 5 +- spec/hspow-spec/common-protocol.md | 310 +++++++++++++++++-------------------- spec/hspow-spec/overview.md | 68 -------- 3 files changed, 144 insertions(+), 239 deletions(-) delete mode 100644 spec/hspow-spec/overview.md diff --git a/spec/SUMMARY.md b/spec/SUMMARY.md index b3b88a8..e08c8f7 100644 --- a/spec/SUMMARY.md +++ b/spec/SUMMARY.md @@ -130,10 +130,9 @@ - [Appendix G: Text vectors](./rend-spec/text-vectors.md) - [`Proof of Work for onion service introduction`](./hspow-spec/index.md) - [Motivation](./hspow-spec/motivation.md) - - [Overview](./hspow-spec/overview.md) - - [Common Protocol](./hspow-spec/common-protocol.md) + - [Common protocol](./hspow-spec/common-protocol.md) - [Version 1, Equi-X and Blake2b](./hspow-spec/v1-equix.md) - - [Appendix A: Analysis and Discussion](./hspow-spec/analysis-discussion.md) + - [Analysis and discussion](./hspow-spec/analysis-discussion.md) # Anticensorship tools and protocols diff --git a/spec/hspow-spec/common-protocol.md b/spec/hspow-spec/common-protocol.md index 0aa9df5..844d87f 100644 --- a/spec/hspow-spec/common-protocol.md +++ b/spec/hspow-spec/common-protocol.md @@ -1,227 +1,201 @@ +# 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} -3. Protocol specification +The service MUST NOT accept introduction requests with the same (seed, nonce) tuple. +For this reason a replay protection mechanism must be employed. -3.4.1.1. Replay protection [REPLAY_PROTECTION] +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. - The service MUST NOT accept introduction requests with the same (seed, nonce) - tuple. For this reason a replay protection mechanism must be employed. +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 simplest way is to use a simple 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. +## The introduction queue {#intro-queue} - If there is a worry that we might get too many introductions during the - lifetime of a seed, we can use a Bloom filter as our replay cache - mechanism. The probabilistic nature of Bloom filters means that sometimes we - will flag some connections as replays even if they are not; with this false - positive probability increasing as the number of entries increase. However, - with the right parameter tuning this probability should be negligible and - well handled by clients. +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. - {TODO: Design and specify a suitable bloom filter for this purpose.} +### Adding introductions to the introduction queue {#add-queue} -3.4.2. The Introduction Queue [INTRO_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. -3.4.2.1. Adding introductions to the introduction queue [ADD_QUEUE] +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. - When PoW is enabled and a verified introduction comes through, the service - instead of jumping straight into rendezvous, queues it and prioritizes it - based on how much effort was devoted by the client to PoW. This means that - introduction requests with high effort should be prioritized over those with - low effort. +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. - To do so, the service maintains an "introduction priority queue" data - structure. Each element in that priority queue is an introduction request, - and its priority is the effort put into its PoW: +### Handling queued introductions {#handling-queue} - When a verified introduction comes through, the service uses its included - effort commitment value to place each request into the right position of the - priority_queue: The bigger the effort, the more priority it gets in the - queue. If two elements have the same effort, the older one has priority over - the newer one. +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. -3.4.2.2. Handling introductions from the introduction queue [HANDLE_QUEUE] +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. - The service should handle introductions 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 a description of how we - expect such a system to work in Tor, see [TOR_SCHEDULER] section. +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. -3.4.3. PoW effort estimation [EFFORT_ESTIMATION] +## Effort control {#effort-control} -3.4.3.1. High-level description of the effort estimation process +### Overall strategy for effort determination {#effort-strategy} - The service starts with a default suggested-effort value of 0, which keeps - the PoW defenses dormant until we notice signs of overload. +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. - The overall process of determining effort can be thought of as a set of - multiple coupled feedback loops. Clients perform their own effort - adjustments via [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. +[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. - 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. +An effective effort estimation 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. - 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 [CLIENT_TIMEOUT], - later clients will benefit from the service detecting this increased queued - effort and offering a larger suggested_effort. +The service starts with a default suggested-effort value of 0, which keeps the PoW defenses dormant until we notice signs of queue overload. - Effort increases and decreases both have an intrinsic 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. +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. -3.4.3.2. Service-side effort estimation +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. - Services keep an internal effort estimation which updates on a regular - periodic timer in response to measurements made on the queueing behavior - in the previous period. These internal effort changes can optionally trigger - client-visible suggested_effort changes when the difference is great enough - to warrant republishing to the HSDir. +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. - This evaluation and update period is referred to as HS_UPDATE_PERIOD. - The service side effort estimation 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. +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. - {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?} +### Service-side effort estimation {#service-effort} -3.4.3.3. Per-period service state +Services keep an internal effort estimation which updates on a regular periodic timer in response to measurements made on the queueing 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). - During each update period, the service maintains some state: +This evaluation and update period is referred to as `HS_UPDATE_PERIOD`. +The service-side effort estimation 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. - 1. TOTAL_EFFORT, a sum of all effort values for rendezvous requests that - were successfully validated and enqueued. +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? - 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. +#### Per-period service state {#service-effort-periodic} - 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. +During each update period, the service maintains some state: -3.4.3.4. Service AIMD conditions +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. - 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: +#### Service AIMD conditions {#service-effort-aimd} - 1. If MAX_TRIMMED_EFFORT > our previous internal suggested_effort, - always INCREASE. Requests that follow our latest advice are being - dropped. +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: - 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 the our latest suggestion isn't high enough - and requests will build up in the queue. +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. - 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. +When we INCREASE, the internal suggested_effort is increased to either its previous value + 1, or (`TOTAL_EFFORT` / `REND_HANDLED`), whichever is larger. - 4. If none of these conditions match, the suggested effort is unchanged. +When we DECREASE, the internal suggested_effort is scaled by 2/3rds. - When we INCREASE, the internal suggested_effort is increased to either its - previous value + 1, or (TOTAL_EFFORT / REND_HANDLED), whichever is larger. +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. - When we DECREASE, the internal suggested_effort is scaled by 2/3rds. +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 lower than the published `suggested-effort`. - 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. +#### Updating descriptor with new suggested effort {#service-effort-update} - 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. The service still adds requests with lower effort than - suggested-effort to the priority queue in [ADD_QUEUE]. +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 estimate updates on a regular timer, we avoid propagating those changes into the descriptor and the HSDir hosts unless there is a significant change. -3.4.3.5. Updating descriptor with new suggested effort +If the PoW params otherwise match but the seed has changed by less than 15 percent, services SHOULD NOT upload a new descriptor. - The service descriptors may be updated for multiple reasons including - introduction point rotation common to all v3 onion services, the scheduled - seed rotations described in [DESC_POW], and updates to the effort suggestion. - Even though the internal effort estimate updates on a regular timer, we avoid - propagating those changes into the descriptor and the HSDir hosts unless - there is a significant change. +### Client-side effort estimation {#client-effort} - If the PoW params otherwise match but the seed has changed by less than 15 - percent, services SHOULD NOT upload a new descriptor. +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. -4. Client behavior [CLIENT_BEHAVIOR] +#### Failure ambiguity {#client-failure-ambiguity} - This proposal introduces a bunch of new ways where a legitimate client can - fail to reach the onion service. +The first challenge in reacting to failure, in our case, is to even accurately and quickly understand when a failure has occurred. - Furthermore, there is currently no end-to-end way for the onion service to - inform the client that the introduction failed. The INTRO_ACK cell 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. +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 INTRO_ACK cell 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. Existing mechanisms - will discard an introduction point that's required too many retries. +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. -4.1. Clients handling timeouts [CLIENT_TIMEOUT] +#### Clients handling timeouts {#client-timeout} - Alice can fail to reach the onion service if her introduction request gets - trimmed off the priority queue in [HANDLE_QUEUE], or if the service does not - get through its priority queue in time and the connection times out. +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. +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. +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.} +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. +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: +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. +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). - 2. Otherwise, multiply the effort by (CLIENT_POW_RETRY_MULTIPLIER = 1.5). +#### Client-imposed effort limits {#client-limits} - 3. Constrain the new effort to be at least - (CLIENT_MIN_RETRY_POW_EFFORT = 8) and no greater than - (CLIENT_MAX_POW_EFFORT = 10000) +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. - {TODO: These hardcoded limits should be replaced by timed limits and/or - an unlimited solver with robust cancellation. This is issue tor#40787} +Effort values used for both initial connections and retries are currently limited to no greater than `CLIENT_MAX_POW_EFFORT` (= 10000). -``` \ No newline at end of file +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/overview.md b/spec/hspow-spec/overview.md deleted file mode 100644 index cb4ea7e..0000000 --- a/spec/hspow-spec/overview.md +++ /dev/null @@ -1,68 +0,0 @@ -```text - -2. System Overview - -2.1. Tor protocol overview - - +----------------------------------+ - | 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 proposal takes place during the - introduction phase of the onion service protocol. - - 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 [DESC_POW] - 2) Client fetches descriptor and computes PoW [CLIENT_POW] - 3) Client completes PoW and sends results in INTRO1 cell [INTRO1_POW] - 4) Service verifies PoW and queues introduction based on PoW effort - [SERVICE_VERIFY] - 5) Requests are continuously drained from the queue, highest effort first, - subject to multiple constraints on speed [HANDLE_QUEUE] - -2.2. Proof-of-work overview - -2.2.2. Dynamic PoW - - DoS 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. Hence, instead of forcing clients to go below a - static target like in Bitcoin to be successful, 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. This is similar to how - proof-of-stake works but instead of staking coins, you stake work. - - The benefit here is that legitimate clients who really care about getting - access can spend a big amount of effort into their PoW computation, which - should guarantee access to the service given reasonable adversary models. See - [PARAM_TUNING] for more details about these guarantees and tradeoffs. - - As a way to improve reachability and UX, the service tries to estimate the - effort needed for clients to get access at any given time and places it in - the descriptor. See [EFFORT_ESTIMATION] for more details. - -``` -- cgit v1.2.3-54-g00ecf From d3987e6889a51beef81bc7f4735c3749cd9fc78b Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Thu, 9 Nov 2023 12:09:28 -0800 Subject: Review feedback, repunctuate parenthetical --- spec/dos-spec/memory-exhaustion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/dos-spec/memory-exhaustion.md b/spec/dos-spec/memory-exhaustion.md index 591d950..2cc55eb 100644 --- a/spec/dos-spec/memory-exhaustion.md +++ b/spec/dos-spec/memory-exhaustion.md @@ -2,7 +2,7 @@ Memory exhaustion is a broad issue with many underlying causes. The Tor protocol requires clients, onion services, relays, and authorities to store various kind of information in buffers and caches. But an attacker can use these buffers and queues to exhaust the memory of the a targeted Tor process, and force the operating system to kill that process. -With this in mind, any Tor implementation—especially one that runs as a relay or onion service—must take steps to prevent memory-based denial-of-service attacks. +With this in mind, any Tor implementation (especially one that runs as a relay or onion service) must take steps to prevent memory-based denial-of-service attacks. ## Detecting low memory { #oom-detection } -- cgit v1.2.3-54-g00ecf From 1d7274bdcc7d46b0aec43ed44d99d2d7362593e5 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Thu, 9 Nov 2023 14:00:01 -0800 Subject: Another editing pass for hspow-spec and friends This mostly updates formatting and links. I added a little bit of new context, primarily a disclaimer and updated benchmark info for analysis-discussion.md --- spec/dos-spec/overview.md | 6 +++--- spec/hspow-spec/analysis-discussion.md | 28 +++++++++++++++------------ spec/hspow-spec/common-protocol.md | 28 ++++++++++++++------------- spec/hspow-spec/motivation.md | 4 ++-- spec/hspow-spec/v1-equix.md | 34 ++++++++++++++++++++------------- spec/rend-spec/introduction-protocol.md | 4 ++-- 6 files changed, 59 insertions(+), 45 deletions(-) diff --git a/spec/dos-spec/overview.md b/spec/dos-spec/overview.md index e159014..0ea0994 100644 --- a/spec/dos-spec/overview.md +++ b/spec/dos-spec/overview.md @@ -7,7 +7,7 @@ These mitigations are expected to improve network availability, but DoS mitigati The attack and defense environment changes over time. Expect that this document is an attempt to describe the current state of things, but that it may not be complete. -The defenses here are organized by the type of resource under contention. These can be physical resources (Memory, CPU, Bandwidth) or protocol resources (Connections, Circuits, Introductions). +The defenses here are organized by the type of resource under contention. These can be physical resources ([Memory](#memory), [CPU](#cpu), [Bandwidth](#bandwidth)) or protocol resources ([Channels](#channels), [Circuits](#circuits), [Introductions](#hs-intro)). In practice there are always overlaps between these resource types. Connecting to an onion service, for example, puts some strain on every resource type here. @@ -73,6 +73,6 @@ Based on the queue behavior, servers will continuously provide an updated effort Queue backlogs cause the effort to rise, and an idle server will cause the effort to decay. If the queue is never overfull the effort decays to zero, asking clients not to include a proof-of-work solution at all. -We may support multiple cryptographic algorithms for this puzzle in the future, but currently we support one type. It's called `v1` in our protocol, and it's based on the Equi-X algorithm developed for this purpose. See the document on [`Proof of Work for onion service introduction`](../hspow-spec/index.md). +We may support multiple cryptographic algorithms for this puzzle in the future, but currently we support one type. It's called `v1` in our protocol, and it's based on the Equi-X algorithm developed for this purpose. See the document on [Proof of Work for onion service introduction](../hspow-spec/index.md). -This defense is configured by an operator using the `HiddenServicePoW` configuration options. Additionally, it requires both the client and the onion service to be compiled with the `pow` module (`--enable-gpl` mode) available. Current versions of the Tor Browser do include `pow` support. +This defense is configured by an operator using the `HiddenServicePoW` configuration options. Additionally, it requires both the client and the onion service to be compiled with the `pow` module (and `--enable-gpl` mode) available. Despite this non-default build setting, proof of work *is* available through common packagers like the Tor Browser and Debian. diff --git a/spec/hspow-spec/analysis-discussion.md b/spec/hspow-spec/analysis-discussion.md index 483bd31..8f25623 100644 --- a/spec/hspow-spec/analysis-discussion.md +++ b/spec/hspow-spec/analysis-discussion.md @@ -1,23 +1,27 @@ # 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 (aka "Overwhelm top half") {#attack-top-half} +### Overwhelm PoW verification ("top half") {#attack-top-half} -A basic attack here is the adversary spamming with bogus INTRO cells 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 [POW_VERIFY] section. +A basic attack here is the adversary spamming with bogus INTRO cells 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 tune this PoW parameter in section [POW_TUNING_VERIFICATION]. +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 (aka "Overwhelm bottom half") {#attack-bottom-half} +### Overwhelm rendezvous capacity ("bottom half") {#attack-bottom-half} -Given the way the introduction queue works (see [HANDLE_QUEUE]), 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 procedure in the [HANDLE_QUEUE] section. +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 introduction cells every 100ms, where high-effort is a PoW which is above the estimated level of "the motivated user" (see [USER_MODEL]). +To do so, the attacker would have to send at least 20 high-effort introduction cells 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 introduction cells that are all above the comfortable level of "the standard user" (see [USER_MODEL]). +An easier attack for the adversary, is the same strategy but with introduction cells 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} @@ -240,11 +244,11 @@ Nevertheless, there are some massive differences in both the scale and the dynam 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 is not gonna 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 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) for a similar argument. +Also see [The DoS Catch-22](./motivation.md#catch22). ## Acknowledgements {#acknowledgements} @@ -272,8 +276,8 @@ Processing an INTRODUCE2 cell at the onion service means a series of operations 2. Decrypt cell (AES operations). 3. Parse cell header and process it depending on its RELAY_COMMAND. 4. INTRODUCE2 cell handling which means building a rendezvous circuit: - - Path selection - - Launch circuit to first hop. + - 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 cells out of the inbuf per mainloop round. diff --git a/spec/hspow-spec/common-protocol.md b/spec/hspow-spec/common-protocol.md index 844d87f..e0910ac 100644 --- a/spec/hspow-spec/common-protocol.md +++ b/spec/hspow-spec/common-protocol.md @@ -85,7 +85,7 @@ Clients automatically increase their bid when retrying, and services regularly o [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 estimation 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. +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. @@ -104,13 +104,13 @@ 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 estimation {#service-effort} +### Service-side effort control {#service-effort} -Services keep an internal effort estimation which updates on a regular periodic timer in response to measurements made on the queueing behavior in the previous period. +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 estimation 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. +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? @@ -128,35 +128,37 @@ During each update period, the service maintains some state: 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. +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. +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. +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 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. +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 lower than the published `suggested-effort`. +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 estimate updates on a regular timer, we avoid propagating those changes into the descriptor and the HSDir hosts unless there is a significant change. +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 estimation {#client-effort} +### 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. diff --git a/spec/hspow-spec/motivation.md b/spec/hspow-spec/motivation.md index a79bac7..8fffe3f 100644 --- a/spec/hspow-spec/motivation.md +++ b/spec/hspow-spec/motivation.md @@ -21,7 +21,7 @@ With the right parameters, this proof-of-work scheme acts as a gatekeeper to blo 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://tools.ietf.org/id/draft-nir-tls-puzzles-00.html) +- [`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 @@ -52,7 +52,7 @@ Let's start with some adversary profiles: 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)). +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} diff --git a/spec/hspow-spec/v1-equix.md b/spec/hspow-spec/v1-equix.md index ccaf055..77b7f95 100644 --- a/spec/hspow-spec/v1-equix.md +++ b/spec/hspow-spec/v1-equix.md @@ -15,13 +15,17 @@ Furthermore, it's designed for this particular use-case and hence cryptocurrency 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, in 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. +- 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 implementation currently has somewhat lower verification performance than the original but otherwise offers equivalent features. + 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} @@ -52,7 +56,7 @@ 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 estimation 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. +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 @@ -80,7 +84,7 @@ Thus the effort is communicated explicitly in our protocol, and it forms part of 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: - `type`, always `v1` for the algorithm described here - `seed-b64`, a periodically updated 32-byte random seed, base64 encoded -- `suggested-effort`, the latest output from [service-side effort estimation](./common-protocol.md#service-effort) +- `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. @@ -88,13 +92,13 @@ At every seed rotation, a new expiration time is chosen uniformly at random from - 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 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}. +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. +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. @@ -113,18 +117,22 @@ The solver itself is iterative; the following steps are repeated until they succ 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))` + + `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))` + + `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`. + + 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. -How quickly this happens, on average, depends mainly on the target effort `E` parameter. +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. diff --git a/spec/rend-spec/introduction-protocol.md b/spec/rend-spec/introduction-protocol.md index 3c0ba0c..60e5a40 100644 --- a/spec/rend-spec/introduction-protocol.md +++ b/spec/rend-spec/introduction-protocol.md @@ -349,8 +349,8 @@ POW_SOLUTION is a matching proof computed by the client's solver Only version 1 is currently defined. Other versions may have a different format. -A correctly functioning client should only submit solutions with a version and seed which at some point were advertised by the server. -An extension with an unknown version or seed is suspicious and SHOULD result in introduction failure. +A correctly functioning client only submits solutions with a version and seed which were advertised by the server and have not yet expired. +An extension with an unknown version or expired seed is suspicious and SHOULD result in introduction failure. This will increase the INTRODUCE1 payload size by 43 bytes since the extension type and length is 2 extra bytes, the N_EXTENSIONS field is always present and currently set to 0 and the EXT_FIELD is 41 bytes. According to ticket #33650, INTRODUCE1 cells currently have more than 200 bytes available. -- cgit v1.2.3-54-g00ecf From 2df330847f21111a6350b01f05d7a6f59ee3f1c3 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Thu, 9 Nov 2023 14:24:16 -0800 Subject: Fix bad link found by the now-fixed linkcheck --- spec/dos-spec/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/dos-spec/index.md b/spec/dos-spec/index.md index 1f88b09..3645935 100644 --- a/spec/dos-spec/index.md +++ b/spec/dos-spec/index.md @@ -2,6 +2,6 @@ This document covers the strategy, motivation, and implementation for denial-of-service mitigation systems designed into Tor. -The older `dos-spec` document is now the [Memory exhaustion](./dos-spec/memory-exhaustion.md) section here. +The older `dos-spec` document is now the [Memory exhaustion](./memory-exhaustion.md) section here. An in-depth description of the proof of work mechanism for onion services, originally [proposal 327](../../proposals/327-pow-over-intro.txt), is now in the [Proof of Work for onion service introduction](../hspow-spec/index.md) spec. \ No newline at end of file -- cgit v1.2.3-54-g00ecf