Algorithm Search⌘K

Algorithmresearch

SybilGuard

Also called random route Sybil defense.

Limits Sybil nodes by random routes on a social graph, since few attack edges link the Sybil region to honest nodes.

Time
O(w^2 m) worst · average · best
Space
O(w m) extra
Where
d = the degree of the verifier; m = the number of edges; n = the number of honest nodes; w = the route length
Properties
decentralizedrandomized
Origin
Haifeng Yu, Michael Kaminsky, Phillip B. Gibbons, Abraham Flaxman, 2006

SybilGuard is a decentralized protocol that lets an honest node, the verifier, decide whether to accept another node, the suspect, in a peer-to-peer system that is open to the Sybil attack. It uses the social network of the users: an edge means a real trust relationship, so an attacker can create many identities but only a few edges, the attack edges, to honest users. Every node sends random routes of length ww along the graph, built from a fixed random permutation at each node, and a verifier accepts a suspect whose routes meet a majority of its own. Yu, Kaminsky, Gibbons and Flaxman showed that a verifier then accepts at most gwg w Sybil identities when there are gg attack edges.

In plain words

Each person in a network of friends keeps a fixed rule card: "if a message comes from this friend, pass it to that friend." Everyone sends a message along each of their friendships, and the message is passed on by the rule cards for a fixed number of steps. Each person on the way writes down who sent it.

To check a stranger, you ask whether the stranger's messages crossed the path of your own messages, and whether the person at the crossing really wrote the stranger's name down. Honest people's paths cross often, because they move among many honest friends. A cheater with many fake names has only a few real friends. All the fake names' messages must pass through those few friendships, and the fixed rule cards then send them along the same paths. So only a few fake names can ever be written down by honest people.

The problem

Input. An undirected social graph whose nodes are identities. The honest region has nn honest nodes; the Sybil region holds every identity that the adversary creates, with any edges among them. There are gg attack edges between the two regions. Each pair of friends shares a secret edge key, used with a message authentication code, so an honest node knows from which edge each message comes and can share at most one edge with the adversary per real friendship. Each node has a key pair of public-key cryptography; its public key is its identity. The route length is ww.

Adversary (Yu et al., Section 2). The adversary controls every Sybil node, knows the whole graph, may deviate from the protocol in any way, and may send any tables over the attack edges. It cannot add attack edges, which need real trust, and cannot forge the edge keys or private keys of honest nodes.

Output. For a verifier VV and a suspect SS: accept or reject. The goal is that honest verifiers accept most honest suspects and only a bounded number of Sybil identities.

The algorithm

  1. SETUP(G, w)
  2. 1every node x picks a uniformly random permutation π_x of its edges: a route that enters x on edge i leaves on edge π_x(i)
  3. 2repeat w rounds
  4. 3for each directed edge (p, x), let (q, p) be the edge that π_p maps to (p, x)
  5. 4p sends R[p, x] ← [p] followed by the first w - 1 entries of R[q, p] to x
  6. VERIFY(V, S)
  7. 5accepted ← 0
  8. 6for each of the deg(V) routes r of V, one along each edge of V, of w hops
  9. 7X ← the first node of r that appears in the witness lists sent by S
  10. 8if X exists and the key of S is in one of the registry tables of X: accepted ← accepted + 1
  11. 9accept S if and only if accepted ≥ deg(V) / 2

The table R[p,x]R[p, x] is the registry table that xx keeps for its edge from pp: entry ii is the identity whose route enters xx from pp at hop ii. Lines L2 to L4 fill it by shifting, as in Section 4.5 of Yu et al. A node of degree dd performs dd random routes, one along each edge, so it is registered at every node on its routes. In the same way, witness tables propagate backward and tell each node the ww nodes on each of its own routes, which is what SS sends in line L7. A Sybil node may send any table in line L4; honest nodes still run lines L3 and L4.

Example

Honest nodes AA to FF have edges AA-BB, AA-CC, BB-CC, BB-DD, CC-EE, DD-EE, DD-FF and EE-FF. Sybil identities XX, YY and ZZ have edges XX-YY, XX-ZZ and YY-ZZ, and the only attack edge is FF-XX. Take w=3w = 3. The routing tables of the honest nodes, drawn with seed 4 in the code, are:

