5D Library › Zero-Touch Multi-Site Fault Tolerance, Payment Anti-Fraud State Machines and Passive Cashflow Queuing · 中文
Chapter 1. Transfer Receipts: Deduplication, Image Hashes and Release-Then-Audit
The question: how many times can one screenshot be used?
Many small digital businesses take no payment gateway; readers transfer money and upload a screenshot from their bank or wallet, which the system or a person checks before releasing access. The commonest cheat is reuse: the same screenshot (or a lightly edited one) for a second order, or someone else’s screenshot. The cheapest defence is to record the last few digits of each receipt’s reference number and refuse a repeat. This chapter first computes why that does not work, then discusses image hashes, and finally computes the economic conditions of “release first, audit later”.
Tail collisions: the birthday problem
If the last digits of reference numbers are uniform, the chance that at least two of honest orders share a tail is the classical birthday problem (Feller 1968). The more direct cost is wrongful refusal: after accepted orders, an honest new receipt finds its tail already used with probability .
Calculation
# Chapter 1. [p01] Last-k-digit receipt checks and hash look-alikes.
# (1) A manual-payment site accepts a bank-transfer screenshot and
# stores only the last k digits of its reference number to stop reuse.
# If tails are uniform, among n honest orders the chance of at least
# one shared tail is 1 - prod_{i<n} (1 - i / 10^k) (birthday problem).
# After M accepted orders, a new honest receipt is wrongly flagged as
# "reused" with chance 1 - (1 - 10^-k)^M.
# (2) A 64-bit perceptual hash flags two images as the same receipt if
# they differ in at most d bits. For unrelated images, bits differ
# with chance 0.5; for two honest receipts made by the same banking
# app (same layout, different numbers) they differ with chance 0.15;
# a re-saved copy of one receipt differs with chance 0.03 per bit.
import math
def birthday(n, k):
p = 1.0
for i in range(n):
p *= 1 - i / 10 ** k
return 1 - p
def first_n(k, target=0.5):
n, p = 1, 1.0
while 1 - p < target:
p *= 1 - n / 10 ** k
n += 1
return n
def tail(d, q, bits=64):
return sum(math.comb(bits, i) * q ** i * (1 - q) ** (bits - i)
for i in range(d + 1))
if __name__ == "__main__":
print(" (1) P(some shared tail) among n orders")
print(" k n=50 n=100 n=500 n=5000 n for 0.5")
for k in (4, 6, 8):
row = [birthday(n, k) for n in (50, 100, 500, 5000)]
print(" {} {:11.4f} {:8.4f} {:8.4f} {:8.4f} {:10d}".format(
k, *row, first_n(k)))
print(" honest receipt flagged after M = 5,000 orders:")
for k in (4, 6, 8):
print(" k={}: {:.4f}".format(k, 1 - (1 - 10 ** -k) ** 5000))
print(" (2) P(Hamming distance <= d) for a 64-bit perceptual hash")
print(" d unrelated same app re-saved copy")
for d in (4, 6, 10):
print(" {:2d} {:11.2e} {:10.4f} {:15.4f}".format(
d, tail(d, 0.5), tail(d, 0.15), tail(d, 0.03)))
print("\nReading: four-digit tails collide by the time a shop has")
print("taken 119 orders, and after 5,000 orders four honest")
print("receipts in ten would be refused. A perceptual hash finds")
print("re-saved copies but also matches honest receipts from the")
print("same app; neither replaces the full reference number.")
# (1) P(some shared tail) among n orders
# k n=50 n=100 n=500 n=5000 n for 0.5
# 4 0.1155 0.3914 1.0000 1.0000 119
# 6 0.0012 0.0049 0.1173 1.0000 1178
# 8 0.0000 0.0000 0.0012 0.1175 11775
# honest receipt flagged after M = 5,000 orders:
# k=4: 0.3935
# k=6: 0.0050
# k=8: 0.0000
# (2) P(Hamming distance <= d) for a 64-bit perceptual hash
# d unrelated same app re-saved copy
# 4 3.68e-14 0.0280 0.9569
# 6 4.51e-12 0.1365 0.9970
# 10 9.98e-09 0.6374 1.0000
#
# Reading: four-digit tails collide by the time a shop has
# taken 119 orders, and after 5,000 orders four honest
# receipts in ten would be refused. A perceptual hash finds
# re-saved copies but also matches honest receipts from the
# same app; neither replaces the full reference number.Checking only the last 4 digits, 50 orders already collide with probability 0.1155, 100 orders with 0.3914, and by 119 orders the chance exceeds a half. Worse is wrongful refusal: after 5,000 orders an honest new receipt is refused as a “repeat” with probability 0.3935. Six digits pass the even chance at 1178 orders, eight digits at 11775. Longer tails only postpone the problem, and a tail is easy to forge by editing the image. The right check is the full reference number, compared together with amount, time and receiving account.
What an image hash can do
Another family of defences hashes the screenshot itself. A cryptographic hash (such as SHA-256) gives a completely different value if any single byte changes (National Institute of Standards and Technology 2015), so it finds only byte-identical files; a screenshot that is re-saved or cropped is no longer recognised. A perceptual hash compresses an image to a 64-bit fingerprint such that similar images get similar fingerprints, and a Hamming-distance threshold decides “same image”.
The program considers three cases: two unrelated images (each bit differs with probability 0.5), two honest receipts produced by the same banking app (same layout, different numbers; each bit differs with probability 0.15), and a re-saved copy of one receipt (each bit differs with probability 0.03). At threshold , a re-saved copy is recognised with chance 0.9569 and unrelated images almost never match, but two honest receipts from the same app are judged the same with chance 0.0280. Loosening the threshold to 10 recognises every copy, while false matches between honest receipts from the same app rise to 0.6374.
A perceptual hash, then, can find “the same picture used again” but cannot tell apart “two different receipts from the same app”, because most of their pixels are the same to begin with. It can serve only as a supporting signal, not as a substitute for the full reference number.
Release first, audit later
Even with good checks, matching against a bank statement by hand takes time. A zero-touch design therefore leans toward releasing first: access opens as soon as the receipt is uploaded, a share of orders is audited later, and a forgery found is revoked. Is that enough to make forgery unprofitable? The economic analysis of crime frames the question as a comparison of expected gain with “probability of being caught times the penalty” (Becker 1968).
Let the product be worth and the effort of forging be 2; let be the share consumed before being caught ( for an instant reading, small for a course unlocked week by week); and let be a stake lost when caught (store credit, pending commissions, referred accounts revoked in cascade). The freeloader’s expected gain is , negative when exceeds .
Calculation
# Chapter 1. [p02] Optimistic release, sampled audits and revocation.
# Access is released as soon as a receipt is uploaded; a share a of
# orders is audited against the bank statement within a few days. A
# freeloader who uploads a fake receipt gains the product's value v,
# of which a share f is consumed before any audit can revoke access
# (f = 1 for an instant reading, small for a course that drips weekly).
# If caught he also loses a stake L (store credit, pending commissions,
# referred accounts revoked in cascade) and spent effort c. His
# expected gain is
# EV(a) = v (1 - a (1 - f)) - a L - c,
# negative iff a > a* = (v - c) / (v (1 - f) + L). An audit costs 1.5;
# the cost of deterrence per order is 1.5 a*.
V, C, AUDIT = 99.0, 2.0, 1.5
def a_star(f, L):
den = V * (1 - f) + L
return float("inf") if den == 0 else (V - C) / den
if __name__ == "__main__":
print(" audit share a* that makes faking unprofitable (v = 99):")
print(" f (consumed early) L=0 L=50 L=200 L=500")
for f in (1.0, 0.5, 0.2, 0.05):
cells = []
for L in (0, 50, 200, 500):
a = a_star(f, L)
cells.append(" never" if a > 1 else "{:8.3f}".format(a))
print(" {:18.2f} ".format(f) + " ".join(cells))
print(" audit cost per order at a*, f = 0.05:")
for L in (0, 50, 200):
a = a_star(0.05, L)
print(" L={:3d}: a* = {:.3f}, cost {:.2f}".format(
L, a, AUDIT * a))
print("\nReading: with nothing at stake (L = 0) no audit rate deters")
print("a freeloader, even when value is released slowly: auditing")
print("every order still leaves him what he consumed early. A stake")
print("lost on detection - credit, commissions, referred accounts")
print("revoked in cascade - is what makes sampled audits work, and")
print("slow release lowers the audit share it needs.")
# audit share a* that makes faking unprofitable (v = 99):
# f (consumed early) L=0 L=50 L=200 L=500
# 1.00 never never 0.485 0.194
# 0.50 never 0.975 0.389 0.177
# 0.20 never 0.751 0.347 0.167
# 0.05 never 0.673 0.330 0.163
# audit cost per order at a*, f = 0.05:
# L= 0: a* = 1.031, cost 1.55
# L= 50: a* = 0.673, cost 1.01
# L=200: a* = 0.330, cost 0.49
#
# Reading: with nothing at stake (L = 0) no audit rate deters
# a freeloader, even when value is released slowly: auditing
# every order still leaves him what he consumed early. A stake
# lost on detection - credit, commissions, referred accounts
# revoked in cascade - is what makes sampled audits work, and
# slow release lowers the audit share it needs.The conclusion is plain: a freeloader who loses nothing when caught () is deterred by no audit share, even when content unlocks slowly week by week: auditing everything still leaves him what he consumed before being caught (at the share needed is 1.031, above 1). What works is the stake: with , an instant good needs only 0.485 of orders audited, and with slow release () only 0.330, at an audit cost of 0.49 per order.
A release-then-audit design must therefore also design what is lost when caught: tie credits, commissions and referral relationships to the same identity and revoke them together when forgery is found (cascading revocation); a newly registered account with nothing at stake should either be verified before release or be released only the low-value part.
Hypothesis · not established
The author’s interpretation (not yet tested): in the author’s business, the great majority of forged receipts come from newly registered accounts with no credits and no referrals; verifying these accounts before release, and releasing first and auditing later for established accounts with a stake, can make forgery unprofitable without a marked loss of conversion. What would show this wrong: if real audit records showed forgery coming mainly from established accounts with credits or referrals, or if delayed release for new accounts sharply lowered their conversion, this routing rule would fail.
Summary
Four trailing digits have an even chance of a collision by 119 orders and, after 5,000 orders, wrongly refuse 0.3935 of honest receipts; the full reference number must be checked. A perceptual hash recognises re-saved copies but takes honest receipts from the same app for one another. Release-then-audit deters only when the person caught loses a stake; with a stake of 200, auditing 0.485 of orders is enough.
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).