5D Library › 零人工多站点容错架构、支付防欺诈状态机与被动现金流排队论 · English

第二章 自购返佣与「邀请好友解锁」

一个人,许多账户

分销计划按推荐给佣金,邀请计划按邀请人数解锁内容。两者都假设一个账户对应一个人。一旦一个人可以开许多账户,自己推荐自己,就能把佣金和解锁拿回自己手里。在分布式系统中这被称为「女巫攻击」:一个实体伪装成许多身份 (Douceur 2002)。Douceur 的结论是,没有一个中心化的身份机构,女巫攻击无法从根本上杜绝;能做的只是提高开设假身份的成本,或者从账户之间的关联中找出它们。

关联图与并查集

程序用 5,000 个诚实账户和 40 个作弊团伙(每个 3 到 8 个账户)模拟这个问题。每个账户有设备指纹、支付账户与 IP 子网三种属性。诚实账户中有 6% 与家人共用设备、10% 共用支付账户;手机上网的用户大多处于运营商级 NAT 之后,IP 子网从 300 个地址块中按齐夫分布抽取,所以陌生人常常共用一个子网。作弊团伙以 0.6 的概率共用一台设备、0.7 的概率共用一个支付账户、0.9 的概率在同一子网;另有 0.2 的「谨慎」团伙什么都不共用。

把共用某种属性的账户连起来,用并查集求连通分量 (Tarjan 1975),推荐双方处在同一分量就拦截佣金。

推导

# 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.

只用设备边时,拦下 0.487 的团伙推荐,诚实推荐被拦 0.019(全部是家人之间);加上支付账户边,拦下 0.779,诚实推荐被拦 0.047,陌生人之间的诚实推荐一个也没拦。谨慎团伙则全部漏网。

加上子网边之后,团伙推荐被拦 0.995,看起来近乎完美;但这只是因为最大的连通分量已经膨胀到 4692 个账户——几乎所有人都连在了一起。陌生人之间的诚实推荐被拦 0.817。子网边并没有找到谨慎团伙,只是把所有人都当成了同一个团伙。

结论是:设备与支付账户是有用的关联信号,子网不是;被拦下的「家人推荐」是一个政策问题(家人之间是否应当有佣金),而不是检测失误。谨慎团伙需要用其他办法提高成本,例如下一节的定价。

「邀请 3 位好友解锁二级」值多少钱

设一级内容 39,二级标价 299,邀请 mm 位好友购买一级即可免费解锁二级,邀请人还拿 50% 的佣金。自购者开 mm 个假账户各买一次一级(每个账户另花 3 的工夫),他为二级实际付出的价钱就是 m(39×0.5+3)m(39 \times 0.5 + 3);若自购佣金被拦下,则是 m(39+3)m(39 + 3)。

企业一侧的增量收益要分开算:一位真正的新客户带来 39×0.539 \times 0.5;一位本来就会来的老客户反而让企业白付 39×0.539 \times 0.5 的佣金;一个假账户也带来 39×0.539 \times 0.5(假账户的钱是自购者付的)。而免费送出的二级,在邀请人本来就会以标价购买时(普通邀请人概率 0.3,自购者显然想要二级,概率 0.8),损失 299。

推导

# 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.

邀请 3 人时,自购者以 67.50 拿到标价 299 的二级,不到四分之一的价钱;即使拦下自购佣金,也只需 126.00。要让自购不再便宜,有佣金时 mm 要到 14,无佣金时要到 8。

从企业一侧看,m=3m = 3 时无论邀请来的是谁,每次解锁都在亏钱:全是新客户时亏 31.20,全是老客户时亏 148.20,自购者亏 180.70。只有当 mm 大、被邀请的又确实是新客户时才赚钱(m=8m = 8、全是新客户时赚 66.30)。「邀请 3 人解锁」与其说是增长手段,不如说是一张二级的大额折扣券;要让它划算,必须提高 mm,并且只把真正的新客户(与邀请人没有设备与支付关联的账户)计入人数。

假说 · 尚未验证

作者的诠释(尚未验证): 在作者的业务中,把邀请门槛定为 8 位与邀请人没有设备与支付关联的新付费用户,可以让邀请计划在增量上不亏钱,同时不明显减少真实的口碑推荐。什么会证明这一判断错:若预注册实验显示,门槛从 3 提到 8 后,真实的新客户推荐数下降超过一半,那么提高门槛的代价大于它挡住的套利。

小结

用设备与支付账户建关联图,可以拦下大部分作弊团伙而几乎不误伤陌生人;加入 IP 子网会把成千上万的陌生人连成一片,0.817 的陌生人推荐被误拦。「邀请 3 人解锁」让自购者以 67.50 拿到 299 的二级,并在每次解锁上亏钱;门槛要到 8 位真正的新客户、并且拦下自购佣金,才不吃亏。

参考文献

Douceur, John R. 2002. “The Sybil Attack.” Peer-to-Peer Systems: First International Workshop, IPTPS 2002 (Berlin), Lecture notes in computer science, vol. 2429: 251–60.
Tarjan, Robert Endre. 1975. “Efficiency of a Good but Not Linear Set Union Algorithm.” Journal of the ACM 22 (2): 215–25.

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).