node entered from, leaves to
AA B→CB \to C, C→BC \to B
BB A→DA \to D, C→AC \to A, D→CD \to C
CC A→AA \to A, B→BB \to B, E→EE \to E
DD B→FB \to F, E→BE \to B, F→EF \to E
EE C→DC \to D, D→FD \to F, F→CF \to C
FF D→XD \to X, E→EE \to E, X→DX \to D

The route of AA along its edge to BB visits BB, then DD (since BB maps A→DA \to D), then FF: its witness list is (B,D,F)(B, D, F). The other route of AA is (C,A,B)(C, A, B).

The adversary sends the table (X,Y,Z)(X, Y, Z) over the attack edge into FF. By its routing table, FF passes routes from XX on to DD, so DD stores (F,X,Y)(F, X, Y) for its edge from FF. Then DD passes routes from FF on to EE, so EE stores (D,F,X)(D, F, X). These 3+2+1=63 + 2 + 1 = 6 entries are the only Sybil entries among the 51 entries of the honest registry tables, and they name only XX, YY and ZZ: gw=3g w = 3 names.

  • Honest suspect EE. The routes of EE are (C,E,D)(C, E, D), (D,B,C)(D, B, C) and (F,E,C)(F, E, C). The route (B,D,F)(B, D, F) of AA first meets them at BB, whose table for its edge from DD is (D,E,C)(D, E, C) and contains EE. The route (C,A,B)(C, A, B) first meets them at CC, whose table for its edge from EE is (E,F,E)(E, F, E). Both routes accept, so AA accepts EE.
  • Sybil suspect ZZ, claiming the route (F)(F). The first route of AA meets FF at hop 3, and FF lists ZZ in its table for the edge from XX; the second route of AA never meets FF. One route of two accepts, which is half, so AA accepts ZZ.
  • The same ZZ, claiming all honest nodes. Both routes of AA now first meet the claim at hop 1, at BB and at CC, and neither lists ZZ. AA rejects. The adversary picks its claim, so the bound below counts the worst claim.
  • Any other Sybil name WW. No honest table lists WW, so every route of AA rejects it, whatever WW claims.

Correctness

Theorem 1 (back-traceability, honest region). If every node follows lines L1 to L4, then for each hop ii from 1 to ww, every directed edge is crossed at hop ii by exactly one route, and after ww rounds entry ii of R[p,x]R[p, x] is the start of that route. A route that crosses some directed edge twice first repeats its own first edge.

Theorem 2 (Sybil bound). Against the adversary above, once the tables are stable (the adversary has sent the same table over each attack edge for ww rounds), the honest registry tables name at most gwg w Sybil identities, and at most w(w+1)/2w(w + 1) / 2 entries are copied from each attack edge. An honest verifier, fewer than half of whose routes reach the Sybil region, accepts only those identities, so at most gwg w Sybil identities, whatever the suspects claim. While the adversary changes its tables, old names can stay downstream for up to ww rounds.

The proofs are in proofs/correctness.md. Theorem 2 is the size bound of Section 3 of Yu et al., "at most gg Sybil groups, each of at most ww nodes", in a form that holds for every protocol deviation by the Sybil nodes.

Theorem (Yu et al., Theorem 1, cited). For a connected, non-bipartite social network, a random walk of length ww from a uniformly random honest node crosses one of the gg attack edges with probability at most gw/ng w / n. With w=Θ(nlog⁡n)w = \Theta(\sqrt{n} \log n) and g=o(n/log⁡n)g = o(\sqrt{n} / \log n) this is o(1)o(1). The theorem is about random walks; that it carries over to random routes is a heuristic, supported by the experiments of Yu et al.

Heuristic (honest acceptance). In a fast-mixing honest region (mixing time O(log⁡n)O(\log n)), a walk of Θ(nlog⁡n)\Theta(\sqrt{n} \log n) steps holds about n\sqrt{n} nearly independent samples of the stationary distribution, so two honest routes meet with probability 1−o(1)1 - o(1) by the birthday paradox. Yu et al. give this as a high-level review of known results for random walks, not as a proof for random routes.

Proof: Correctness of SybilGuardfull

