Skip to content

Commit

Permalink
Use instances to resolve hashing
Browse files Browse the repository at this point in the history
This allows us to separate hashing concerns from everything else with
only minor overhead
  • Loading branch information
WhatisRT committed Nov 6, 2024
1 parent 5948ec5 commit bac93f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion formal-spec/Leios/Base.agda
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- {-# OPTIONS --safe #-}
{-# OPTIONS --safe #-}

open import Leios.Prelude
open import Leios.Abstract
Expand Down
22 changes: 8 additions & 14 deletions formal-spec/Leios/Blocks.agda
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- {-# OPTIONS --safe #-}
{-# OPTIONS --safe #-}

open import Leios.Prelude
open import Leios.Abstract
Expand Down Expand Up @@ -41,8 +41,6 @@ record IBHeaderOSig (b : Bool) : Type where
IBHeader = IBHeaderOSig true
PreIBHeader = IBHeaderOSig false

instance postulate Hashable-IBHeaderOSig : {b} Hashable (IBHeaderOSig b) Hash

record IBBody : Type where
field txs : List Tx

Expand All @@ -62,7 +60,7 @@ instance
IsBlock-InputBlock : IsBlock InputBlock
IsBlock-InputBlock = record { InputBlock }

mkIBHeader : PoolID VrfPf PrivKey List Tx IBHeader
mkIBHeader : ⦃ Hashable PreIBHeader Hash ⦄ PoolID VrfPf PrivKey List Tx IBHeader
mkIBHeader slot id π pKey txs = record { signature = sign pKey (hash h) ; IBHeaderOSig h }
where
h : IBHeaderOSig false
Expand All @@ -73,7 +71,7 @@ mkIBHeader slot id π pKey txs = record { signature = sign pKey (hash h) ; IBHea
; signature = _
}

getIBRef : InputBlock IBRef
getIBRef : ⦃ Hashable IBHeader Hash ⦄ InputBlock IBRef
getIBRef = hash ∘ InputBlock.header

--------------------------------------------------------------------------------
Expand All @@ -92,16 +90,14 @@ EndorserBlock = EndorserBlockOSig true
PreEndorserBlock = EndorserBlockOSig false

instance
postulate Hashable-PreEndorserBlock : Hashable PreEndorserBlock Hash

Hashable-EndorserBlock : Hashable EndorserBlock Hash
Hashable-EndorserBlock : ⦃ Hashable PreEndorserBlock Hash ⦄ Hashable EndorserBlock Hash
Hashable-EndorserBlock .hash b = hash {T = PreEndorserBlock}
record { EndorserBlockOSig b hiding (signature) ; signature = _ }

IsBlock-EndorserBlockOSig : {b} IsBlock (EndorserBlockOSig b)
IsBlock-EndorserBlockOSig {b} = record { EndorserBlockOSig }

mkEB : PoolID VrfPf PrivKey List IBRef List EBRef EndorserBlock
mkEB : ⦃ Hashable PreEndorserBlock Hash ⦄ PoolID VrfPf PrivKey List IBRef List EBRef EndorserBlock
mkEB slot id π pKey LI LE = record { signature = sign pKey (hash b) ; EndorserBlockOSig b }
where
b : PreEndorserBlock
Expand All @@ -113,7 +109,7 @@ mkEB slot id π pKey LI LE = record { signature = sign pKey (hash b) ; EndorserB
; signature = _
}

getEBRef : EndorserBlock EBRef
getEBRef : ⦃ Hashable PreEndorserBlock Hash ⦄ EndorserBlock EBRef
getEBRef = hash

-- TODO
Expand All @@ -127,9 +123,7 @@ getEBRef = hash
-- FFD for Leios Blocks
--------------------------------------------------------------------------------

postulate instance IsBlock-Vote : IsBlock (List Vote)

module GenFFD where
module GenFFD ⦃ _ : IsBlock (List Vote) ⦄ where
data Header : Type where
ibHeader : IBHeader Header
ebHeader : EndorserBlock Header
Expand All @@ -152,5 +146,5 @@ module GenFFD where
msgID (ebHeader h) = (slotNumber h , producerID h) -- NOTE: this isn't in the paper
msgID (vHeader h) = (slotNumber h , producerID h) -- NOTE: this isn't in the paper

ffdAbstract : FFDAbstract
ffdAbstract : ⦃ _ : IsBlock (List Vote) ⦄ FFDAbstract
ffdAbstract = record { GenFFD }
3 changes: 3 additions & 0 deletions formal-spec/Leios/SimpleSpec.agda
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Leios.Base
import Leios.Blocks

module Leios.SimpleSpec (a : LeiosAbstract) (let open LeiosAbstract a) (let open Leios.Blocks a)
⦃ IsBlock-Vote : IsBlock (List Vote) ⦄
⦃ Hashable-IBHeaderOSig : {b} Hashable (IBHeaderOSig b) Hash ⦄
⦃ Hashable-PreEndorserBlock : Hashable PreEndorserBlock Hash ⦄
(id : PoolID) (pKey : PrivKey) (FFD' : FFDAbstract.Functionality ffdAbstract)
(vrf : LeiosVRF a) (let open LeiosVRF vrf) (pubKey : PubKey)
(let open Leios.Base a) (B' : BaseAbstract) (BF' : BaseAbstract.Functionality B') where
Expand Down

0 comments on commit bac93f2

Please sign in to comment.