5D Library › 跨境支付智能路由、拒付抗辩博弈与资金池破产边界 · English

第四章 加密证据链与「抗辩还是预警」

让日志无法事后改写

证据包要有说服力,日志本身必须可信:银行或仲裁方会问,这份下载记录是不是事后补写的。哈希链是一种简单的防篡改结构:每一条事件的哈希值都包含前一条的哈希值,所以改动任何一条过去的事件,之后的每一个链接都会断开 (Haber and Stornetta 1991)。身份字段(IP、设备编号、邮箱)则以带密钥的哈希(HMAC)保存,既能在两笔交易之间比对是否相同,又不必保留原始值,这也符合个人资料保护法对最少保存的要求 (Parliament of Malaysia 2010)。

推导

# Chapter 4. p07: A tamper-evident evidence log. Each event (order, terms
# ticked, payment, report exported, download) is chained: its hash covers
# the previous hash, so changing any past event breaks every later link.
# Identity fields are stored as keyed hashes (HMAC-SHA256 with a secret
# key), so two purchases can be matched on IP or device without keeping
# the raw values. A hash chain proves the log was not changed after it
# was written; it does not prove that what was written is true.
import hashlib
import hmac
import json

KEY = b"demo-key-not-for-production"

def ident(value):
    return hmac.new(KEY, value.encode(), hashlib.sha256).hexdigest()[:16]

def chain(events):
    prev, out = "0" * 64, []
    for e in events:
        body = json.dumps(e, sort_keys=True)
        h = hashlib.sha256((prev + body).encode()).hexdigest()
        out.append((e, prev, h))
        prev = h
    return out

def verify(rows):
    prev = "0" * 64
    for i, (e, p, h) in enumerate(rows):
        body = json.dumps(e, sort_keys=True)
        if p != prev or hashlib.sha256((p + body).encode()).hexdigest() != h:
            return i
        prev = h
    return None

if __name__ == "__main__":
    dev = ident("device:7f3a-demo")
    ev = [{"t": "2026-03-01T10:00:05Z", "e": "order", "id": "A1001",
           "ip": ident("203.0.113.7"), "dev": dev},
          {"t": "2026-03-01T10:00:41Z", "e": "terms ticked", "v": "v3.2"},
          {"t": "2026-03-01T10:01:02Z", "e": "paid", "rm": 150},
          {"t": "2026-03-01T10:01:30Z", "e": "report exported"},
          {"t": "2026-03-01T10:02:11Z", "e": "downloaded", "dev": dev}]
    rows = chain(ev)
    for e, p, h in rows:
        print("   {:<16} {}".format(e["e"], h[:16]))
    print("   verify untouched log: {}".format(
        "OK" if verify(rows) is None else "broken"))
    rows[3][0]["e"] = "export failed"
    print("   after editing event 4: first broken link at event {}"
          .format(verify(rows) + 1))
    old = ident("device:7f3a-demo")
    print("   same device as a purchase 200 days ago: {}".format(old == dev))
#    order            68467c2b806f7d7e
#    terms ticked     262e7265e46052ad
#    paid             b2efb3683ca492d8
#    report exported  7c454867d4470cfd
#    downloaded       00df7c23badbfc66
#    verify untouched log: OK
#    after editing event 4: first broken link at event 4
#    same device as a purchase 200 days ago: True

五条事件(下单、勾选条款、付款、报告导出、下载)依次成链,验证通过。把第 4 条改成「导出失败」,验证在第 4 条就发现链接断开。设备编号的带密钥哈希与 200 天前一笔交易的相同,可以作为强有力证据 3.0 所需的匹配(见第三章 p06),而系统里不必存放设备编号本身。

注

哈希链证明的是「写入之后没有被改」,不是「写入的内容是真的」。 如果日志在写入时就是错的,哈希链只会忠实地保存这个错误。要让外人也能相信写入的时间,可以每天把链头的哈希值交给第三方存证或公开发布。

抗辩、认赔,还是在争议之前拦下