Let GG be an undirected graph in which every node has degree at least 1. A directed edge (p,x)(p, x) is an edge {p,x}\{p, x\} used from pp to xx. Every node xx has a permutation πx\pi_x of its edges (line L1). For a directed edge (p,x)(p, x), define its successor σ(p,x)=(x,y)\sigma(p, x) = (x, y), where {x,y}=πx({p,x})\{x, y\} = \pi_x(\{p, x\}). A route of ss along its edge to tt is the sequence of directed edges e1=(s,t)e_1 = (s, t) and ek+1=σ(ek)e_{k+1} = \sigma(e_k); it crosses eke_k at hop kk, and its witness list is the heads of e1,…,ewe_1, \ldots, e_w.

Lemma 1 (the successor is a bijection). σ\sigma is a bijection of the set of directed edges.

Proof. The set is finite, so it suffices that σ\sigma is onto. Take (x,y)(x, y). Since πx\pi_x is a permutation of the edges of xx, there is exactly one edge {p,x}\{p, x\} with πx({p,x})={x,y}\pi_x(\{p, x\}) = \{x, y\}, and then σ(p,x)=(x,y)\sigma(p, x) = (x, y). □\square

Theorem 1 (back-traceability). If every node is honest, then for each hop i∈{1,…,w}i \in \{1, \ldots, w\} every directed edge is crossed at hop ii by exactly one route, and after the ww rounds of lines L2 to L4, entry ii of R[p,x]R[p, x] is the start of that route. A route that crosses some directed edge twice repeats its first edge before any other edge.

Proof. A route is fixed by its first edge e1e_1, and it crosses σi−1(e1)\sigma^{i-1}(e_1) at hop ii. By Lemma 1, σi−1\sigma^{i-1} is a bijection, so for each directed edge ee there is exactly one first edge e1=σ−(i−1)(e)e_1 = \sigma^{-(i-1)}(e), and e1e_1 is the first edge of exactly one route, the route of its tail along it.

For the tables, show by induction on the round kk that after round kk, for every (p,x)(p, x), R[p,x]R[p, x] has min⁡(k,w)\min(k, w) entries and entry ii is the start of the route that crosses (p,x)(p, x) at hop ii. Before round 1 all tables are empty. In round kk, line L4 sets R[p,x]R[p, x] to pp followed by the first w−1w - 1 entries of R[q,p]R[q, p] from round k−1k - 1, where σ(q,p)=(p,x)\sigma(q, p) = (p, x). Entry 1 is pp, the start of the route of pp along (p,x)(p, x), which is the route that crosses (p,x)(p, x) at hop 1. For i≥2i \ge 2, entry ii is entry i−1i - 1 of R[q,p]R[q, p], which by induction is the start of the route that crosses (q,p)(q, p) at hop i−1i - 1. That route crosses σ(q,p)=(p,x)\sigma(q, p) = (p, x) at hop ii, and by the first claim it is the only one. The length is 1+min⁡(k−1,w−1)=min⁡(k,w)1 + \min(k - 1, w - 1) = \min(k, w).

For loops, let ek=eje_k = e_j with j<kj < k be the first repetition, with kk smallest. If j>1j > 1, then σ(ej−1)=ej=ek=σ(ek−1)\sigma(e_{j-1}) = e_j = e_k = \sigma(e_{k-1}), so ej−1=ek−1e_{j-1} = e_{k-1} by Lemma 1, a repetition that ends before hop kk. This contradicts the choice of kk, so j=1j = 1. □\square

Model of the adversary. Let HH be the honest nodes and AA the set of gg attack edges, each written as a directed edge (s,h)(s, h) with s∉Hs \notin H and h∈Hh \in H. Honest nodes run lines L1 to L4 and keep tables R[p,x]R[p, x] for x∈Hx \in H. Over each (s,h)∈A(s, h) \in A the adversary sends a list Ls,hL_{s, h} of its choice, and hh stores its first ww entries as R[s,h]R[s, h]. The adversary also chooses the permutations of Sybil nodes, the tables on edges between Sybil nodes, and the witness lists of Sybil suspects, with full knowledge of the graph. It cannot send on an edge with an honest tail, since it does not hold the edge keys of honest pairs. We consider the stable state: the adversary has sent the same list over each attack edge in the last ww rounds.

Lemma 2 (where Sybil names come from). In the stable state, every entry of an honest table is an honest identity or a member of Ls,h[1..w]L_{s, h}[1..w] for some (s,h)∈A(s, h) \in A. So the honest tables name at most gwg w distinct Sybil identities, and at most w(w+1)/2w(w + 1) / 2 entries are copied from each attack edge.

