One-way functions on bit strings
DefinitionLevin2003_owf_modelThe model in which Levin's one-way functions are stated. Instances are finite bit strings. A function on bit strings is length-preserving if for every , and polynomial-time computable if some multi-tape Turing machine outputs within steps for a fixed polynomial .
An inverter is a function that is handed the instance followed by a string of random coins and outputs a candidate preimage. Its success probability at input length with coins is
the fraction of pairs on which returns some preimage of .
is a one-way function when it is polynomial-time computable, length-preserving, and for every polynomial-time computable inverter , every coin budget and every , there is an with for all .
This is the standard asymptotic strong form of one-wayness for length-preserving functions, as discussed in Section 4.2 of the paper ('the simplest one is to define owfs as hard on average problems of inverting length-preserving functions'). It does not reproduce the paper's own apparatus of Las Vegas algorithms in (Definition 1), multimedian time (Definition 2) or security (Section 4.1).
import Mathlib
/-!
# Levin 2003, "The Tale of One-Way Functions" — basic model
Core notions used by the mission: bit strings, polynomial-time computability
(via Mathlib's two-tape Turing machine model), length preservation, the
inversion success probability of a probabilistic inverter, and the resulting
notion of a (strong) one-way function on length-preserving functions, as in
Section 4.2 of the paper.
-/
namespace Levin2003
/-- Finite bit strings. -/
abbrev Bits := List Bool
/-- `f` is computable in polynomial time by a multi-tape Turing machine,
bit strings being written on the tape symbol by symbol. -/
def PolyTimeComputable (f : Bits → Bits) : Prop :=
Nonempty (Turing.TM2ComputableInPolyTime (id : Bits → List Bool) (id : Bits → List Bool) f)
/-- `f` preserves the length of its argument. -/
def LengthPreserving (f : Bits → Bits) : Prop :=
∀ w : Bits, (f w).length = w.length
/-- The set of all bit strings of length `n`. -/
def cube (n : ℕ) : Finset Bits :=
Finset.image (fun v : Fin n → Bool => List.ofFn v) Finset.univ
/-- The number of pairs `(w, r)` with `w` of length `n` and `r` of length `m`
for which the inverter `A`, run on the instance `f w` together with the random
string `r`, returns a preimage of `f w` under `f`. -/
def invSuccessCount (f A : Bits → Bits) (n m : ℕ) : ℕ :=
((cube n ×ˢ cube m).filter (fun p => f (A (f p.1 ++ p.2)) = f p.1)).card
/-- The probability that `A` inverts `f` on a uniformly random instance `f w`,
`w` of length `n`, using `m` uniformly random coins. -/
def invSuccessProb (f A : Bits → Bits) (n m : ℕ) : ℚ :=
(invSuccessCount f A n m : ℚ) / (2 : ℚ) ^ (n + m)
/-- A (strong) one-way function: a length-preserving, polynomial-time computable
function that every polynomial-time probabilistic inverter inverts with
negligible probability on uniformly random inputs. -/
def OneWay (f : Bits → Bits) : Prop :=
PolyTimeComputable f ∧ LengthPreserving f ∧
∀ A : Bits → Bits, PolyTimeComputable A → ∀ c k : ℕ,
∃ N : ℕ, ∀ n : ℕ, N ≤ n → invSuccessProb f A n (n ^ c) < 1 / (n : ℚ) ^ k
end Levin2003
Read-back
What the Lean code literally says, in plain math · Aristotle (Harmonic) — non-blind, authored by the drafting agent
Non-blind read-back — not independent testimony. This read-back was written by the same agent that drafted the Lean statements in this proposal, at the explicit instruction of the proposal's owner. It was therefore not produced blind by an independent auditor: its author knew the source text, the intended meaning and the mission's aims while writing it. A reviewer must not treat it as an independent cross-check of faithfulness; it is at best a careful restatement by an interested party, and any discrepancy it fails to surface may simply reflect the author's own assumptions about what the code was meant to say.
This file fixes a model of feasible computation on finite bit strings and defines one-wayness inside it. Throughout, a bit string is a finite list of booleans, and its length is the number of entries.
Polynomial-time computability. A function from bit strings to bit strings is declared polynomial-time computable exactly when the type of multi-tape Turing machines that compute in polynomial time is nonempty, the input and output being written on the tape as the list of their own bits (the encoding map is the identity on lists of booleans). Concretely this requires a machine, an identification of its input and output alphabets with the booleans, a single polynomial with natural number coefficients, and a proof that on every input the machine halts with output within steps. Nonemptiness only asserts that such data exists; it carries no information about the machine.
Length preservation. is length-preserving when holds for every bit string , including the empty string.
The cube. For a natural number , the set of all bit strings of length exactly is formed as the image of the set of all functions from to the booleans. For this is the one-element set containing the empty string.
Success count and success probability. For functions and and naturals , the success count is the number of pairs , with ranging over all bit strings of length and over all bit strings of length , satisfying
where is concatenation. Note what this equation says and does not say: receives the single string with no marker separating the two parts, and it counts as successful when its output is any preimage of , not necessarily itself. The success probability is this count divided by as a rational number. The denominator is written as a power of two rather than as the cardinality of the index set; for or the corresponding factor is and the single string involved is the empty one.
One-wayness. is one-way when all three of the following hold: is polynomial-time computable; is length-preserving; and for every function from bit strings to bit strings that is itself polynomial-time computable, and for every pair of naturals and , there exists a natural such that for all ,
Several boundary features are worth spelling out. The coin budget is exactly for the quantified natural ; with the inverter gets one coin, and no quantifier ranges over coin budgets that are not of this shape. The right-hand side is a rational quotient: for it is , which in this arithmetic is when and when , and for it equals ; but since the bound is only required for and may be chosen freely, small impose nothing. The inverters quantified over are deterministic functions of the pair (instance, coins) — randomness enters only through the uniform average over — and they are quantified over as functions satisfying a computability predicate, not as machines, so no uniformity is required in , or . Finally, the inequality is strict.