One-Way Function

lean4-proofcryptographyvisualization
f(x)=gxmodpf(x) = g^x \bmod p

Statement

A function f:{0,,q1}Gf : \{0, \ldots, q-1\} \to G is one-way if it is easy to evaluate but computationally hard to invert: for any probabilistic polynomial-time algorithm A\mathcal{A},

Pr[A(f(x))=x]0\Pr[\mathcal{A}(f(x)) = x] \approx 0

The discrete logarithm function in a prime-order group G=gG = \langle g \rangle of order qq:

f(x)=gxf(x) = g^x

is conjectured to be one-way. Evaluating gxg^x takes O(logx)O(\log x) multiplications via square-and-multiply; no polynomial-time algorithm to invert it is known.

Note. One-wayness is a computational assumption — it cannot be proved from first principles without resolving PNP\mathsf{P} \ne \mathsf{NP}. What we can prove formally is that the function is injective on its domain (distinct exponents give distinct group elements when gg is a generator of order qq), and surjective onto GG (every element is a power of gg). These are purely algebraic facts.

Visualization

Discrete log table for g=2g = 2, p=11p = 11 (so G=(Z/11Z)G = (\mathbb{Z}/11\mathbb{Z})^*, order q=10q = 10):

xx (log)f(x)=2xmod11f(x) = 2^x \bmod 11
0011
1122
2244
3388
4455
551010
6699
7777
8833
9966

Forward direction (easy): given x=7x = 7, compute f(7)=27mod11=128mod11=7f(7) = 2^7 \bmod 11 = 128 \bmod 11 = 7 in 3 multiplications.

Inverse direction (hard for large pp): given y=7y = 7, find xx such that 2x7(mod11)2^x \equiv 7 \pmod{11}. For p=11p = 11 we read off x=7x = 7 from the table. For pp with hundreds of digits, no known efficient algorithm exists.

The function is visibly a bijection on {0,,9}\{0, \ldots, 9\}: each output in {1,,10}\{1, \ldots, 10\} appears exactly once — injectivity is provable, invertibility is hard.

Proof Sketch

  1. Well-defined and surjective. If gg generates GG of order qq, then {g0,g1,,gq1}=G\{g^0, g^1, \ldots, g^{q-1}\} = G by definition of generator.

  2. Injective. If ga=gbg^a = g^b in a group of order qq, then gab=1g^{a-b} = 1, so q(ab)q \mid (a - b), hence ab(modq)a \equiv b \pmod{q}. On {0,,q1}\{0, \ldots, q-1\} this gives a=ba = b.

  3. One-way assumption (not provable). The assumption is that no PPT algorithm inverts ff with non-negligible probability. This is the Discrete Logarithm Assumption (DLA), equivalent to the CDH assumption when the group is suitably chosen.

  4. Trapdoor structure. With a trapdoor (the private key xx), inversion is trivial. Without it, inversion is believed hard. This asymmetry is the source of all public-key security.

Connections

The discrete log one-way function underlies Diffie–HellmanDiffie–Hellman(ga)b=(gb)a(g^a)^b = (g^b)^aAlice and Bob derive the same shared secret g^(ab) from public keys g^a and g^b in any commutative group.Read more → and Digital Signature (Schnorr)Digital Signature (Schnorr)gs=Rycg^s = R \cdot y^cA Schnorr signature (R, s) is valid iff g^s = R · y^c, verified by a single group equation.Read more →. Computing gxg^x efficiently uses Modular ExponentiationModular Exponentiationanmodma^n \bmod mSquare-and-multiply computes a^n mod m in O(log n) multiplications, agreeing with naive exponentiation.Read more →. The injectivity proof uses that the group order divides gq=1g^{q} = 1, which follows from Fermat's Little TheoremFermat's Little Theoremapa(modp)a^p \equiv a \pmod{p}For prime p, a^p is congruent to a mod pRead more → for prime-order groups. The surjectivity claim is Cayley's TheoremCayley's TheoremGSGG \hookrightarrow S_{|G|}Every group embeds into a symmetric groupRead more → applied to cyclic groups.

Lean4 Proof

/-- For p = 11, g = 2: the map x ↦ 2^x mod 11 on {0,...,9} is injective.
    We verify by listing all 10 values and checking they are distinct. -/

-- The full orbit: 2^0, 2^1, ..., 2^9  (mod 11)
def dlogTable : List  := (List.range 10).map (fun x => 2 ^ x % 11)

-- All 10 values are pairwise distinct.
example : dlogTable = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6] := by decide

example : dlogTable.Nodup := by decide

/-- Consequently the discrete log function is well-defined on this group:
    every element of {1,...,10} appears exactly once. -/
example : dlogTable.length = 10 := by decide

/-- Forward direction is O(log x): compute f(7) = 2^7 mod 11 directly. -/
example : 2 ^ 7 % 11 = 7 := by decide