Proof. Consider entry ii of R[p,x]R[p, x] after the last round, with x∈Hx \in H. If p∉Hp \notin H, then (p,x)∈A(p, x) \in A and the entry is in Lp,x[1..w]L_{p, x}[1..w]. Otherwise pp is honest and ran line L4: entry 1 is the honest pp, and entry i≥2i \ge 2 is entry i−1i - 1 of R[q,p]R[q, p] from the round before, with σ(q,p)=(p,x)\sigma(q, p) = (p, x) and p∈Hp \in H. Follow this chain backward. After at most i−1i - 1 steps it stops either at entry 1 of a table on an edge with an honest tail, which is that honest tail, or at a table on an attack edge, from a round within the last ww rounds, whose content is Ls,h[1..w]L_{s, h}[1..w] by stability. This proves the first claim. There are gg attack edges and each list contributes at most ww names.

For the count of entries, fix (s,h)∈A(s, h) \in A. An entry copied from R[s,h]R[s, h] through tt steps of line L4 lies on the edge σt(s,h)\sigma^t(s, h), since each step moves from an edge to its successor, and it sits at position i=j+ti = j + t, where j≤wj \le w is its position in R[s,h]R[s, h]. So t≤w−1t \le w - 1, and the edge σt(s,h)\sigma^t(s, h) holds at most w−tw - t such entries, at positions t+1t + 1 to ww. The total is at most ∑t=0w−1(w−t)=w(w+1)/2\sum_{t=0}^{w-1} (w - t) = w(w + 1) / 2. □\square

Theorem 2 (Sybil bound). In the stable state, let VV be an honest verifier and suppose that fewer than half of the deg⁡(V)\deg(V) routes of VV contain a node outside HH. Then VV accepts no Sybil identity outside the at most gwg w names of Lemma 2, whatever witness lists the suspect sends. So VV accepts at most gwg w Sybil identities.

Proof. Let b<deg⁡(V)/2b < \deg(V) / 2 be the number of routes of VV that reach the Sybil region. If VV accepts SS, line L9 gives at least deg⁡(V)/2>b\deg(V) / 2 > b accepting routes, so some accepting route rr lies inside HH. For rr, line L8 found a node XX on rr, so X∈HX \in H, with the key of SS in a registry table of XX. That table is an honest table, so if SS is a Sybil identity, it is one of the at most gwg w names of Lemma 2. The witness lists sent by SS only choose which node XX line L7 picks; they cannot change honest tables. □\square

Remark (changing lists). If the adversary changes Ls,hL_{s, h} between rounds, the chain argument of Lemma 2 still shows that every Sybil entry comes from a list sent over an attack edge within the last ww rounds, but entries from different rounds can then hold different names, up to w(w+1)/2w(w + 1) / 2 per attack edge. After ww rounds without changes the stable state, and the bound gwg w, hold again.

Cost. Line L1 takes O(deg⁡(x))O(\deg(x)) time per node, O(n+m)O(n + m) in total. Each round of lines L3 and L4 builds one list of at most ww entries for each of the at most 2m2m directed edges, after finding the predecessor edge with the inverse permutation, so a round takes O(wm)O(w m) time and the ww rounds take O(w2m)O(w^2 m). The tables hold O(wm)O(w m) entries. Verification walks deg⁡(V)\deg(V) routes of ww hops and makes one lookup per node, O(deg⁡(V)w)O(\deg(V) w) expected time with a hash set of the claimed nodes. ■\blacksquare

Complexity

In the word RAM model, with one word per identity:

  • Setup. Each of the ww rounds of lines L2 to L4 copies ww entries for each of the 2m2m directed edges: O(w2m)O(w^2 m) time over the whole network, and O(w)O(w) words for each edge of a node. Per node of degree dd, the tables hold dwd w entries. Yu et al. estimate about 256 KB per registry table for w=2000w = 2000 and 1024-bit keys, and less with 160-bit hashes of the keys.
  • Verification. VV walks its deg⁡(V)\deg(V) witness lists of ww nodes and looks each node up in a hash set of the claimed nodes: O(dw)O(d w) expected time plus the size of the claim, and one query to each intersection node.
  • Updates. Tables change only when users or edges are created or deleted, not when nodes go offline (Section 5).

Properties

  • Convergence. Two routes that cross the same directed edge at any hops follow the same path from then on, because each node forwards by a fixed table.
  • Back-traceability. Because each table is a permutation, the edge out of a node fixes the edge in, so a route is fixed by one of its edges and the hop number.
  • Sybil groups. Yu et al. group the accepted nodes by the intersection node and the edge into it. At most gg groups hold Sybil nodes, and each group has at most ww nodes.
  • Decentralized. Each node keeps only its routing table, registry tables and witness tables, and talks only to its friends and to intersection nodes.
  • Not every honest node. Honest nodes near attack edges have a higher chance that their routes enter the Sybil region; the majority rule of line L9 limits the harm.

Variants and improvements

  • SybilLimit (Yu, Gibbons, Kaminsky and Xiao, 2008) uses Θ(m)\Theta(\sqrt{m}) routes of length Θ(log⁡n)\Theta(\log n) per node and registers keys on edges instead of nodes. It accepts O(log⁡n)O(\log n) Sybil nodes per attack edge, against O(nlog⁡n)O(\sqrt{n} \log n) for SybilGuard, and keeps the guarantee for g=o(n/log⁡n)g = o(n / \log n) attack edges (theorem of Yu et al., 2008).
  • SybilRank (2012) replaces random routes by a short power iteration of trust from honest seeds and ranks all accounts, for an operator who holds the whole graph.
  • Local choice of ww (Section 4.7). A node estimates the length at which two honest routes meet from short random walks, takes the median of several samples and sets ww to 2.1 times the median.
  • Bloom filters can summarize the witness tables sent in line L7 (Section 4.5).
  • Incremental routing tables (Section 5.2). When an edge is added or deleted, a node changes its permutation so that only routes entering by one edge are redirected.

When to use it

Use SybilGuard in an open peer-to-peer system without a central authority, when users can name a few real friends and exchange edge keys out of band, and when the honest social graph is fast mixing. It suits tasks that need a bound on Sybil identities per verifier, such as placing replicas or voting. It does not help when the adversary has compromised many honest nodes, since those already have real friends, and its bound becomes weak when gg approaches n/log⁡n\sqrt{n} / \log n; SybilLimit is the better choice there.

Pitfalls

  • Coin flips instead of tables. If line L1 lets a node pick a fresh random next hop each time a route passes, routes from the Sybil region no longer merge after the attack edge, and each Sybil identity can reach a different part of the honest region. Fix the permutation once in line L1.
  • A table that is not a permutation. If line L1 maps two incoming edges to the same outgoing edge, back-tracing is ambiguous, two routes compete for one registry entry in line L4, and Sybil groups are no longer bounded by ww. Use a bijection in line L1.
  • Trusting the claim. If line L8 accepts as soon as XX appears in the witness lists of SS, a Sybil suspect claims every node and is accepted. Line L8 must also check that XX lists the key of SS in its registry tables.
  • Any route suffices. If line L9 accepts when one route of VV accepts, a single route of VV that enters the Sybil region accepts every Sybil identity. Keep the majority threshold of line L9.
  • Wrong route length. If line L2 runs far more than Θ(nlog⁡n)\Theta(\sqrt{n} \log n) rounds, Sybil groups grow with ww and the verifier's routes enter the Sybil region more often; with too few rounds, honest routes do not meet and line L9 rejects honest suspects. Choose ww as in Section 4.7.

Implementations

The code is a synthetic, single-process model on graphs of at most 60 nodes: identities are node names instead of public keys, and there are no messages, edge keys or signatures. A route of the verifier that reaches a Sybil node counts as accepting, the worst case. The tests reproduce the example, compare the registry tables with a forward walk of every route on 500 random graphs, check Theorem 2 against random forged tables and claims on 100 graphs with two regions, and measure honest acceptance: on three random 60-node graphs with w=16w = 16, 1765 of 1770 sampled honest pairs, 99.7%, accepted each other (measurement).

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

sybilguard.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sybilguard/. The authors are listed in prov/QFN0T8.jsonl.

"""SybilGuard random routes, registry tables and verification (Yu et al., SIGCOMM 2006, Section 4).

A small synthetic model of the protocol on an undirected social graph given
as an adjacency dict. The position of a neighbor in a node's list is the
number of that edge. Identities are node names; real public keys, edge keys
and network messages are left out.
"""

import random
from typing import Hashable, Iterable, Mapping, Optional, Sequence

Node = Hashable
Adj = Mapping[Node, Sequence[Node]]
Perm = Mapping[Node, Sequence[int]]
Registry = dict[tuple[Node, Node], list[Node]]


def routing_tables(adj: Adj, rng: random.Random) -> dict[Node, list[int]]:
    """A uniformly random permutation of the edges of every node.

    perm[x][i] is the edge on which x forwards a route that arrived on edge i.
    Cost: O(n + m) time and space.
    """
    perm: dict[Node, list[int]] = {}
    for x in adj:
        p = list(range(len(adj[x])))
        rng.shuffle(p)  # @line L1
        perm[x] = p
    return perm


def next_hop(adj: Adj, perm: Perm, prev: Node, x: Node) -> Node:
    """The node after x on a route that entered x from prev. Cost: O(deg x)."""
    return adj[x][perm[x][list(adj[x]).index(prev)]]


def route(adj: Adj, perm: Perm, s: Node, j: int, w: int) -> list[Node]:
    """The witness list of the route of s along its edge j: the nodes at hops 1 to w.

    Precondition: 0 <= j < deg(s) and w >= 1. Cost: O(w d) time for maximum degree d.
    """
    prev, x = s, adj[s][j]
    out = [x]
    for _ in range(w - 1):
        prev, x = x, next_hop(adj, perm, prev, x)
        out.append(x)
    return out


def registries(
    adj: Adj,
    perm: Perm,
    w: int,
    honest: Optional[set] = None,
    forged: Optional[Mapping[tuple[Node, Node], Sequence[Node]]] = None,
) -> Registry:
    """Registry tables of the honest nodes after w synchronous rounds of propagation.

    reg[(p, x)][i - 1] is the identity whose route enters x from p at hop i.
    Nodes outside honest are Sybil nodes: on an attack edge (p, x) with p a
    Sybil node, the table is the adversary's choice forged[(p, x)], cut to w
    entries. honest=None means that every node is honest.
    Cost: O(w^2 m) time and O(w m) space.
    """
    if honest is None:
        honest = set(adj)
    forged = forged or {}
    inv = {p: {k: i for i, k in enumerate(perm[p])} for p in adj}
    reg: Registry = {(p, x): [] for x in honest for p in adj[x]}
    for _ in range(w):  # @line L2
        new: Registry = {}
        for (p, x) in reg:  # @line L3
            if p not in honest:
                new[(p, x)] = list(forged.get((p, x), []))[:w]
                continue
            q = adj[p][inv[p][list(adj[p]).index(x)]]
            new[(p, x)] = [p] + reg[(q, p)][: w - 1]  # @line L4
        reg = new
    return reg


def verify(
    adj: Adj,
    perm: Perm,
    w: int,
    reg: Registry,
    v: Node,
    suspect: Node,
    suspect_routes: Iterable[Sequence[Node]],
    honest: Optional[set] = None,
) -> bool:
    """Does the verifier v accept the identity suspect?

    suspect_routes are the witness lists that the suspect sends; a Sybil
    suspect may send any lists. A route of v that reaches a node outside
    honest is under the adversary's control and is counted as accepting.
    Cost: O(d w + L) time for maximum degree d and total claimed length L.
    """
    if honest is None:
        honest = set(adj)
    claimed = set()
    for r in suspect_routes:
        claimed.update(r)
    accepted = 0  # @line L5
    for j in range(len(adj[v])):  # @line L6
        r = route(adj, perm, v, j, w)
        if any(y not in honest for y in r):
            accepted += 1
            continue
        x = next((y for y in r if y in claimed), None)  # @line L7
        if x is not None and any(suspect in reg[(p, x)] for p in adj[x]):  # @line L8
            accepted += 1
    return 2 * accepted >= len(adj[v])  # @line L9


def own_routes(adj: Adj, perm: Perm, s: Node, w: int) -> list[list[Node]]:
    """The d witness lists of an honest node s, one per edge. Cost: O(d^2 w)."""
    return [route(adj, perm, s, j, w) for j in range(len(adj[s]))]
test_sybilguard.py 141 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sybilguard/. The authors are listed in prov/QFN0T8.jsonl.

import random

