PHΛSE Docs PHASE.XYZ

Proxy Protocol

Technical Specification: On-Chain Metered Mobile-IP Egress over iroh

This page specifies the Phase proxy protocol for technical audiences: implementers of clients, exit operators, and integrators. It describes protocol behavior and network-level parameters; operator-configurable values are marked as current configuration and may change.

#Introduction

The Phase proxy protocol turns the network's validator fleet into a metered egress service: a client tunnels TCP connections through a Phase node — the exit — and the traffic leaves for the public internet from that node's own connection, typically a genuine mobile IP. Usage is metered per session and settled on-chain against a prepaid balance.

The protocol is built on three design commitments:

  1. Billing is mandatory. An exit refuses to start without at least one billing service configured, and no connection is relayed without metering. There is no unmetered mode.
  2. Discovery goes through the registry. Clients obtain exits from the billing layer's registry rather than naming arbitrary endpoints, so every serving exit is a registered, heartbeating participant.
  3. The exit relays bytes, never content. End-to-end encryption (TLS) is established between the client's application and the target; the exit forwards opaque bytes and, when the application uses TLS, cannot read or modify the payload.

The proxy shares its transport with the rest of the Phase network: the same QUIC-based iroh stack that carries consensus also carries proxy tunnels, on an endpoint of their own, with the same NAT traversal and relay fallback. Running an exit requires no additional infrastructure — it is a configuration flag on a Phase node, plus the address of a billing service.

#Roles and Protocol Surfaces

Five parties participate:

  • Application — any software speaking SOCKS5 to the local client.
  • Client (\mathcal{C}) — a local process exposing a SOCKS5 listener; holds an Ethereum-style key identifying the paying account c.
  • Exit (\mathcal{X}) — a Phase node with the proxy enabled (or a standalone exit binary); terminates tunnels and originates connections to targets.
  • Billing service (\mathcal{B}) — an HTTP/JSON service handling authentication, sessions, metering aggregation, the exit registry, and on-chain settlement. Proxied bytes never pass through it.
  • Target (\mathcal{T}) — the destination host on the internet.

Four protocol surfaces connect them: (i) the \mathcal{C}\to\mathcal{X} tunnel over QUIC (iroh), carrying the handshake and all proxied traffic; (ii) \mathcal{X}\to\mathcal{B} HTTP calls — the exit performs authentication, session management, and usage reporting on the client's behalf; (iii) a single \mathcal{C}\to\mathcal{B} call to list available exits; and (iv) \mathcal{B}\tochain JSON-RPC for balance reads and settlement writes.

The exit performs the billing login for the client. The client never sees the billing token; the exit obtains it during the handshake and uses it for all subsequent session calls.

#Life of a Request

The following walkthrough traces one application request end to end; each step is specified below or on the linked pages.

  1. The application issues a SOCKS5 CONNECT to the client's local listener.
  2. The client selects an exit from its candidate set — the union of registry listings from its configured billing services — and dials it over iroh QUIC (ALPN cells/proxy/0), racing up to three candidates in parallel.
  3. On the first connection to that exit, the authentication handshake runs: the client announces its account, signs a fresh challenge, and the exit opens a billing session on every configured billing service. The QUIC connection is now a metered session.
  4. The client opens a bidirectional stream and writes the length-prefixed target address.
  5. The exit checks the rate limit, resolves the target name exactly once, and evaluates the egress predicate (Egress Protection) on the resolved address.
  6. The exit connects to the target and answers the status byte; on 0x00 the stream becomes a transparent relay.
  7. The client completes the SOCKS5 handshake with the application; application-level TLS now runs end to end through the tunnel.
  8. The session meter counts the request and every byte in both directions.
  9. Every second, the exit pushes the cumulative meter to all session legs.
  10. Each billing service independently folds the reports into packages and charges against the account.
  11. On its settlement tick, the settler submits cumulative charge targets to the on-chain billing contract, which debits exactly the unsettled difference (Settlement).
  12. The account tops up, keeps browsing, or withdraws its unspent balance.

#Transport and Tunnel Protocol

#Transport

Tunnels run over QUIC via iroh with TLS 1.3. Exits are addressed by their ed25519 endpoint identifier — a cryptographic key, not an IP — with iroh providing NAT hole punching and relay fallback. The proxy uses a dedicated ALPN, cells/proxy/0.

Wire literals retain the project's original internal codename; they are fixed protocol constants and cannot change without breaking compatibility.

One QUIC connection corresponds to one billing session. Unidirectional streams carry the authentication handshake; each bidirectional stream carries exactly one tunnel.

#Opening a tunnel

To open a tunnel, the client writes a length-prefixed target address: a 16-bit little-endian length \ell (1 \le \ell \le 512) followed by \ell bytes of UTF-8 host:port. The exit responds with a single status byte:

