Documentation

CslibFrontier.DataStructure.HashFamily.Memory

A random table over the memory oracle #

A uniformly random function Fin U → Fin (2 ^ b) is the simplest resamplable hash family: its seed is the whole table. Here it is stored in a field array table of U cells, behind the memory oracle with private coins, (Memory.spec w).toRandomized.withCoins. resample refills the table with one uniform b-bit draw and one write per cell (fill), and eval u reads cell u.

The abstraction function reads the table as a function (tableOf). The implementation is a RandomizedRefinement of the seed-level specification tableSpec U b (refinement): the only probabilistic fact is that independent uniform draws fill a uniform table (run_fill, tableOf_writeFrom). The generic hop then gives the law of every adaptive client, and the run from allocation (run) has the transcript law HashFamily.evalOps on every operation list (run_obliviousClient). This is the memory-level counterpart of HashFamily.WordRAM.Impl.evalOps_execSteps, with no register, instruction count or ExecSteps bookkeeping. Every operation makes at most 2 * U calls, and eval exactly one (isCostBounded_methods, expectedAmortized, isQueryBounded_run).

Main definitions #

Main results #

References #

@[reducible, inline]

The uniformly random function Fin U → Fin (2 ^ b) as a resamplable hash family.

The table stored in the field table: cell u read as a b-bit word.

Fill cells i, …, i + n - 1 of the table with independent uniform b-bit words, one draw and one write per cell.

The operations: resample refills the table, and eval u reads cell u.

The memory after writing θ j to cell i + j of the table for each j < n, in order.

The memory after a fill #

@[simp]
theorem Cslib.DataStructure.HashFamily.RandomTable.frontier_writeFrom {table : WordRAM.Block} {b : ℕ} (i n : ℕ) (θ : Fin n → Fin (2 ^ b)) (s : Memory.State) :
(writeFrom table b i n θ s).frontier = s.frontier
theorem Cslib.DataStructure.HashFamily.RandomTable.mem_writeFrom_of_lt {table : WordRAM.Block} {b : ℕ} (i n : ℕ) (θ : Fin n → Fin (2 ^ b)) (s : Memory.State) {a : ℕ} (ha : a < table.base + i) :
(writeFrom table b i n θ s).mem a = s.mem a

Cells below the first written cell are unchanged.

theorem Cslib.DataStructure.HashFamily.RandomTable.mem_writeFrom {table : WordRAM.Block} {b : ℕ} (i n : ℕ) (θ : Fin n → Fin (2 ^ b)) (s : Memory.State) (j : Fin n) :
(writeFrom table b i n θ s).mem (table.base + (i + ↑j)) = ↑(θ j)

Cell i + j holds the j-th written word.

theorem Cslib.DataStructure.HashFamily.RandomTable.tableOf_writeFrom {table : WordRAM.Block} {b U : ℕ} (θ : Fin U → Fin (2 ^ b)) (s : Memory.State) :
tableOf table b U (writeFrom table b 0 U θ s) = θ

A full fill stores the written table.

Evaluation #

theorem Cslib.DataStructure.HashFamily.RandomTable.run_fill {table : WordRAM.Block} {b w : ℕ} (i n : ℕ) (s : Memory.State) :
PMF.map Prod.snd ((Memory.spec w).toRandomized.withCoins.run (fill table b i n) s) = PMF.map (fun (θ : Fin n → Fin (2 ^ b)) => writeFrom table b i n θ s) (Probability.PMF.uniformOfFintype (Fin n → Fin (2 ^ b)))

A fill writes a uniform table.

Reading a cell answers the stored word and leaves memory unchanged.

Admissibility #

theorem Cslib.DataStructure.HashFamily.RandomTable.demonicValid_fill {table : WordRAM.Block} {b w : ℕ} (hb : b ≤ w) {i n : ℕ} (hn : i + n ≤ table.length) {s : Memory.State} (hs : table.Allocated s) :

Every call of a fill within an allocated table is admissible when b-bit words fit.

The refinement #

The random table refines the random function. From an allocated table of U cells, resample draws a uniform table and eval u answers its entry u.

Costs #

One unit per call: resample makes one draw and one write per cell, eval one read.

A fill of n cells makes 2 * n calls.

Every operation makes at most its budget of calls.

theorem Cslib.DataStructure.HashFamily.RandomTable.expectedAmortized {table : WordRAM.Block} {b w U : ℕ} (hlen : table.length = U) (hb : b ≤ w) :
(refinement table b hlen hb).ExpectedAmortized (fun (x : (Memory.spec w).toRandomized.withCoins.State) (x_1 : (Memory.spec w).toRandomized.withCoins.Op) => 1) (fun (x : (tableSpec U b).State) (o : (tableSpec U b).Op) => budget U o) fun (x : (Memory.spec w).toRandomized.withCoins.State) => 0

In expectation as well, every operation costs at most its budget of calls.

The run from allocation #

Allocate a table of U cells, fill it, then serve the client p.

theorem Cslib.DataStructure.HashFamily.RandomTable.run_eq {b w U : ℕ} {α : Type} (p : OracleComp (Result (2 ^ b)) α) (s : Memory.State) :
PMF.map Prod.fst ((Memory.spec w).toRandomized.withCoins.run (run b U p) s) = (Probability.PMF.uniformOfFintype (Fin U → Fin (2 ^ b))).bind fun (θ : Fin U → Fin (2 ^ b)) => PMF.map Prod.fst ((tableSpec U b).run p θ)

The law of a client run from allocation: a uniform table, then the client against the random function. The law does not depend on the word size w, which only constrains admissibility.

theorem Cslib.DataStructure.HashFamily.RandomTable.run_obliviousClient {b w U : ℕ} (ops : List (Op U)) (s : Memory.State) :
PMF.map Prod.fst ((Memory.spec w).toRandomized.withCoins.run (run b U ((tableSpec U b).obliviousClient ops)) s) = evalOps (Probability.PMF.uniformOfFintype (Fin U → Fin (2 ^ b))) (fun (θ : Fin U → Fin (2 ^ b)) (u : Fin U) => θ u) ops

The memory-level evalOps theorem. From any memory state, the transcript law of the oblivious client of ops, run after allocating and filling the table, is HashFamily.evalOps of the random function.

The kWiseSpec contract over memory. A uniform table is k-wise independent for every k (Probability.isKWiseIndependentHash_id). So on every oblivious operation sequence with at most k distinct keys per epoch, the transcript law of the run from allocation meets HashFamily.kWiseSpec: it is the ideal transcript law.

Every memory call of the run is admissible when the table and b-bit words fit.

A client whose operations cost at most n in total, with budget U, runs from allocation with at most 1 + 2 * U + n calls.