Algorithmresearch
SybilRank
Also called early-terminated trust propagation.
Ranks accounts by a short power iteration of trust from known honest seeds, which stays mostly inside the honest region.
- Time
- O((n + m) log n) worst · average · best
- Space
- O(n) extra
- Where
- m = the number of friendship edges; n = the number of accounts; w = the number of iterations
- Model
- Word RAM
- Properties
- deterministicparallelranking not classification
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Qiang Cao, Michael Sirivianos, Xiaowei Yang, Tiago Pregueiro, 2012
SybilRank ranks the accounts of a social network by how likely they are to be fake. It puts trust on a few accounts known to be honest, the seeds, and spreads it along friendships by power iteration for only about steps. Because fake accounts, the Sybil identities, have few friendships with honest users, little trust reaches them in so few steps, and ranking accounts by trust divided by degree puts most of them at the bottom. Cao, Sirivianos, Yang and Pregueiro designed it for the operators of large networks, who then check the lowest-ranked accounts.
In plain words
Pour water on a few people you trust in a crowd. Each round, everyone passes their water equally to their friends. Real people have many friends among each other, so the water spreads quickly through them. Fake accounts are friends mostly with other fake accounts and have only a few links to real people, so the water reaches them slowly.
Stop pouring after a few rounds, before the water has spread evenly everywhere. Then measure how much water each person holds per friend. The people with the least are most likely fake. If you wait too long, the water evens out across the whole crowd and the test no longer tells anything.
The problem
Input. An undirected social graph with nodes and edges, every node of degree at least 1; a nonempty set of trust seeds known to be honest; a total trust ; and a number of iterations .
Model (Cao et al., Section 3). The nodes split into honest nodes and Sybil nodes. The honest region, the subgraph on , is connected, not bipartite, and fast mixing: a random walk in it reaches its stationary distribution in steps. The attacker can create any number of Sybil nodes and any edges among them, but only attack edges between Sybil and honest nodes, attached to random honest nodes.
Output. A ranking of from most suspect to least suspect.
The algorithm
SYBILRANK(G, S, T_G, w)- 1
for each node v: T(v) ← T_G / |S| if v is in S, else 0 - 2
repeat w times - 3
T'(v) ← 0 for each node v - 4
for each node u and each neighbor v of u: T'(v) ← T'(v) + T(u) / deg(u) - 5
T ← T' - 6
for each node v: R(v) ← T(v) / deg(v) - 7
return the nodes sorted by R, lowest first (ties by name)
Line L4 is one step of the random walk on , applied to the vector of trust: every node splits its trust evenly among its neighbors. The total stays the same. Cao et al. use ; the code uses . Line L6 divides by the degree because, after many steps, trust is proportional to degree, so trust per degree is the quantity that is equal everywhere at the stationary state and lower on nodes that the walk has not reached yet.
Example
The graph of Figure 4 of Cao et al. has honest nodes to and Sybil nodes to , with edges -, -, -, -, -, -, -, -, -, -, - and -. The only attack edge is -. The seeds are and , with .
| iteration | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 324 | 324 | 0 | 0 | 0 | 0 | 0 |
| 1 | 108 | 108 | 162 | 108 | 162 | 0 | 0 | 0 | 0 |
| 2 | 90 | 162 | 144 | 108 | 90 | 54 | 0 | 0 | 0 |
| 3 | 102 | 123 | 153 | 78 | 126 | 30 | 18 | 18 | 0 |
| 4 | 92 | 144 | 131 | 93 | 90 | 54 | 16 | 16 | 12 |
| degree | 2 | 3 | 3 | 2 | 3 | 3 | 3 | 3 | 2 |
| after 4 | 46 | 48 | 43.67 | 46.5 | 30 | 18 | 5.33 | 5.33 | 6 |
The ranking, lowest first, is : all four Sybils come before all five honest nodes. With 50 iterations instead of 4, the trust per degree is between 26.79 and 27.19 for every node, close to the stationary value , and the ranking says almost nothing.
Correctness
Theorem (what is computed). After line L5 has run times, , where is a uniform random seed and is the simple random walk on . The total trust is at every step. If is connected and not bipartite, as , so for every .
Lemma (escape bound). For any , the total trust on Sybil nodes after iterations is at most the sum, over , of over the attack edges with honest. This holds for every placement of Sybil nodes and edges, since trust enters the Sybil region only along attack edges. If, in addition, every honest node holds at most trust per degree at each step, the Sybil region holds at most trust after steps.
The proofs are in proofs/correctness.md.
Guarantee and its adversary (Cao et al., security analysis; theorem, not proved here). Under the model above, with the attacker placing attack edges at random honest nodes and , the number of Sybil nodes ranked above (as less suspect than) honest nodes is , however many Sybils the attacker creates. Against an attacker who places attack edges close to the seeds, the bound does not apply; Cao et al. study that case by experiment and recommend spreading many seeds.
Proof: Correctness of SybilRankfull
Let be an undirected graph with nodes and edges, every node of degree at least 1. Let be a nonempty set of seeds and . Write for the vector after line L5 of the algorithm has run times, and for the vector set by line L1. Let be the transition matrix of the simple random walk on : if , and otherwise.
Lemma 1 (one step). For and every node ,
Proof. Line L3 sets . Line L4 visits each node once and, for each neighbor of , adds to . So receives exactly one term for each neighbor of . Line L5 sets . The second form follows from the definition of .
Lemma 2 (conservation). for every .
Proof. For , line L1 puts on each of the seeds. For , by Lemma 1,
since each row of sums to 1, because has neighbors and gives to each. Induction on completes the proof.
Theorem 1 (what is computed). Let be uniform on and let be the simple random walk on . Then for every and every .
Proof. By induction on . For , for and otherwise, which matches line L1 after multiplication by . For , by the Markov property, . By the induction hypothesis and Lemma 1, .
Corollary (limit, cited fact). If is connected and not bipartite, the walk is irreducible and aperiodic, and its unique stationary distribution is , since . By the convergence theorem for finite irreducible aperiodic Markov chains, for every start. So , and the score of line L6 tends to for every . Only the convergence theorem is cited; the stationarity check is the computation above.
Lemma 3 (escape bound). Let be the honest nodes, the Sybil nodes, and the set of attack edges with and . If , then for every ,
The bound holds for every graph on and every choice of , so it holds against an attacker who controls all Sybil nodes and their edges.
Proof. Let . Since , . Fix . By Lemma 1, each node sends along each of its edge ends, and is the sum of what arrives at . Split the trust that arrives in by the sender. A Sybil sender sends at most in total, so all Sybil senders together deliver at most to . An honest sender delivers to only along its attack edges, on each. Hence
Summing this inequality from to and using gives the claim.
Corollary (per-step cap). If for every honest node that has an attack edge and every , then . This is the form used by Cao et al.: in a fast-mixing honest region, is close to after a few steps, so the Sybil region gains about per step and after steps, however many Sybil nodes there are. The step from "close to" to a bound on the ranking is the security analysis of Cao et al. and is not proved here.
Theorem 2 (the output). Line L7 returns the nodes of , each exactly once, in nondecreasing order of , with ties broken by the string form of the node.
Proof. Line L6 defines for every ; the division is defined because . Line L7 sorts the list of all nodes by the key , and a sort returns a permutation of its input in nondecreasing key order.
Cost. Lines L3 and L5 take per iteration, and line L4 takes for each , so per iteration in total. Line L1 and line L6 take , and line L7 takes comparisons. With iterations the time is , which is for . Two vectors of values are kept, so the extra space is .
Complexity
In the word RAM model, with trust as floating-point words:
- Time. Each iteration of lines L3 to L5 touches each node and each edge end once: . With iterations the total is , and sorting in line L7 adds .
- Space. Two vectors of values, extra.
- Parallelism. Each iteration is a sparse matrix-vector product, which splits over machines; Cao et al. ran it on a cluster for the graph of Tuenti, with about 11 million users.
Properties
- A ranking, not a verdict. The output tells operators which accounts to inspect first; no threshold is part of the algorithm.
- No jumps. Unlike PageRank and TrustRank, the walk never jumps to random nodes or back to the seeds: random jumps would give Sybils trust in each step, and jumps to the seeds would favor Sybils attached near them.
- Many seeds. Trust is split over many seeds, so a wrong seed puts only a small share of the trust in the Sybil region.
- Deterministic. The same graph and seeds always give the same ranking.
Variants and improvements
- Seeds in every community. Honest users in a community with few links to the seeds receive little trust and look like Sybils. Cao et al. (Section 4.2.2) find communities with the Louvain method and seed a few verified accounts in each.
- Random-route defenses. SybilGuard and SybilLimit accept or reject single nodes with random routes under the same model of attack edges and fast mixing. SybilRank replaces many random walks by one deterministic power iteration, which is cheaper on large graphs.
- Personalized PageRank and TrustRank. These run personalized PageRank to convergence with jumps back to the seeds; SybilRank stops early and has no jumps.
- Community detection. Viswanath et al. (SIGCOMM 2010) showed that social Sybil defenses effectively rank nodes by how well connected they are to the trusted node, which links them to community detection.
When to use it
Use SybilRank when an operator holds the whole social graph, can verify a few honest seeds per community, and wants a list of accounts to inspect in order. It fits fake accounts made in bulk that have few real friends. It does not fit when attackers can obtain many real friendships, for example by taking over real accounts, or when the honest graph is made of weakly linked groups without seeds in each.
Pitfalls
- Running to convergence. If line L2 repeats until the vector stops changing, trust per degree becomes the same everywhere (the 50-iteration case of the example), and Sybils cannot be told apart. Stop after iterations in line L2.
- Ranking by raw trust. If line L6 sets , honest nodes of low degree rank as suspect and a Sybil with many edges to other Sybils can rank as trusted. Divide by the degree, as in line L6.
- Adding jumps. If line L4 also sends a fraction of trust back to the seeds or to random nodes, Sybils near the seeds or anywhere gain trust in every step. Keep line L4 a plain walk step.
- Seeds in one community. If line L1 seeds only one community, honest communities far from it end up at the bottom of the ranking. Spread the seeds over the communities.
- Nodes without friends. A node of degree 0 makes line L4 and line L6 divide by zero. Remove such nodes first, or treat them separately.
Implementations
The code runs on small synthetic graphs of at most 60 nodes. The tests reproduce Figure 4 exactly, compare the power iteration with an exact dense-matrix computation in fractions on 500 random graphs, check the escape bound, and measure the ranking on graphs with two regions and 2 attack edges: in 40 graphs with 30 honest and 30 Sybil nodes, all 1200 Sybils fell in the bottom 30 places (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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sybilrank/. The authors are listed in prov/S4HXC8.jsonl.
"""SybilRank (Cao, Sirivianos, Yang and Pregueiro, NSDI 2012, Section 4).
Early-terminated power iteration of trust from honest seeds on an undirected
social graph, then a ranking by degree-normalized trust. The graph is an
adjacency dict of a small synthetic graph; no real account data is used.
"""
from math import ceil, log2
from typing import Hashable, Mapping, Sequence
Node = Hashable
def default_iterations(n: int) -> int:
"""w = ceil(log2 n), the O(log n) early termination of Section 4.2."""
return max(1, ceil(log2(n))) if n > 1 else 1
def propagate(adj: Mapping[Node, Sequence[Node]], seeds: Sequence[Node], total: float, w: int) -> dict[Node, float]:
"""Trust after w power iterations, starting with total split evenly on the seeds.
Precondition: every node has at least one neighbor, adj is symmetric, and
seeds is a nonempty list of distinct nodes. Cost: O(w (n + m)) time and
O(n) extra space for n nodes and m edges.
"""
share = total / len(seeds)
seed_set = set(seeds)
trust = {v: (share if v in seed_set else 0.0) for v in adj} # @line L1
for _ in range(w): # @line L2
nxt = {v: 0.0 for v in adj} # @line L3
for u, nbrs in adj.items(): # @line L4
give = trust[u] / len(nbrs)
for v in nbrs:
nxt[v] += give
trust = nxt # @line L5
return trust
def rank(adj: Mapping[Node, Sequence[Node]], trust: Mapping[Node, float]) -> list[Node]:
"""Nodes ordered by degree-normalized trust, lowest (most suspect) first.
Ties are broken by the string form of the node, so the order is
deterministic. Cost: O(n log n).
"""
score = {v: trust[v] / len(adj[v]) for v in adj} # @line L6
return sorted(adj, key=lambda v: (score[v], str(v))) # @line L7
def sybilrank(adj: Mapping[Node, Sequence[Node]], seeds: Sequence[Node], total: float = 1.0, w: int | None = None) -> list[Node]:
"""Propagate trust from the seeds for w iterations (default ceil(log2 n)) and rank."""
if w is None:
w = default_iterations(len(adj))
return rank(adj, propagate(adj, seeds, total, w))
test_sybilrank.py 139 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sybilrank/. The authors are listed in prov/S4HXC8.jsonl.
import random
from fractions import Fraction
from sybilrank import default_iterations, propagate, rank, sybilrank
# The graph of Figure 4 of Cao et al.: A..E are honest, F..I are Sybils, E-F is the attack edge.
EDGES = ["AB", "AC", "BC", "BE", "CD", "DE", "EF", "FG", "FH", "GH", "GI", "HI"]
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 adj.items()}
def oracle(adj: dict, seeds: list, total: Fraction, w: int) -> dict:
"""Exact trust by w products with the dense transition matrix, in fractions."""
nodes = sorted(adj, key=str)
idx = {v: i for i, v in enumerate(nodes)}
n = len(nodes)
p = [[Fraction(0)] * n for _ in range(n)] # p[i][j]: from i to j
for u in nodes:
for v in adj[u]:
p[idx[u]][idx[v]] += Fraction(1, len(adj[u]))
x = [total / len(seeds) if v in seeds else Fraction(0) for v in nodes]
for _ in range(w):
x = [sum(x[i] * p[i][j] for i in range(n)) for j in range(n)]
return {v: x[idx[v]] for v in nodes}
def test_example() -> None:
adj = build(EDGES)
t = propagate(adj, ["C", "D"], 648.0, 4)
want = {"A": 92, "B": 144, "C": 131, "D": 93, "E": 90, "F": 54, "G": 16, "H": 16, "I": 12}
for v, x in want.items():
assert abs(t[v] - x) < 1e-9
assert oracle(adj, ["C", "D"], Fraction(648), 4) == {v: Fraction(x) for v, x in want.items()}
order = rank(adj, t)
assert order[:4] == ["G", "H", "I", "F"] # every Sybil is below every honest node
assert set(order[4:]) == set("ABCDE")
# After many iterations the trust is proportional to degree: 27 per edge end.
t = propagate(adj, ["C", "D"], 648.0, 200)
for v in adj:
assert abs(t[v] - 27 * len(adj[v])) < 1e-6
def test_edges() -> None:
adj = build(["AB"])
assert propagate(adj, ["A"], 1.0, 0) == {"A": 1.0, "B": 0.0}
assert propagate(adj, ["A"], 1.0, 1) == {"A": 0.0, "B": 1.0}
assert rank(adj, {"A": 0.5, "B": 0.5}) == ["A", "B"] # ties by name
assert default_iterations(1) == 1 and default_iterations(2) == 1
assert default_iterations(9) == 4 and default_iterations(1024) == 10
assert sybilrank(build(EDGES), ["C", "D"])[:4] == ["G", "H", "I", "F"]
def random_graph(rng: random.Random, n: int) -> dict:
adj = {v: set() for v in range(n)}
for v in range(1, n):
u = rng.randrange(v)
adj[u].add(v)
adj[v].add(u)
for _ in range(rng.randrange(0, 2 * n)):
a, b = rng.randrange(n), rng.randrange(n)
if a != b:
adj[a].add(b)
adj[b].add(a)
return {v: sorted(s) for v, s in adj.items()}
def test_random_against_oracle() -> None:
"""Floating power iteration agrees with the exact matrix oracle and keeps the total."""
rng = random.Random(2012)
for _ in range(500):
n = rng.randrange(2, 13)
adj = random_graph(rng, n)
seeds = rng.sample(range(n), rng.randrange(1, n + 1))
w = rng.randrange(0, 6)
got = propagate(adj, seeds, 1.0, w)
want = oracle(adj, seeds, Fraction(1), w)
assert sum(want.values()) == 1
for v in adj:
assert abs(got[v] - float(want[v])) < 1e-12
def two_regions(rng: random.Random, nh: int, ns: int, g: int, extra: int) -> tuple[dict, set]:
"""An honest region and a Sybil region, each a random connected graph, joined by g attack edges."""
adj = {v: set() for v in range(nh + ns)}
def add(a: int, b: int) -> None:
if a != b:
adj[a].add(b)
adj[b].add(a)
for lo, size in ((0, nh), (nh, ns)):
for v in range(1, size):
add(lo + v, lo + rng.randrange(v))
for _ in range(extra * size):
add(lo + rng.randrange(size), lo + rng.randrange(size))
attack = set()
while len(attack) < g:
e = (rng.randrange(nh), nh + rng.randrange(ns))
attack.add(e)
add(*e)
return {v: sorted(s) for v, s in adj.items()}, attack
def test_escape_bound() -> None:
"""Trust in the Sybil region after w steps is at most the sum, over steps, of the flow on attack edges."""
rng = random.Random(197)
for _ in range(200):
nh, ns = rng.randrange(5, 31), rng.randrange(2, 31)
adj, attack = two_regions(rng, nh, ns, rng.randrange(1, 4), 2)
seeds = rng.sample(range(nh), rng.randrange(1, 4))
w = default_iterations(nh + ns)
flow = 0.0
for i in range(w):
t = propagate(adj, seeds, 1.0, i)
flow += sum(t[u] / len(adj[u]) for u, _ in attack)
t = propagate(adj, seeds, 1.0, w)
assert sum(t[v] for v in range(nh, nh + ns)) <= flow + 1e-12
def test_ranking_measurement() -> None:
"""With few attack edges most Sybils fall in the bottom of the ranking (a measurement, not a bound)."""
rng = random.Random(210)
caught = total = 0
for _ in range(40):
nh, ns = 30, 30
adj, _ = two_regions(rng, nh, ns, 2, 3)
order = sybilrank(adj, rng.sample(range(nh), 3))
caught += sum(1 for v in order[:ns] if v >= nh)
total += ns
assert caught / total > 0.8
History
Yu, Kaminsky, Gibbons and Flaxman introduced social-network Sybil defenses with SybilGuard in 2006, followed by SybilLimit in 2008. Viswanath, Post, Gummadi and Mislove analyzed these defenses in 2010. Cao, Sirivianos, Yang and Pregueiro presented SybilRank at NSDI 2012, replacing random routes by early-terminated power iteration, and reported that at Tuenti about 90% of the 200,000 lowest-ranked accounts were fake (measurement).
References
- Qiang Cao, Michael Sirivianos, Xiaowei Yang and Tiago Pregueiro, Aiding the detection of fake accounts in large scale social online services, USENIX NSDI 2012, pages 197 to 210, Section 3 (the model and assumptions), Section 4.2 (trust propagation, early termination and Figure 4), Section 4.2.2 (seeds in several communities with the Louvain method), the security analysis, and the evaluation and the deployment at Tuenti
- 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 social network model with g attack edges and a fast-mixing honest region
- Bimal Viswanath, Ansley Post, Krishna P. Gummadi and Alan Mislove, An analysis of social network-based Sybil defenses, ACM SIGCOMM 2010, the analysis of social Sybil defenses as ranking by connectivity to trusted nodes
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag S4HXC8 Edit this page History Report an error Markdown