Skip to content

Commit

Permalink
Add a VRF functionality to replace some postulates
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatisRT committed Oct 31, 2024
1 parent ed8f01e commit efa02c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions formal-spec/Leios/Abstract.agda
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open import Leios.Prelude
record LeiosAbstract : Type₁ where
field Tx : Type
PoolID : Type
⦃ DecEq-PoolID ⦄ : DecEq PoolID
BodyHash VrfPf PrivKey Sig Hash : Type -- these could have been byte strings, but this is safer
⦃ DecEq-Hash ⦄ : DecEq Hash
Vote : Type
Expand Down
5 changes: 4 additions & 1 deletion formal-spec/Leios/BaseFunctionality.agda
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ module Leios.BaseFunctionality (a : LeiosAbstract) (let open LeiosAbstract a) wh

open import Leios.Blocks a

postulate StakeDistr Cert : Type
StakeDistr : Type
StakeDistr = PoolID ⇀ ℕ

postulate Cert : Type

data Input : Type₁ where
INIT : (EndorserBlock × Cert Type) Input
Expand Down
17 changes: 11 additions & 6 deletions formal-spec/Leios/SimpleSpec.agda
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
open import Leios.Prelude
open import Leios.Abstract
open import Leios.FFD
open import Leios.VRF
import Leios.Blocks

module Leios.SimpleSpec (a : LeiosAbstract) (let open LeiosAbstract a) (let open Leios.Blocks a)
(id : PoolID) (pKey : PrivKey) (FFD : FFDAbstract.Functionality ffdAbstract) where
(id : PoolID) (pKey : PrivKey) (FFD : FFDAbstract.Functionality ffdAbstract)
(vrf : LeiosVRF a) (let open LeiosVRF vrf) (pubKey : PubKey) where

import Leios.BaseFunctionality

Expand Down Expand Up @@ -61,9 +63,7 @@ initLeiosState V SD = record
; slot = initSlot V
}

postulate canProduceIB : VrfPf Type
canProduceEB : VrfPf Type
canProduceV1 : Type
postulate canProduceV1 : Type
canProduceV2 : Type

-- some predicates about EBs
Expand All @@ -90,6 +90,11 @@ private variable s : LeiosState

open LeiosState using (FFDState; MemPool)

stake : LeiosState
stake record { SD = SD } = case lookupᵐ? SD id of λ where
(just s) s
nothing 0

data _⇀⟦_⟧_ : Maybe LeiosState LeiosInput LeiosState × LeiosOutput Type where
Init : {V bs bs' SD}
{!!} -- create & register the IB/EB lottery and voting keys with key reg
Expand Down Expand Up @@ -117,7 +122,7 @@ data _⇀⟦_⟧_ : Maybe LeiosState → LeiosInput → LeiosState × LeiosOutpu
b = GenFFD.ibBody (record { txs = txs })
h = GenFFD.ibHeader (mkIBHeader slot id π pKey txs)
in
∙ canProduceIB slot π
∙ canProduceIB slot pKey (stake s)
∙ FFDAbstract.Send h (just b) FFD'.⇀⟦ ffds ⟧ (ffds' , FFDAbstract.SendRes)
─────────────────────────────────────────────────────────────────────────
just s ⇀⟦ SLOT ⟧ (record s { FFDState = ffds' } , EMPTY)
Expand All @@ -129,7 +134,7 @@ data _⇀⟦_⟧_ : Maybe LeiosState → LeiosInput → LeiosState × LeiosOutpu
h = mkEB slot id π pKey LI LE
ffds = s .FFDState
in
∙ canProduceEB slot π
∙ canProduceEB slot pKey (stake s)
∙ FFDAbstract.Send (GenFFD.ebHeader h) nothing FFD'.⇀⟦ ffds ⟧ (ffds' , FFDAbstract.SendRes)
──────────────────────────────────────────────────────────────────────────────────────────
just s ⇀⟦ SLOT ⟧ (record s { FFDState = ffds' } , EMPTY)
Expand Down
30 changes: 30 additions & 0 deletions formal-spec/Leios/VRF.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
open import Leios.Prelude
open import Leios.Abstract

module Leios.VRF (a : LeiosAbstract) (let open LeiosAbstract a) where

record VRF (Dom Range PubKey : Type) : Type₁ where
field isKeyPair : PubKey PrivKey Type
eval : PrivKey Dom Range × VrfPf
verify : PubKey Dom Range VrfPf Type

record LeiosVRF : Type₁ where
field PubKey : Type
vrf : VRF ℕ ℕ PubKey

open VRF vrf public

-- transforming slot numbers into VRF seeds
field genIBInput genEBInput :

canProduceIB : PrivKey Type
canProduceIB slot k stake = proj₁ (eval k (genIBInput slot)) < stake

canProduceIBPub : PubKey VrfPf Type
canProduceIBPub slot val k pf stake = verify k (genIBInput slot) val pf × val < stake

canProduceEB : PrivKey Type
canProduceEB slot k stake = proj₁ (eval k (genEBInput slot)) < stake

canProduceEBPub : PubKey VrfPf Type
canProduceEBPub slot val k pf stake = verify k (genEBInput slot) val pf × val < stake

0 comments on commit efa02c0

Please sign in to comment.