diff --git a/tools/nginx/relay-limit.conf b/tools/nginx/relay-limit.conf index a921031..a985563 100644 --- a/tools/nginx/relay-limit.conf +++ b/tools/nginx/relay-limit.conf @@ -2,5 +2,24 @@ # services' own limits (AUDIT CC-01). Goes in the http context: /etc/nginx/conf.d/crosschain-relay-limit.conf. # The site's pages poll relay/receipt and relay/info about once a second while an operation is under way, # so 10 requests a second with a burst of 40 leaves normal use untouched and only stops floods. -limit_req_zone $binary_remote_addr zone=crosschain_relay:10m rate=10r/s; +# +# The key: an IPv4 address as it is, an IPv6 address by its /64 (one subscriber usually holds a whole /64, +# so a key per address would not bind; audit 2026-11-24 R16). nginx prints $remote_addr compressed (RFC +# 5952), so each pattern below reads the first 64 bits from one way of writing it; generated and checked +# against the relayer's ipKey() on random addresses. An address none of them matches keeps its own key. +map $remote_addr $crosschain_relay_key { + "~^(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):" "$a:$b:$c:$d"; + "~^(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})::([0-9a-f]{1,4}(:[0-9a-f]{1,4}){0,3})?$" "$p0:$p1:$p2:0"; + "~^(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "$p0:$p1:0:$s0"; + "~^(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})::([0-9a-f]{1,4}(:[0-9a-f]{1,4}){0,3})?$" "$p0:$p1:0:0"; + "~^(?[0-9a-f]{1,4})::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "$p0:0:$s0:$s1"; + "~^(?[0-9a-f]{1,4})::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "$p0:0:0:$s0"; + "~^(?[0-9a-f]{1,4})::([0-9a-f]{1,4}(:[0-9a-f]{1,4}){0,3})?$" "$p0:0:0:0"; + "~^::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "0:$s0:$s1:$s2"; + "~^::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "0:0:$s0:$s1"; + "~^::(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4}):(?[0-9a-f]{1,4})$" "0:0:0:$s0"; + "~^::([0-9a-f]{1,4}(:[0-9a-f]{1,4}){0,3})?$" "0:0:0:0"; + default $binary_remote_addr; +} +limit_req_zone $crosschain_relay_key zone=crosschain_relay:10m rate=10r/s; limit_req_status 429; diff --git a/tools/relayer/README.md b/tools/relayer/README.md index 448ba21..760c2b7 100644 --- a/tools/relayer/README.md +++ b/tools/relayer/README.md @@ -24,11 +24,12 @@ Only operations that: The relay transaction uses the operation's own fee fields, so the relayer never pays a higher price than it gets back. Other limits: -- one pending operation per UP at a time: a UP stays blocked until its transaction is mined, and, if it is not mined within 3 minutes, while the EntryPoint has not used the operation's nonce, for up to 15 minutes (AUDIT CC-10); -- the relay transaction is signed and its hash recorded before it is broadcast: if the answer to the send is lost but the transaction reached the network, the page gets it, and the same operation sent again gets the same transaction, never a second one that would revert at the relayer's cost (AUDIT CC-10); -- rate limits (`limits` in the configuration): per IP (`perIpPerMinute`, default 6), for all clients together (`globalPerMinute`, default 60, before any RPC call), and per UP (`perSenderPerMinute`, default 3). The per-UP limit is charged only to operations that passed both simulations, so the UP's own signature: anyone can forge a request naming a UP, and such requests never use up that UP's quota (AUDIT CC-01); +- one pending operation per UP at a time, taken once the `handleOps` simulation has passed (so a forged operation never holds a UP's lock): a UP stays blocked until its transaction is mined, and, if it is not mined within 3 minutes, while the EntryPoint has not used the operation's nonce, for up to 15 minutes (AUDIT CC-10); +- the relay transaction is signed and written to a **record of sent transactions** before it is broadcast (AUDIT CC-10, audit 2026-11-24 R15): `relay-sends.json` in the service's state directory, `/var/lib/crosschain-relayer` (mode 600; `sendLogFile` in the configuration to put it elsewhere). If the answer to the send is lost but the transaction reached the network, the page gets it. If it is not found right after the error, its outcome is "unknown": the page gets a 502 that says it may have been sent, the UP stays blocked, and the same operation sent again gets that same signed transaction broadcast again, never a second one that would revert at the relayer's cost. A transaction is settled (and removed from the record) when it is mined, when its operation's nonce is used, or when another transaction of the relayer has used its nonce while it was never seen on the network (then it can never be mined: the UP is unblocked and the operation can be sent again); meanwhile one not seen is broadcast again. After a restart the record is read again: its transactions block their UPs and are settled as usual (dropped after 30 minutes). An unreadable record is moved aside (`relay-sends.json.unreadable-