Counting Queries Made by a Computation #
This file defines a simulation oracle countingOracle for counting the number of queries made
while running the computation. The count is represented by a function from oracle indices to
counts, allowing each oracle to be tracked individually.
Tracking individually is not necessary, but gives tighter security bounds in some cases. It also allows for generating things like seed values for a computation more tightly.
Wrap an oracle implementation to accumulate cost in a WriterT ω layer.
The cost function costFn assigns a cost value to each oracle query.
Cost is accumulated before the implementation runs, so failed queries are still costed.
Instances For
Wrap an oracle implementation to count queries in a WriterT (QueryCount ι) layer.
Counting happens before the implementation runs, so failed queries are still counted.
This is a special case of withCost where the cost function is QueryCount.single.
Equations
- so.withCounting = so.withCost fun (x : spec.Domain) => OracleSpec.QueryCount.single x
Instances For
Oracle with arbitrary cost tracking. The cost is accumulated in a WriterT ω layer
while preserving the original oracle behavior.
Equations
- costOracle costFn = (QueryImpl.ofLift spec (OracleComp spec)).withCost costFn
Instances For
Oracle for counting the number of queries made by a computation. The count is stored as a function from oracle indices to counts, to give finer grained information about the count.
Equations
- countingOracle = (QueryImpl.ofLift spec (OracleComp spec)).withCounting
Instances For
Compatibility helper matching old state-style counting semantics:
simulate with zero initial count, then offset by qc.
Equations
- countingOracle.simulate oa qc = (Prod.map id fun (x : OracleSpec.QueryCount ι) => qc + x) <$> (simulateQ countingOracle oa).run
Instances For
We can always reduce simulation with counting to start with 0,
and add the initial count back at the end.
Reduce membership in support of simulation with counting to simulation starting from 0.