抗辩一笔金额为 AA 的争议,胜诉概率 ww、准备成本 cc,期望价值是 wA−cwA – c,所以金额高于 c/wc/w 才值得抗辩。但有一点常被忽略:赢下的争议仍然计入监控比率。按 VAMP 的规则,经由争议前预警服务(如 Visa 的快速争议解决 RDR 与 CDRN)以退款解决、没有成为争议的个案,不计入比率 (Visa 2025)。

推导

# Chapter 4. p08: Fight, accept, or stop the dispute before it starts.
# Fighting a dispute of amount A with win probability w and preparation
# cost c is worth w * A - c, so fight when A > c / w. But a dispute that
# is won still COUNTS in the monitored ratio; under Visa VAMP, disputes
# resolved through pre-dispute alert services (Rapid Dispute Resolution,
# CDRN), by refunding before they become disputes, are left out. Per
# month: 10,800 card sales, 0.60% of them disputed, ticket RM 150; an
# alert service costs RM 25 an alert and catches a share of disputes.
CARD, RATE, TICKET = 10800, 0.006, 150.0

def threshold(c, w):
    return c / w

if __name__ == "__main__":
    print("   prep cost  win prob  fight disputes above RM")
    for c in (15.0, 60.0):
        for w in (0.35, 0.6, 0.95):
            print("   {:9.0f}  {:8.2f}  {:23.0f}".format(c, w,
                                                        threshold(c, w)))
    d = CARD * RATE
    print("   disputes a month: {:.1f}; ratio {:.2%}".format(d, d / CARD))
    for caught in (0.0, 0.3, 0.6):
        left = d * (1 - caught)
        cost = d * caught * (TICKET + 25)
        print("   alerts catch {:.0%}: counted {:.1f}, ratio {:.2%},"
              " alert refunds+fees RM {:,.0f}".format(
                  caught, left, left / CARD, cost))
#    prep cost  win prob  fight disputes above RM
#           15      0.35                       43
#           15      0.60                       25
#           15      0.95                       16
#           60      0.35                      171
#           60      0.60                      100
#           60      0.95                       63
#    disputes a month: 64.8; ratio 0.60%
#    alerts catch 0%: counted 64.8, ratio 0.60%, alert refunds+fees RM 0
#    alerts catch 30%: counted 45.4, ratio 0.42%, alert refunds+fees RM 3,402
#    alerts catch 60%: counted 25.9, ratio 0.24%, alert refunds+fees RM 6,804

准备成本 RM 15、胜诉概率 0.60 时,金额高于 RM 25 的争议值得抗辩;人工准备成本 RM 60、胜诉概率 0.35 时,门槛升到 RM 171。在每月 10,800 笔卡交易、争议率 0.60% 的示意商户中,每月有 64.8 笔争议;预警服务拦下 30% 时,计入比率的降到 45.4 笔,比率 0.42%,预警退款与服务费每月 RM 3,402;拦下 60% 时比率降到 0.24%,每月 RM 6,804。

假说 · 尚未验证

作者的假说(尚未验证): 对每月卡交易少于两万笔的数字产品商户,接入争议前预警服务并对预警一律退款,比只对争议抗辩,十二个月内被收单机构冻结或提高保证金的次数更少。什么会证明它错: 在多家商户的对比中,两种做法的冻结与加保次数没有差别。

小结

哈希链让证据日志无法事后改写,带密钥的身份哈希让交易可以比对而不必保存原始资料;但它们证明的是完整性,不是真实性。抗辩可以拿回钱,却不会降低监控比率;能降低比率的是快速退款与争议前预警。

参考文献

Haber, Stuart, and W. Scott Stornetta. 1991. “How to Time-Stamp a Digital Document.” Journal of Cryptology 3 (2): 99–111.
Parliament of Malaysia. 2010. Personal Data Protection Act 2010 (Act 709). Laws of Malaysia.
Visa. 2025. Visa Acquirer Monitoring Program (VAMP): Program Overview and Merchant Thresholds. Visa Inc.

Fan, Y. (2026). Cross-Border Payment Routing, Chargeback Defense Games and Treasury Ruin Bounds: Multi-Acquirer Success Optimization, Dispute Evidence Scoring and Cramér-Lundberg Cash Reserves [跨境支付智能路由、拒付抗辩博弈与资金池破产边界] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090225 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).