Bias of the reduce-modulo-order decoder #
A challenge squeezed from a byte sponge is CanonicalNat.ofBytesModOrder: n bytes read as a
little-endian integer and reduced modulo bound. Reducing the 256 ^ n strings modulo bound
hits every residue 256 ^ n / bound or 256 ^ n / bound + 1 times, so the induced distribution
on F is within bound / 256 ^ n of uniform in total variation. Sixteen bytes beyond the
field's width make that below 2 ^ -128, which is the margin spongefish uses.
Bytes.equivFin:n-byte strings are the naturals below256 ^ n.CanonicalNat.card_fiber_ofBytesModOrder: the exact fiber count, from Mathlib'sNat.count_modEq_card.CanonicalNat.tv_ofBytesModOrder_le: the total-variation bound, overℚ.
Everything here is counting; no probability theory is imported. ArkLib's
Deserialize.CloseToUniform instance for ZMod p is derived from the last theorem by casting
into its PMF distance.
The n-byte strings decoding to x modulo the order, as the naturals below 256 ^ n
congruent to toNat x.
Instances For
Exactly how many n-byte strings decode to x modulo the order: the quotient
256 ^ n / bound, plus one for the residues below the remainder.
Every fiber is within one of the ideal 256 ^ n / bound, so each residue's probability is
within 1 / 256 ^ n of uniform.
The total-variation distance of ofBytesModOrder on n bytes from the uniform
distribution on F is at most bound / 256 ^ n: sixteen bytes beyond the width give
2 ^ -128. Stated over ℚ; ArkLib derives its PMF form from it.