5D Library › Cross-Border Payment Routing, Chargeback Defense Games and Treasury Ruin Bounds · 中文
Chapter 4. A Cryptographic Evidence Chain, and “Fight or Pre-Empt”
Logs that cannot be rewritten afterwards
For an evidence package to convince, the log itself must be credible: a bank or arbitrator will ask whether this download record was written in after the fact. A hash chain is a simple tamper-evident structure: each event’s hash covers the previous event’s hash, so changing any past event breaks every later link (Haber and Stornetta 1991). Identity fields (IP, device ID, email) are stored as keyed hashes (HMAC), which can be compared across two transactions without keeping the raw values, in line with the data-minimisation duty of personal data protection law (Parliament of Malaysia 2010).
Calculation
# 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: TrueFive events (order, terms ticked, payment, report exported, download) are chained in turn, and verification passes. Change event 4 to “export failed”, and verification finds the broken link at event 4. The keyed hash of the device ID equals that of a transaction 200 days earlier, which can serve as the match Compelling Evidence 3.0 requires (see p06 in Chapter 3), without the system ever storing the device ID itself.
Note
A hash chain proves “not changed after it was written”, not “what was written is true”. If a log was wrong when written, the chain will faithfully preserve the error. To let outsiders trust the time of writing too, the head hash can be lodged with a third party or published each day.
Fight, accept, or stop it before it becomes a dispute
Fighting a dispute of amount with win probability and preparation cost is worth in expectation, so only disputes above are worth fighting. But one point is often missed: a dispute that is won still counts in the monitored ratio. Under VAMP’s rules, cases resolved by refund through pre-dispute alert services (such as Visa’s Rapid Dispute Resolution, RDR, and CDRN), and so never becoming disputes, are left out of the ratio (Visa 2025).
Calculation
# 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,804With a preparation cost of RM 15 and a win probability of 0.60, disputes above RM 25 are worth fighting; with RM 60 of manual preparation and a win probability of 0.35, the threshold rises to RM 171. For an illustrative merchant with 10,800 card transactions a month and a dispute rate of 0.60%, there are 64.8 disputes a month; if alerts stop 30% of them, those counted fall to 45.4 and the ratio to 0.42%, at RM 3,402 a month in alert refunds and fees; stopping 60% brings the ratio to 0.24% at RM 6,804 a month.
Hypothesis · not established
The author’s hypothesis (not yet tested): for merchants of digital products with fewer than twenty thousand card transactions a month, joining a pre-dispute alert service and refunding every alert leads to fewer payout freezes or reserve increases by the acquirer over twelve months than fighting disputes alone. What would show it wrong: across many merchants, the number of freezes and reserve increases does not differ between the two practices.
Summary
A hash chain makes an evidence log impossible to rewrite unnoticed, and keyed identity hashes let transactions be compared without keeping raw personal data; but they prove integrity, not truth. Fighting disputes recovers money but does not lower the monitored ratio; what lowers it is fast refunds and pre-dispute alerts.
References
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).