from sybilguard import own_routes, registries, route, routing_tables, verify

# The worked example: honest A..F, Sybil X, Y, Z, one attack edge F-X.
EDGES = ["AB", "AC", "BC", "BD", "CE", "DE", "DF", "EF", "FX", "XY", "XZ", "YZ"]
HONEST = set("ABCDEF")


def build(edges) -> dict:
    adj: dict = {}
    for a, b in edges:
        adj.setdefault(a, []).append(b)
        adj.setdefault(b, []).append(a)
    return {v: sorted(n) for v, n in sorted(adj.items())}


def test_example() -> None:
    adj = build(EDGES)
    perm = routing_tables(adj, random.Random(4))
    assert [adj["F"][perm["F"][i]] for i in range(3)] == ["X", "E", "D"]  # from D, E, X
    w = 3
    reg = registries(adj, perm, w, HONEST, {("X", "F"): ["X", "Y", "Z"]})
    assert reg[("X", "F")] == ["X", "Y", "Z"]
    assert reg[("F", "D")] == ["F", "X", "Y"]
    assert reg[("D", "E")] == ["D", "F", "X"]
    polluted = sum(1 for t in reg.values() for e in t if e not in HONEST)
    assert polluted == 3 + 2 + 1
    assert {e for t in reg.values() for e in t} - HONEST == {"X", "Y", "Z"}  # g * w = 3 names
    assert own_routes(adj, perm, "A", w) == [["B", "D", "F"], ["C", "A", "B"]]
    assert own_routes(adj, perm, "E", w) == [["C", "E", "D"], ["D", "B", "C"], ["F", "E", "C"]]
    assert verify(adj, perm, w, reg, "A", "E", own_routes(adj, perm, "E", w), HONEST)
    assert verify(adj, perm, w, reg, "A", "Z", [["F"]], HONEST)  # one route of two accepts
    assert not verify(adj, perm, w, reg, "A", "Z", [sorted(HONEST)], HONEST)
    assert not verify(adj, perm, w, reg, "A", "W", [["F"]], HONEST)  # W is in no registry


def test_edge_cases() -> None:
    adj = build(["AB"])
    perm = routing_tables(adj, random.Random(0))
    assert route(adj, perm, "A", 0, 4) == ["B", "A", "B", "A"]
    reg = registries(adj, perm, 1)
    assert reg == {("A", "B"): ["A"], ("B", "A"): ["B"]}
    # With w = 1 the routes A->B and B->A share no node, so A rejects its only friend.
    assert not verify(adj, perm, 1, reg, "A", "B", own_routes(adj, perm, "B", 1))
    reg = registries(adj, perm, 2)
    assert reg == {("A", "B"): ["A", "B"], ("B", "A"): ["B", "A"]}
    assert verify(adj, perm, 2, reg, "A", "B", own_routes(adj, perm, "B", 2))
    assert not verify(adj, perm, 2, reg, "A", "C", [["B"]])
    # A route on a triangle with the identity table goes round and round.
    adj = build(["AB", "BC", "CA"])
    perm = {"A": [1, 0], "B": [1, 0], "C": [1, 0]}
    assert route(adj, perm, "A", 0, 4) == ["B", "C", "A", "B"]


def random_graph(rng: random.Random, n: int, lo: int = 0, extra: int = 2) -> list[tuple[int, int]]:
    edges = {(lo + v, lo + rng.randrange(v)) for v in range(1, n)}
    for _ in range(extra * n):
        a, b = rng.randrange(n), rng.randrange(n)
        if a != b:
            edges.add((lo + max(a, b), lo + min(a, b)))
    return sorted(edges)


def test_back_traceable() -> None:
    """Every slot (directed edge, hop) is used by exactly one honest route, and the registries match it."""
    rng = random.Random(2006)
    for _ in range(500):
        n = rng.randrange(2, 12)
        adj = build(random_graph(rng, n))
        perm = routing_tables(adj, rng)
        w = rng.randrange(1, 7)
        owner: dict = {}
        for s in adj:
            for j in range(len(adj[s])):
                nodes = [s] + route(adj, perm, s, j, w)
                hops = list(zip(nodes, nodes[1:]))
                for i, e in enumerate(hops):
                    assert (e, i) not in owner
                    owner[(e, i)] = s
                first_repeat = next((i for i, e in enumerate(hops) if e in hops[:i]), None)
                if first_repeat is not None:  # a loop closes only on the first edge
                    assert hops[first_repeat] == hops[0]
        assert len(owner) == w * sum(len(a) for a in adj.values())
        reg = registries(adj, perm, w)
        for (p, x), table in reg.items():
            assert table == [owner[((p, x), i)] for i in range(w)]


