Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

YukonModule.VCVio.CryptoFoundations.PRG.part0

Definition
Yukon_eb44a079d629d0642e74f1e2

by yukon · Sep 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

better-codes

Source module VCVio.CryptoFoundations.PRG.

Definition code
/-
Copyright (c) 2026 Quang Dao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Quang Dao
-/

module
public import Definitions.Def_Yukon_19e49f429e40ab4a8ab6f6e7

public import Definitions.Def_Yukon_2b5744019605f484379c669d

public import Definitions.Def_Yukon_3ca8dea642d23c4bd0e25cee



public import Batteries.Control.OptionT
public import Mathlib.Probability.Distributions.Uniform
public import Mathlib.Data.Vector.Defs
public import Mathlib.Data.Finset.Card
public import Init
public import Mathlib.CategoryTheory.Monad.Types
public import Mathlib.Order.CompleteLattice.Basic
public import Mathlib.Probability.ProbabilityMassFunction.Monad
public import Batteries.Control.AlternativeMonad
public import Mathlib.Data.PFunctor.Multivariate.Basic
public import Mathlib.Data.PFunctor.Univariate.Basic
public import Mathlib.Tactic.Common
public import Mathlib.Init
public import Lean.Message
public import Batteries.Tactic.Lint.Basic
public import Batteries.Tactic.Lint
public import Mathlib.Algebra.Polynomial.Eval.Defs
public import Mathlib.Algebra.MvPolynomial.Eval
public import Mathlib.Data.Fintype.Vector
public import Mathlib.Data.Fintype.Pi
public import Mathlib.Data.Fintype.Perm
public import Mathlib.Data.FinEnum
public import Init.Data.UInt.Lemmas
public import Mathlib.Logic.Embedding.Basic
public import Mathlib.Data.List.Sym
public import Mathlib.Topology.Algebra.InfiniteSum.ENNReal
meta import Definitions.Def_Yukon_19e49f429e40ab4a8ab6f6e7
meta import Definitions.Def_Yukon_2b5744019605f484379c669d
meta import Definitions.Def_Yukon_3ca8dea642d23c4bd0e25cee
set_option backward.isDefEq.respectTransparency.types false
/-!
# Pseudorandom Generators (PRGs)

This file defines pseudorandom generators and their security game.

A PRG stretches a short random seed into a longer pseudorandom output.
Security means no efficient adversary can distinguish `gen(s)` (for a random seed `s`)
from a truly random output `r`.

## Main Definitions

- `PRGScheme S R` — a PRG with seed space `S` and output space `R`.
- `PRGAdversary R` — a distinguisher receiving a single value in `R`.
- `prgRealExp` — the real experiment (adversary sees `gen(s)` for random `s`).
- `prgIdealExp` — the ideal experiment (adversary sees random `r`).
- `prgAdvantage` — distinguishing advantage.
-/

@[expose] public section

open OracleComp OracleSpec ENNReal

/-- A pseudorandom generator with seed space `S` and output space `R`.
The generator is a deterministic function; security comes from the
seed being sampled uniformly. -/
structure PRGScheme (S R : Type) where
  gen : S → R

namespace PRGScheme

variable {S R : Type}

/-- A PRG adversary receives a single value and guesses whether it was
generated by the PRG or sampled uniformly. -/
def PRGAdversary (R : Type) := R → ProbComp Bool

/-- Real PRG experiment: sample a random seed and let the adversary
see the PRG output. -/
def prgRealExp [SampleableType S] (prg : PRGScheme S R) (adversary : PRGAdversary R) :
    ProbComp Bool := do
  let s ← $ᵗ S
  adversary (prg.gen s)

/-- Ideal PRG experiment: let the adversary see a uniformly random value. -/
def prgIdealExp [SampleableType R] (adversary : PRGAdversary R) : ProbComp Bool := do
  let r ← $ᵗ R
  adversary r

/-- PRG advantage: how well the adversary distinguishes PRG output from random. -/
noncomputable def prgAdvantage [SampleableType S] [SampleableType R]
    (prg : PRGScheme S R) (adversary : PRGAdversary R) : ℝ :=
  |(Pr[= true | prg.prgRealExp adversary]).toReal -
    (Pr[= true | prgIdealExp adversary]).toReal|

end PRGScheme


Source
https://github.com/Verified-zkEVM/VCV-io/blob/446baa72bb7d4296d6f6b7015fd6c15ca9c678b7/VCVio/CryptoFoundations/PRG.lean yukon-proof-operation:9d10b17a720a454e261022be48fa09fe1c982c62db0db42c0436bc63850b5c52 [yukon-proof-receipt:eyJ2IjoxLCJtYXJrZXIiOiJ5dWtvbi1wcm9vZi1vcGVyYXRpb246OWQxMGIxN2E3MjBhNDU0ZTI2MTAyMmJlNDhmYTA5ZmUxYzk4MmM2MmRiMGRiNDJjMDQzNmJjNjM4NTBiNWM1MiIsImhhc2giOiI4NDFlMWFiMjgzN2Q4ZTJlNDI2MzA4YmE2N2JjYmFhOGZhMDk3YzBhNjk3YjgxNTdlYmRkZDVkNTQ2ZDcxNDA1Iiwia2luZCI6ImRlZmluaXRpb24iLCJ0YXJnZXQiOiJZdWtvbl9lYjQ0YTA3OWQ2MjlkMDY0MmU3NGYxZTIiLCJlbnZpcm9ubWVudCI6eyJtYXRobGliUmV2IjoiMGRmNDQ0YTM2MGVhYTYwYWI4YzExZGNhNTFhODZhZjY5Mjk1NTQ3NCIsInRvb2xjaGFpbiI6ImxlYW5wcm92ZXIvbGVhbjQ6djQuMzMuMSJ9LCJ0YWciOiJiZXR0ZXItY29kZXMifQ]

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me