-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVRF.lean
More file actions
39 lines (29 loc) · 1.13 KB
/
VRF.lean
File metadata and controls
39 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Crypto.EllipticCurve
open Crypto.EllipticCurve
open Crypto.Field
namespace Crypto.EllipticCurve.VRF
variable {α : Type}
variable {p : Nat}
variable {ec : EllipticCurve (Fp p)}
structure Proof (g : Group ec) where
output : Point ec
challenge : Fp g.n
response : Fp g.n
deriving Repr, DecidableEq, BEq, Inhabited
variable {g : EllipticCurve.Group ec}
def prove [RandomGen gen] [Monad m] (htc : Point ec → α → Point ec) (commit : Point ec → Point ec → Point ec → Point ec → Fp g.n) (kp : Group.KeyPair g) (x : α) : RandGT gen m (Proof g) :=
do
let H := htc kp.pub x
let Z := kp.prv * H
let r ← Random.random
let RB := r * g.G
let RH := r * H
let c := commit H Z RB RH
let s := r + kp.prv * c
pure ⟨ Z , c , s ⟩
def verify (htc : Point ec → α → Point ec) (commit : Point ec → Point ec → Point ec → Point ec → Fp g.n) (pk : Group.PubKey g) (x : α) : Proof g → Bool
| ⟨ Z , c , s ⟩ => let H := htc pk.pub x
let RB := s * g.G - c * pk.pub
let RH := s * H - c * Z
c = commit H Z RB RH
end Crypto.EllipticCurve.VRF