def two_regions(rng: random.Random, nh: int, ns: int, g: int) -> tuple[dict, set, list]:
    edges = random_graph(rng, nh) + random_graph(rng, ns, nh)
    attack: set = set()
    while len(attack) < g:
        attack.add((rng.randrange(nh), nh + rng.randrange(ns)))
    return build(edges + sorted(attack)), set(range(nh)), sorted(attack)


def test_sybil_bound() -> None:
    """Whatever the adversary sends, at most g * w Sybil names reach honest registries,
    and a verifier with fewer than half of its routes escaping accepts no other Sybil name."""
    rng = random.Random(2008)
    for _ in range(100):
        nh, ns, g = rng.randrange(4, 16), rng.randrange(2, 8), rng.randrange(1, 4)
        adj, honest, attack = two_regions(rng, nh, ns, g)
        perm = routing_tables(adj, rng)
        w = rng.randrange(1, 6)
        names = [("sybil", i) for i in range(4 * w * g + 4)]
        forged = {(s, h): rng.sample(names, rng.randrange(0, 2 * w)) for h, s in attack}
        reg = registries(adj, perm, w, honest, forged)
        seen = {e for t in reg.values() for e in t if e not in honest}
        assert len(seen) <= g * w
        assert seen <= {e for t in forged.values() for e in t[:w]}
        for v in honest:
            routes = own_routes(adj, perm, v, w)
            if 2 * sum(any(y not in honest for y in r) for r in routes) >= len(routes):
                continue
            for name in rng.sample(names, 6):
                claims = [[[x]] for x in adj] + [[list(adj)]]
                if any(verify(adj, perm, w, reg, v, name, c, honest) for c in claims):
                    assert name in seen


def test_honest_acceptance_measurement() -> None:
    """On random honest graphs of 60 nodes most honest pairs accept each other (a measurement)."""
    rng = random.Random(267)
    ok = total = 0
    for _ in range(3):
        adj = build(random_graph(rng, 60, extra=2))
        perm = routing_tables(adj, rng)
        w = 16
        reg = registries(adj, perm, w)
        routes = {s: own_routes(adj, perm, s, w) for s in adj}
        for v in adj:
            for s in rng.sample(sorted(adj), 10):
                if s != v:
                    ok += verify(adj, perm, w, reg, v, s, routes[s])
                    total += 1
    assert ok / total > 0.8

History

Douceur showed in 2002 that without a trusted authority a system cannot prevent Sybil identities under his resource model, the Sybil impossibility theorem. Yu, Kaminsky, Gibbons and Flaxman, at Intel Research Pittsburgh and Carnegie Mellon University, presented SybilGuard at SIGCOMM 2006 in Pisa. They added the trust of a social network to the model and tested the protocol on a synthetic social network with one million nodes, where they used ww of about 2000. SybilLimit (2008) improved the bound by a factor of about n\sqrt{n}, and later work such as SybilRank (2012) moved the idea to fake-account detection by operators.

References

  1. Haifeng Yu, Michael Kaminsky, Phillip B. Gibbons and Abraham Flaxman, SybilGuard: defending against Sybil attacks via social networks, ACM SIGCOMM 2006, pages 267 to 278, Section 2 (the guarantees on the number and size of Sybil groups), Section 3 (overview, convergence and back-traceability), Sections 4.3 to 4.5 (random routes, redundancy, registry tables, witness tables and verification), Sections 4.6 and 4.7 (Theorem 1 and the route length), Section 5.2 (incremental routing tables)
  2. Haifeng Yu, Phillip B. Gibbons, Michael Kaminsky and Feng Xiao, SybilLimit: a near-optimal social network defense against Sybil attacks, IEEE Symposium on Security and Privacy 2008, pages 3 to 17, doi:10.1109/SP.2008.13, the abstract and the conclusion (O(log n) Sybil nodes per attack edge, against O(sqrt(n) log n) for SybilGuard)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • at least three sources
  • a scene preset for the example