5D Library › Zero-Touch Multi-Site Fault Tolerance, Payment Anti-Fraud State Machines and Passive Cashflow Queuing · 中文
Chapter 2. Self-Referral and “Invite Friends to Unlock”
One person, many accounts
An affiliate programme pays commission per referral; an invitation programme unlocks content per invitee. Both assume one account per person. Once one person can open many accounts and refer himself, commissions and unlocks flow back to him. In distributed systems this is called a Sybil attack: one entity posing as many identities (Douceur 2002). Douceur’s conclusion is that without a central identity authority, Sybil attacks cannot be ruled out in principle; one can only raise the cost of fake identities or find them through the links between accounts.
An association graph and union-find
The program simulates the problem with 5,000 honest accounts and 40 cheating rings of 3 to 8 accounts each. Every account has a device fingerprint, a payment account and an IP subnet. Among honest accounts 6% share a device with a family member and 10% share a payment account; most mobile users sit behind carrier-grade NAT, so subnets are drawn from 300 address blocks with Zipf weights, and strangers often share one. A ring shares one device with probability 0.6, one payment account with 0.7 and one subnet with 0.9; a further 0.2 of rings are “careful” and share nothing.
Accounts that share an attribute are joined, connected components are found with union-find (Tarjan 1975), and a commission is blocked when referrer and referee fall in the same component.
Calculation
# Chapter 2. [p03] Blocking self-referral with an association graph.
# 5,000 honest users and 40 fraud rings of 3-8 accounts. Every account
# has a device fingerprint, a payment account and an IP /24 subnet.
# Honest: 6% share a device with a family member, 10% share a payment
# account; subnets come from 300 mobile carrier-NAT blocks (Zipf
# weights), so strangers often share one. Rings: members share one
# device with chance 0.6, one payment account with chance 0.7, one
# subnet with chance 0.9; a careful ring (chance 0.2) shares nothing.
# Honest users make 3,000 referrals (30% within the family); each ring
# leader refers all members. Union-find joins accounts linked by the
# chosen edge types; a referral is blocked when both ends share a
# component. Reported: rings' referrals blocked, honest ones blocked
# (all, and to strangers only), and the largest component.
import random
class DSU:
def __init__(self, n):
self.p = list(range(n))
def find(self, x):
while self.p[x] != x:
self.p[x] = self.p[self.p[x]]
x = self.p[x]
return x
def union(self, a, b):
self.p[self.find(a)] = self.find(b)
def world(rng):
acc, fam = [], []
w = [1 / (i + 1) for i in range(300)]
for i in range(5000):
acc.append({"dev": ("d", i), "pay": ("p", i),
"net": ("n", rng.choices(range(300), w)[0])})
fam.append(i)
for i in range(0, 5000, 2):
if rng.random() < 0.06:
acc[i + 1]["dev"] = acc[i]["dev"]
if rng.random() < 0.10:
acc[i + 1]["pay"] = acc[i]["pay"]
fam[i + 1] = i
rings = []
for r in range(40):
size = rng.randint(3, 8)
careful = rng.random() < 0.2
base = len(acc)
net = ("n", rng.choices(range(300), w)[0])
for j in range(size):
a = {"dev": ("rd", r, j), "pay": ("rp", r, j),
"net": ("n", rng.choices(range(300), w)[0])}
if not careful:
if rng.random() < 0.6:
a["dev"] = ("rd", r, 0)
if rng.random() < 0.7:
a["pay"] = ("rp", r, 0)
if rng.random() < 0.9:
a["net"] = net
acc.append(a)
rings.append([(base, base + j) for j in range(1, size)])
refs = []
for _ in range(3000):
i = rng.randrange(5000)
if rng.random() < 0.3:
j = i + 1 if i % 2 == 0 else i - 1
refs.append((i, j, True))
else:
refs.append((i, rng.randrange(5000), False))
return acc, refs, [x for r in rings for x in r]
def evaluate(acc, refs, ring_refs, kinds):
d = DSU(len(acc))
first = {}
for i, a in enumerate(acc):
for k in kinds:
key = a[k]
if key in first:
d.union(i, first[key])
else:
first[key] = i
same = lambda x, y: d.find(x) == d.find(y)
caught = sum(same(a, b) for a, b in ring_refs) / len(ring_refs)
hon = sum(same(a, b) for a, b, _ in refs) / len(refs)
strangers = [(a, b) for a, b, f in refs if not f]
hs = sum(same(a, b) for a, b in strangers) / len(strangers)
sizes = {}
for i in range(len(acc)):
r = d.find(i)
sizes[r] = sizes.get(r, 0) + 1
return caught, hon, hs, max(sizes.values())
if __name__ == "__main__":
rng = random.Random(75003)
acc, refs, ring_refs = world(rng)
print(" edges rings honest honest largest")
print(" blocked blocked strangers component")
for kinds in (("dev",), ("dev", "pay"), ("dev", "pay", "net")):
c, h, hs, big = evaluate(acc, refs, ring_refs, kinds)
print(" {:18s} {:7.3f} {:7.3f} {:8.3f} {:9d}".format(
"+".join(kinds), c, h, hs, big))
print("\nReading: device and payment edges catch most rings and")
print("block only family referrals among honest users; careful")
print("rings slip through. Adding the shared-subnet edge seems to")
print("catch almost every ring, but only because it glues thousands")
print("of strangers behind carrier NAT into one component: it")
print("blocks most honest referrals between strangers too.")
# edges rings honest honest largest
# blocked blocked strangers component
# dev 0.487 0.019 0.000 8
# dev+pay 0.779 0.047 0.000 8
# dev+pay+net 0.995 0.820 0.817 4692
#
# Reading: device and payment edges catch most rings and
# block only family referrals among honest users; careful
# rings slip through. Adding the shared-subnet edge seems to
# catch almost every ring, but only because it glues thousands
# of strangers behind carrier NAT into one component: it
# blocks most honest referrals between strangers too.With device edges alone, 0.487 of ring referrals are blocked and 0.019 of honest referrals (all between family members); adding payment-account edges blocks 0.779 of ring referrals and 0.047 of honest ones, and not a single honest referral between strangers. Careful rings all slip through.
With subnet edges added, 0.995 of ring referrals are blocked, which looks almost perfect; but only because the largest component has swollen to 4692 accounts – nearly everyone is joined together. Honest referrals between strangers are blocked at 0.817. Subnet edges do not find the careful rings; they merely treat everyone as one ring.
The conclusion: device and payment account are useful association signals, subnet is not; blocked “family referrals” are a policy question (should family members earn commission from one another?), not a detection error. Careful rings need their cost raised by other means, such as the pricing of the next section.
What is “invite 3 friends to unlock level 2” worth?
Let level 1 cost 39 and level 2 list at 299; inviting friends who buy level 1 unlocks level 2 free, and the inviter also takes a 50% commission. A self-referrer opens fake accounts and buys level 1 with each (spending effort worth 3 per account), so his real price for level 2 is ; with self-referral commission blocked it is .
The firm’s incremental gain must be counted separately: a genuinely new customer brings ; an existing customer who would have come anyway makes the firm pay commission for nothing; a fake account also brings (the self-referrer pays for it). And level 2 given away loses 299 whenever the inviter would have bought it at list price (probability 0.3 for an ordinary inviter; a self-referrer plainly wants level 2, probability 0.8).
Calculation
# Chapter 2. [p04] "Invite m friends to unlock L2": who really pays?
# Level 1 costs 39; level 2 lists at 299 and is unlocked free when m
# invitees buy level 1. The inviter earns a commission g = 50% on each
# invitee's purchase. A self-referrer opens m fake accounts and buys
# level 1 with each (effort 3 per account): his price for level 2 is
# m (39 (1 - g) + 3) with the commission paid,
# m (39 + 3) when self-referral commission is blocked.
# The firm's incremental gain per unlock: a real invitee who is new
# brings 39 (1 - g); one who would have bought anyway costs the
# commission 39 g; a fake invitee brings 39 (1 - g) (the fraudster pays
# for the account). Giving level 2 away loses its list price whenever
# the inviter would have bought it: probability b = 0.3 for a typical
# inviter, 0.8 for a self-referrer, who plainly wants level 2.
L1, L2, G, EFFORT = 39.0, 299.0, 0.5, 3.0
def real(m, h, b=0.3):
return m * (h * L1 * (1 - G) - (1 - h) * L1 * G) - b * L2
def fake(m, b=0.8):
return m * L1 * (1 - G) - b * L2
if __name__ == "__main__":
print(" self-referral price of level 2 (list 299):")
print(" m commission paid commission blocked")
for m in (3, 5, 8):
print(" {:2d} {:17.2f} {:20.2f}".format(
m, m * (L1 * (1 - G) + EFFORT), m * (L1 + EFFORT)))
print(" smallest m with no discount: paid {}, blocked {}".format(
next(m for m in range(1, 50) if m * (L1 * (1 - G) + EFFORT) >= L2),
next(m for m in range(1, 50) if m * (L1 + EFFORT) >= L2)))
print(" firm's incremental gain per unlock:")
print(" m real h=0 real h=0.5 real h=1 fake (b=0.8)")
for m in (3, 5, 8):
print(" {:2d} {:10.2f} {:12.2f} {:10.2f} {:14.2f}".format(
m, real(m, 0), real(m, 0.5), real(m, 1), fake(m)))
print("\nReading: with three invitees, self-referral buys a 299")
print("level for under a quarter of its price, and even with the")
print("commission blocked it costs 126. The unlock gains money only")
print("when invitees are genuinely new and m is large; with three")
print("invitees it loses on every inviter, honest or not.")
# self-referral price of level 2 (list 299):
# m commission paid commission blocked
# 3 67.50 126.00
# 5 112.50 210.00
# 8 180.00 336.00
# smallest m with no discount: paid 14, blocked 8
# firm's incremental gain per unlock:
# m real h=0 real h=0.5 real h=1 fake (b=0.8)
# 3 -148.20 -89.70 -31.20 -180.70
# 5 -187.20 -89.70 7.80 -141.70
# 8 -245.70 -89.70 66.30 -83.20
#
# Reading: with three invitees, self-referral buys a 299
# level for under a quarter of its price, and even with the
# commission blocked it costs 126. The unlock gains money only
# when invitees are genuinely new and m is large; with three
# invitees it loses on every inviter, honest or not.With 3 invitees, the self-referrer gets a level listed at 299 for 67.50, under a quarter of the price; even with self-referral commission blocked it costs only 126.00. For self-referral to stop being cheap, must reach 14 with commission and 8 without.
From the firm’s side, at every unlock loses money whoever the invitees are: 31.20 when all are new customers, 148.20 when all are existing ones, and 180.70 for a self-referrer. Only when is large and the invitees really are new does it gain ( with all new customers gains 66.30). “Invite 3 to unlock” is less a growth device than a large discount voucher for level 2; to make it pay, must be raised and only genuinely new customers (accounts with no device or payment link to the inviter) counted.
Hypothesis · not established
The author’s interpretation (not yet tested): in the author’s business, setting the invitation threshold at 8 new paying users with no device or payment link to the inviter keeps the programme from losing money on the margin without markedly reducing genuine word-of-mouth referrals. What would show this wrong: if a pre-registered experiment showed that raising the threshold from 3 to 8 cut genuine new-customer referrals by more than half, the cost of the higher threshold would exceed the arbitrage it stops.
Summary
An association graph of devices and payment accounts blocks most cheating rings while hardly touching strangers; adding IP subnets joins thousands of strangers together and wrongly blocks 0.817 of referrals between strangers. “Invite 3 to unlock” lets a self-referrer get a 299 level for 67.50 and loses money on every unlock; the threshold must reach 8 genuinely new customers, with self-referral commission blocked, before it stops losing.
References
Fan, Y. (2026). Zero-Touch Multi-Site Fault Tolerance, Payment Anti-Fraud State Machines and Passive Cashflow Queuing: Receipt-Hash Deduplication, Self-Referral Blocking, Host-Header Routing and Availability Bounds [零人工多站点容错架构、支付防欺诈状态机与被动现金流排队论] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090201 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).