StatusMeaning
0x00OK — tunnel established, raw relay begins
0x01malformed request (invalid length)
0x02target unreachable (includes egress-policy refusal)
0x03rate-limited — retry later

Refusals for unreachable targets and for egress-policy violations are indistinguishable on the wire: the exit does not disclose its internal policy surface to probing clients.

After 0x00, the stream is a transparent bidirectional byte pipe with no additional framing. The exit closes both directions when either end closes; the client handles half-close locally.

#Authentication Handshake

Before the first tunnel, four unidirectional streams establish the paying account:

  1. Account announcement. The client sends a tagged 21-byte message: tag 0x01 followed by its 20-byte account address c.
  2. Challenge. The exit requests a nonce from the billing layer and forwards it to the client (a 16-byte nonce, hex-encoded).
  3. Signature. The client returns a 65-byte secp256k1 signature R \,\|\, S \,\|\, y over the nonce, using Ethereum's standard signed-message encoding (EIP-191). The recovery byte y is the bare parity bit \{0,1\} — implementations must not apply the legacy 27{+}y offset.
  4. Verdict. The exit completes verification with the billing layer and answers one byte: 0x00 accepted, 0x01 refused.

On acceptance, the billing layer issues a bearer token (JWT, HS256) binding the session to the account address with a bounded lifetime. The token lives only between the exit and the billing services.

#Anchors and legs

An exit may be configured with several billing services for redundancy. During the handshake, the first service to answer the challenge becomes the session's anchor: only the anchor verifies the signature and mints the token. The session is then opened on every configured service; those that acknowledge within the open timeout become the session's legs. The leg set is fixed for the session's lifetime, and at least one leg is required — otherwise the handshake fails. Legs mint independent session identifiers that are deliberately uncorrelated across services.

#Client Behavior

The reference client is a small local daemon exposing a SOCKS5 listener (by default on the loopback interface) and holding the account key. It maintains no chain connection and speaks no billing API beyond a single listing request — everything else is delegated to the exit.

#Discovery and dialing

The client requests exit listings from each of its configured billing services, takes the union, and keeps a candidate set of bounded size. Dialing is happy-eyeballs: several candidates are raced in parallel and the first established connection wins. A candidate that fails is moved down the list for 60 s and redialed sooner only if nothing healthier is available, and reconnection attempts follow exponential backoff with jitter — a fleet of clients recovering from an outage spreads its reconnects instead of stampeding a single exit.

#Failover

If the active exit degrades or disconnects, the client transparently fails over to the next candidate: a fresh QUIC connection, a fresh handshake, and a fresh billing session. Application connections in flight on the old tunnel are terminated — the proxy provides connection-level, not migration-level, continuity — but new CONNECT requests are served without operator intervention.

#Half-close semantics

SOCKS5 applications may close one direction of a TCP stream while continuing to read the other. The client honors this locally; on the tunnel, the exit treats the first close from either side as the end of the tunnel and closes both directions. Applications requiring long half-open flows should hold the sending side open until the exchange completes.

#Design Notes

Why the exit performs the login. Pushing the billing handshake to the exit keeps the client radically thin — an account key and a SOCKS5 listener, with a single HTTP call for discovery. The bearer token never crosses into the client's trust domain, so a compromised application behind the client cannot exfiltrate a credential that spends the account elsewhere.

Why reports are cumulative. Loss-tolerance without sequencing. A metering stream built on deltas needs acknowledgements, retransmission, and gap detection; cumulative totals need none of these — any later report supersedes any earlier one, and the fold is order-insensitive for completed packages.

Why pricing is package-based. A package bundles a request budget with an included transfer volume, giving agents a predictable unit cost for request-dominated workloads while bounding the price of bulk transfer through per-block overage. It also decouples pricing from the wire: prices are billing-service parameters, not protocol constants, and can evolve without touching deployed exits or clients.

Why discovery is registry-only. If clients could dial arbitrary endpoints, unmetered exits and stale listings would be unavoidable. Registry-only discovery means every listed exit is a metered participant: every listed exit registered or sent a heartbeat within the last 45 s, and randomized listings spread the fleet's load without a scheduler.

Why refusals are indistinguishable. The unreachable-target status covers both genuinely unreachable hosts and egress-policy refusals. Distinguishing them would hand a probing client an oracle over the exit's internal network policy; merging them leaks nothing.

Why identities are separate. The transport identity (iroh key) proves possession of an endpoint; the account (Ethereum-style key) authorizes spending. Binding them per-session by a fresh challenge signature means the endpoint key alone cannot spend an account, and either can be rotated without the other.

© 2026 Phase Labs Technologies Inc. All rights reserved. Phase is a product of Phase Labs Technologies Inc.proxy-protocol.md