Lawful state lenses for composite stateful oracle handlers #
Cryptographic games and reductions often combine several stateful components—an association-list
cache, a ciphertext log, a query countdown, a sticky Boolean bad flag—inside a single documented
structure rather than nested anonymous tuples (((j, (false, [])), queried)). A
StateLens S Part packages a lawful getter/setter pair (get_set, set_get, set_set) focusing
on one field or sub-record Part inside S.
StateLens.zoom lifts any StateT Part m action or oracle handler onto S while leaving the
unfocused fields invariant:
StateLens.run_interpret_zoomandStateLens.runWith_zoomcommute adaptive execution with zooming, using all three lens laws to preserve the unfocused frame of the initial state.StateLens.identicalUntilBad_zoomandStateLens.probIdenticalUntilBad_zoomtransportIdenticalUntilBadfromParttoS.StateLens.zoom_memoize_of_some,StateLens.zoom_memoize_of_none, andStateLens.length_get_of_mem_support_zoom_memoizeliftmemoizeand its cache-growth bound onto astructurestate.StateLens.latchturns any Boolean fieldflag : StateLens S Boolinto a monotone sticky bad flag directly onS, transportingIdenticalUntilBad, marginal projection (runWith_latch_map), and linear/triangular union bounds (toOuterMeasure_latch_le,toOuterMeasure_latch_choose_two_le) without packingSintoBase × Bool.
Main definitions #
Cslib.StateLens: lawful lens (get,set,get_set,set_get,set_set).Cslib.StateLens.zoom: lift aStateT Part mcomputation ontoS.Cslib.StateLens.Bad,Cslib.StateLens.latch: monotone Boolean bad-flag latching along aStateLens S Bool.
Main results #
Cslib.StateLens.run_interpret_zoom,Cslib.StateLens.runWith_zoom: adaptive execution of a zoomed handler preserves the outer state frame.Cslib.StateLens.identicalUntilBad_zoom,Cslib.StateLens.probIdenticalUntilBad_zoom:IdenticalUntilBadlifts acrosszoom.Cslib.StateLens.zoom_memoize_of_some,Cslib.StateLens.zoom_memoize_of_none,Cslib.StateLens.length_get_of_mem_support_zoom_memoize: zoomedmemoizecharacterization and cache-size growth.Cslib.StateLens.latch_of_false,Cslib.StateLens.identicalUntilBad_latch,Cslib.StateLens.probIdenticalUntilBad_latch,Cslib.StateLens.runWith_latch_map,Cslib.StateLens.toOuterMeasure_latch_le,Cslib.StateLens.toOuterMeasure_latch_choose_two_le: named-structure bad-flag hops and union bounds.
A lawful lens focusing on a Part component inside a composite state S.
- get : S → Part
Read the focused component from
S. - set : S → Part → S
Replace the focused component in
S. Reading immediately after writing recovers the written component.
Writing back the current component leaves the composite state unchanged.
Writing twice overwrites the first write.
Fixing the surrounding composite state s, l.set s is injective.
Zooming oracle executions and IdenticalUntilBad #
Running an OracleComp against a zoomed PMF handler executes against the inner handler from
l.get s and writes the final inner state back into the initial frame s.
Running a ProbOracleComp with runWith against a zoomed PMF handler executes against the
inner handler from l.get s and writes the final inner state back into s.
OracleComp.IdenticalUntilBad lifts along a lawful StateLens.
ProbOracleComp.IdenticalUntilBad lifts along a lawful StateLens.
Zooming memoize onto a composite state #
On a cache hit, l.zoom (memoize compute key) returns the cached value and leaves the entire
composite state s unchanged.
On a cache miss, l.zoom (memoize compute key) runs compute key and prepends (key, value)
to l.get s inside s.
Every supported transition of l.zoom (memoize compute key) in PMF grows the focused cache by
at most one entry.
Sticky Boolean bad-flag latching on a named structure state #
Latch a Boolean bad-flag field flag : StateLens S Bool across oracle calls: evaluate step on
the unflagged state flag.set s false and combine the prior flag flag.get s with the per-call
indicator flag.get s' via ||.
Two flag.latch handlers satisfy OracleComp.IdenticalUntilBad whenever their underlying
step kernels assign equal mass to unflagged transitions from unflagged states.
Two flag.latch handlers satisfy ProbOracleComp.IdenticalUntilBad whenever their underlying
step kernels assign equal mass to unflagged transitions from unflagged states.
Projecting a flag.latch step execution along proj : S → Base that ignores flag recovers
ProbOracleComp.runWith unflagged whenever each unflagged step projects to unflagged.
Linear bad-event union bound for ProbOracleComp.runWith (flag.latch step), stated directly in
terms of unflagged step transitions (flag.get s = false).
Triangular (n * size s + n.choose 2) bad-event union bound for
ProbOracleComp.runWith (flag.latch step), stated directly in terms of unflagged step
transitions (flag.get s = false).