-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
207 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{-# OPTIONS --safe #-} | ||
|
||
open import Ledger.Prelude | ||
open import Ledger.Types.GovStructure | ||
open import Ledger.Transaction | ||
open import Ledger.Abstract | ||
|
||
module Ledger.Ledger.Haskell | ||
(txs : _) (open TransactionStructure txs using (govStructure; Tx; TxBody; epoch)) | ||
(abs : AbstractFunctions txs) (open AbstractFunctions abs) | ||
where | ||
|
||
open import Ledger.Utxo txs abs | ||
open import Ledger.Utxow txs abs | ||
open import Ledger.Gov txs | ||
open import Ledger.Certs.Haskell govStructure | ||
open import Ledger.Ledger txs abs | ||
using (LEnv; txgov) | ||
open import Ledger.Types.Epoch | ||
|
||
record LState : Type where | ||
constructor ⟦_,_,_⟧ˡ | ||
field | ||
utxoSt : UTxOState | ||
govSt : GovState | ||
certState : CertState | ||
|
||
private variable | ||
Γ : LEnv | ||
s s' s'' : LState | ||
utxoSt' : UTxOState | ||
govSt' : GovState | ||
certState' : CertState | ||
tx : Tx | ||
|
||
open Tx | ||
|
||
data | ||
_⊢_⇀⦇_,LEDGER⦈_ : LEnv → LState → Tx → LState → Type | ||
where | ||
LEDGER-V : let open LState s; txb = tx .body; open TxBody txb; open LEnv Γ in | ||
∙ isValid tx ≡ true | ||
∙ record { LEnv Γ } ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt' | ||
∙ ⟦ epoch slot , pparams , txvote , txwdrls ⟧ᶜ ⊢ certState ⇀⦇ txcerts ,CERTS⦈ certState' | ||
∙ ⟦ txid , epoch slot , pparams , ppolicy , enactState ⟧ᵍ ⊢ govSt ⇀⦇ txgov txb ,GOV⦈ govSt' | ||
──────────────────────────────── | ||
Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt' , govSt' , certState' ⟧ˡ | ||
|
||
LEDGER-I : let open LState s; txb = tx .body; open TxBody txb; open LEnv Γ in | ||
∙ isValid tx ≡ false | ||
∙ record { LEnv Γ } ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt' | ||
──────────────────────────────── | ||
Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt' , govSt , certState ⟧ˡ | ||
|
||
pattern LEDGER-V⋯ w x y z = LEDGER-V (w , x , y , z) | ||
pattern LEDGER-I⋯ y z = LEDGER-I (y , z) | ||
|
||
_⊢_⇀⦇_,LEDGERS⦈_ : LEnv → LState → List Tx → LState → Type | ||
_⊢_⇀⦇_,LEDGERS⦈_ = ReflexiveTransitiveClosure _⊢_⇀⦇_,LEDGER⦈_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{-# OPTIONS --safe #-} | ||
|
||
open import Ledger.Prelude | ||
open import Ledger.Transaction | ||
open import Ledger.Abstract | ||
|
||
module Ledger.Ledger.Haskell.Properties | ||
(txs : _) (open TransactionStructure txs using (Tx; TxBody; epoch; govStructure)) | ||
(abs : AbstractFunctions txs) (open AbstractFunctions abs) | ||
where | ||
|
||
open import Ledger.Ledger.Haskell txs abs | ||
open import Ledger.Certs.Haskell govStructure | ||
open import Ledger.Certs.Haskell.Properties govStructure | ||
open import Ledger.Utxow txs abs | ||
open import Ledger.Utxow.Properties txs abs | ||
open import Ledger.Gov txs | ||
open import Ledger.Gov.Properties txs | ||
open import Ledger.Ledger txs abs | ||
using (LEnv; ⟦_,_,_,_,_⟧ˡᵉ; txgov) | ||
open import Ledger.Utxo txs abs | ||
open import Ledger.Utxo.Properties txs abs | ||
open import Data.Bool.Properties using (¬-not) | ||
|
||
instance | ||
_ = Monad-ComputationResult | ||
|
||
Computational-LEDGER : Computational _⊢_⇀⦇_,LEDGER⦈_ String | ||
Computational-LEDGER = record {go} | ||
where | ||
open Computational ⦃...⦄ renaming (computeProof to comp; completeness to complete) | ||
computeUtxow = comp {STS = _⊢_⇀⦇_,UTXOW⦈_} | ||
computeCerts = comp {STS = _⊢_⇀⦇_,CERTS⦈_} | ||
computeGov = comp {STS = _⊢_⇀⦇_,GOV⦈_} | ||
|
||
module go | ||
(Γ : LEnv) (let ⟦ slot , ppolicy , pparams , enactState , _ ⟧ˡᵉ = Γ) | ||
(s : LState) (let ⟦ utxoSt , govSt , certSt ⟧ˡ = s) | ||
(tx : Tx) (let open Tx tx renaming (body to txb); open TxBody txb) | ||
where | ||
utxoΓ = UTxOEnv ∋ record { LEnv Γ } | ||
certΓ = CertEnv ∋ ⟦ epoch slot , pparams , txvote , txwdrls ⟧ᶜ | ||
govΓ = GovEnv ∋ ⟦ txid , epoch slot , pparams , ppolicy , enactState ⟧ᵍ | ||
|
||
computeProof : ComputationResult String (∃[ s' ] Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ s') | ||
computeProof = case isValid ≟ true of λ where | ||
(yes p) → do | ||
(utxoSt' , utxoStep) ← computeUtxow utxoΓ utxoSt tx | ||
(certSt' , certStep) ← computeCerts certΓ certSt txcerts | ||
(govSt' , govStep) ← computeGov govΓ govSt (txgov txb) | ||
success (_ , LEDGER-V⋯ p utxoStep certStep govStep) | ||
(no ¬p) → do | ||
(utxoSt' , utxoStep) ← computeUtxow utxoΓ utxoSt tx | ||
success (_ , LEDGER-I⋯ (¬-not ¬p) utxoStep) | ||
|
||
completeness : ∀ s' → Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ s' → (proj₁ <$> computeProof) ≡ success s' | ||
completeness ⟦ utxoSt' , govSt' , certState' ⟧ˡ (LEDGER-V⋯ v utxoStep certStep govStep) | ||
with isValid ≟ true | ||
... | no ¬v = contradiction v ¬v | ||
... | yes refl | ||
with computeUtxow utxoΓ utxoSt tx | complete _ _ _ _ utxoStep | ||
... | success (utxoSt' , _) | refl | ||
with computeCerts certΓ certSt txcerts | complete _ _ _ _ certStep | ||
... | success (certSt' , _) | refl | ||
with computeGov govΓ govSt (txgov txb) | complete govΓ _ _ _ govStep | ||
... | success (govSt' , _) | refl = refl | ||
completeness ⟦ utxoSt' , govSt' , certState' ⟧ˡ (LEDGER-I⋯ i utxoStep) | ||
with isValid ≟ true | ||
... | yes refl = case i of λ () | ||
... | no ¬v | ||
with computeUtxow utxoΓ utxoSt tx | complete _ _ _ _ utxoStep | ||
... | success (utxoSt' , _) | refl = refl | ||
|
||
Computational-LEDGERS : Computational _⊢_⇀⦇_,LEDGERS⦈_ String | ||
Computational-LEDGERS = it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters