-
Notifications
You must be signed in to change notification settings - Fork 20
Dijkstra: nested transactions (first phase) #942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
daddad4
Model subtransactions WIP
carlostome a0dc326
Add agda to literate code block
carlostome 7554836
progress and improvements
carlostome 7e510d7
reorganize Dijkstra consistent with Conway org
williamdemeo 1da89bb
effect Carlos's change requests
williamdemeo bffe14d
reinserting definitions until we switch to new agda-sets
williamdemeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| module Ledger.Dijkstra where | ||
|
|
||
| --- Cardano ledger in the Dijkstra era | ||
| import Ledger.Dijkstra.Specification | ||
|
|
||
| -- TODO: | ||
| -- import Ledger.Dijkstra.Conformance -- Conformance test reconciliation | ||
| -- import Ledger.Dijkstra.Foreign.HSLedger -- Haskell code extraction | ||
This file contains hidden or 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,16 @@ | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| module Ledger.Dijkstra.Specification where | ||
|
|
||
| import Ledger.Core.Specification.Address renaming (RwdAddr to RewardAddress) | ||
| import Ledger.Core.Specification.Epoch | ||
|
|
||
| import Ledger.Dijkstra.Specification.Certs | ||
| import Ledger.Dijkstra.Specification.Gov.Base | ||
| import Ledger.Dijkstra.Specification.Gov.Actions | ||
| import Ledger.Dijkstra.Specification.PParams | ||
| import Ledger.Dijkstra.Specification.Script | ||
| import Ledger.Dijkstra.Specification.Script.Validation | ||
| import Ledger.Dijkstra.Specification.TokenAlgebra.Base | ||
| import Ledger.Dijkstra.Specification.Transaction | ||
| ``` |
This file contains hidden or 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,28 @@ | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Prelude | ||
| open import Ledger.Dijkstra.Specification.Transaction | ||
|
|
||
| module Ledger.Dijkstra.Specification.Abstract (txs : TransactionStructure) where | ||
|
|
||
| open TransactionStructure txs | ||
| open import Ledger.Dijkstra.Specification.Certs govStructure | ||
|
|
||
| record indexOf : Type where | ||
| field | ||
| indexOfDCert : DCert → List DCert → Maybe Ix | ||
| indexOfRwdAddr : RewardAddress → Withdrawals → Maybe Ix | ||
| indexOfTxIn : TxIn → ℙ TxIn → Maybe Ix | ||
| indexOfPolicyId : ScriptHash → ℙ ScriptHash → Maybe Ix | ||
| indexOfVote : GovVoter → List GovVoter → Maybe Ix | ||
| indexOfProposal : GovProposal → List GovProposal → Maybe Ix | ||
| indexOfGuard : TxId × ScriptHash → ℙ (TxId × ScriptHash) → Maybe Ix | ||
|
|
||
| record AbstractFunctions : Type where | ||
| field txScriptFee : Prices → ExUnits → Fees | ||
| serializedSize : Value → MemoryEstimate | ||
| indexOfImp : indexOf | ||
| runPLCScript : CostModel → P2Script → ExUnits → List Data → Bool | ||
| scriptSize : Script → ℕ | ||
| ``` |
This file contains hidden or 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,14 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/Certs.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| open import Ledger.Conway.Specification.Gov.Base | ||
| using (GovStructure) | ||
|
|
||
| module Ledger.Dijkstra.Specification.Certs | ||
| (gs : GovStructure) where | ||
|
|
||
| open import Ledger.Conway.Specification.Certs gs public | ||
| ``` |
This file contains hidden or 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,13 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/Gov/Actions.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| open import Ledger.Conway.Specification.Gov.Base | ||
| using (GovStructure) | ||
| module Ledger.Dijkstra.Specification.Gov.Actions | ||
| (gs : GovStructure) where | ||
|
|
||
| open import Ledger.Conway.Specification.Gov.Actions gs public | ||
| ``` |
This file contains hidden or 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,10 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/Gov/Base.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| module Ledger.Dijkstra.Specification.Gov.Base where | ||
|
|
||
| open import Ledger.Conway.Specification.Gov.Base public | ||
| ``` |
This file contains hidden or 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,21 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/PParams.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| open import Ledger.Core.Specification.Crypto | ||
| using (CryptoStructure) | ||
| open import Ledger.Dijkstra.Specification.Script | ||
| using (ScriptStructure) | ||
| open import Ledger.Core.Specification.Epoch | ||
| using (EpochStructure) | ||
|
|
||
| module Ledger.Dijkstra.Specification.PParams | ||
| (crypto : CryptoStructure ) | ||
| (es : EpochStructure) | ||
| (ss : ScriptStructure crypto es) | ||
| where | ||
|
|
||
| open import Ledger.Conway.Specification.PParams crypto es ss public | ||
| ``` |
This file contains hidden or 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,16 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/Script.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Core.Specification.Crypto using (CryptoStructure) | ||
| open import Ledger.Core.Specification.Epoch using (EpochStructure) | ||
|
|
||
| module Ledger.Dijkstra.Specification.Script | ||
| (crypto : CryptoStructure) | ||
| (es : EpochStructure) where | ||
|
|
||
| open import Ledger.Conway.Specification.Script crypto es public | ||
| ``` |
170 changes: 170 additions & 0 deletions
170
src/Ledger/Dijkstra/Specification/Script/Validation.lagda.md
This file contains hidden or 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,170 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/Script/Validation.lagda.md | ||
| --- | ||
|
|
||
| <!-- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Dijkstra.Specification.Transaction | ||
| open import Ledger.Dijkstra.Specification.Abstract | ||
|
|
||
| module Ledger.Dijkstra.Specification.Script.Validation | ||
| (txs : _) (open TransactionStructure txs) | ||
| (abs : AbstractFunctions txs) (open AbstractFunctions abs) (open indexOf indexOfImp) | ||
| where | ||
|
|
||
| open import Ledger.Prelude | ||
| open import Ledger.Dijkstra.Specification.Certs govStructure | ||
| ``` | ||
| --> | ||
|
|
||
| ```agda | ||
| data ScriptPurpose : Type where | ||
| Cert : DCert → ScriptPurpose | ||
| Rwrd : RewardAddress → ScriptPurpose | ||
| Mint : ScriptHash → ScriptPurpose | ||
| Spend : TxIn → ScriptPurpose | ||
| Vote : GovVoter → ScriptPurpose | ||
| Propose : GovProposal → ScriptPurpose | ||
| Guard : (TxId × ScriptHash) → ScriptPurpose | ||
| ``` | ||
|
|
||
| <!-- | ||
| ```agda | ||
| private variable | ||
| ℓ : TxLevel | ||
|
|
||
| rdptr : (Tx ℓ) → ScriptPurpose → Maybe (RedeemerPtr ℓ) | ||
| rdptr tx = λ where | ||
| (Cert h) → map (Cert ,_) $ indexOfDCert h txCerts | ||
| (Rwrd h) → map (Reward ,_) $ indexOfRwdAddr h txWithdrawals | ||
| (Mint h) → map (Mint ,_) $ indexOfPolicyId h (policies mint) | ||
| (Spend h) → map (Spend ,_) $ indexOfTxIn h txIns | ||
| (Vote h) → map (Vote ,_) $ indexOfVote h (map GovVote.voter txGovVotes) | ||
| (Propose h) → map (Propose ,_) $ indexOfProposal h txGovProposals | ||
| (Guard h) → map (Guard ,_) $ indexOfGuard h (getTxScripts tx) | ||
| where open TxBody (TxBodyOf tx) | ||
| -- getSubTxScripts : TopLevelTx → ℙ (TxId × ScriptHash) | ||
|
|
||
| indexedRdmrs : (Tx ℓ) → ScriptPurpose → Maybe (Redeemer × ExUnits) | ||
| indexedRdmrs tx sp = maybe (λ x → lookupᵐ? txRedeemers x) nothing (rdptr tx sp) | ||
| where open Tx tx; open TxWitnesses txWitnesses | ||
|
|
||
| getDatum : Tx ℓ → UTxO → ScriptPurpose → Maybe Datum | ||
| getDatum tx utxo (Spend txin) = | ||
| do (_ , _ , just d , _) ← lookupᵐ? utxo txin where | ||
| (_ , _ , nothing , _) → nothing | ||
| case d of λ where | ||
| (inj₁ d) → just d | ||
| (inj₂ h) → lookupᵐ? (setToMap (mapˢ < hash , id > (DataOf tx))) h | ||
| getDatum tx utxo _ = nothing | ||
| ``` | ||
| --> | ||
|
|
||
| ```agda | ||
| record TxInfo : Type where | ||
| field realizedInputs : UTxO | ||
| txOuts : Ix ⇀ TxOut | ||
| txFee : Maybe Fees | ||
| mint : Value | ||
| txCerts : List DCert | ||
| txWithdrawals : Withdrawals | ||
| txVldt : Maybe Slot × Maybe Slot | ||
| vkKey : ℙ KeyHash | ||
| txData : ℙ Datum | ||
| txId : TxId | ||
|
|
||
|
|
||
| txInfo : (ℓ : TxLevel) → UTxO → Tx ℓ → TxInfo | ||
|
|
||
| txInfo TxLevelTop utxo tx = | ||
| record { realizedInputs = utxo ∣ txIns | ||
| ; txOuts = txOuts | ||
| ; txFee = just txFee | ||
| ; mint = mint | ||
| ; txCerts = txCerts | ||
| ; txWithdrawals = txWithdrawals | ||
| ; txVldt = txVldt | ||
| ; vkKey = txRequiredGuards -- ? | ||
| ; txData = DataOf tx | ||
| ; txId = txId | ||
| } where open Tx tx; open TxBody txBody | ||
|
|
||
| txInfo TxLevelSub utxo tx = | ||
| record { realizedInputs = utxo ∣ txIns | ||
| ; txOuts = txOuts | ||
| ; txFee = nothing | ||
| ; mint = mint | ||
| ; txCerts = txCerts | ||
| ; txWithdrawals = txWithdrawals | ||
| ; txVldt = txVldt | ||
| ; vkKey = txRequiredGuards -- ? | ||
| ; txData = DataOf tx | ||
| ; txId = txId | ||
| } where open Tx tx; open TxBody txBody | ||
| ``` | ||
|
|
||
| <!-- | ||
| ```agda | ||
| credsNeededMinusCollateral : {ℓ : TxLevel} → TxBody ℓ → ℙ (ScriptPurpose × Credential) | ||
| credsNeededMinusCollateral txb = a ∪ b ∪ c ∪ d ∪ e | ||
| where | ||
| a b c d e : ℙ (ScriptPurpose × Credential) | ||
| a = mapˢ (λ a → (Rwrd a , CredentialOf a)) (dom ∣ WithdrawalsOf txb ∣) | ||
| b = mapPartial (λ c → (Cert c ,_) <$> cwitness c) (fromList (DCertsOf txb)) | ||
| c = mapˢ (λ x → (Mint x , ScriptObj x)) (policies (ValueOf txb)) | ||
| d = mapPartial (λ v → if isGovVoterCredential v then (λ {c} → just (Vote v , c)) else nothing) | ||
| (fromList (map GovVoterOf (GovVotesOf txb))) | ||
| e = mapPartial (λ p → if PolicyOf p then (λ {sh} → just (Propose p , ScriptObj sh)) else nothing) | ||
| (fromList (GovProposalsOf txb)) | ||
|
|
||
| credsNeeded : (ℓ : TxLevel) → UTxO → (TxBody ℓ) → ℙ (ScriptPurpose × Credential) | ||
| credsNeeded TxLevelTop utxo txb = credsNeededMinusCollateral txb | ||
| ∪ mapˢ (λ (i , o) → (Spend i , payCred (proj₁ o))) ((utxo ∣ (txIns ∪ collateralInputs)) ˢ) | ||
| where open TxBody txb | ||
|
|
||
| credsNeeded TxLevelSub utxo txb = credsNeededMinusCollateral txb | ||
| ∪ mapˢ (λ (i , o) → (Spend i , payCred (proj₁ o))) ((utxo ∣ txIns) ˢ) | ||
| where open TxBody txb | ||
|
|
||
| valContext : TxInfo → ScriptPurpose → Data | ||
| valContext txinfo sp = toData (txinfo , sp) | ||
|
|
||
| txOutToDataHash : TxOut → Maybe DataHash | ||
| txOutToDataHash (_ , _ , d , _) = d >>= isInj₂ | ||
|
|
||
| txOutToP2Script | ||
| : UTxO → (Tx ℓ) | ||
| → TxOut → Maybe P2Script | ||
| txOutToP2Script utxo tx (a , _) = | ||
| do sh ← isScriptObj (payCred a) | ||
| s ← lookupScriptHash sh tx utxo | ||
| toP2Script s | ||
| -- opaque | ||
| -- collectP2ScriptsWithContext | ||
| -- : PParams → (Tx ℓ) → UTxO | ||
| -- → List (P2Script × List Data × ExUnits × CostModel) | ||
| -- collectP2ScriptsWithContext pp tx utxo | ||
| -- = setToList | ||
| -- $ mapPartial (λ (sp , c) → if isScriptObj c | ||
| -- then (λ {sh} → toScriptInput sp sh) | ||
| -- else nothing) | ||
| -- $ credsNeeded utxo (TxBodyOf tx) | ||
| -- where | ||
| -- toScriptInput | ||
| -- : ScriptPurpose → ScriptHash | ||
| -- → Maybe (P2Script × List Data × ExUnits × CostModel) | ||
| -- toScriptInput sp sh = | ||
| -- do s ← lookupScriptHash sh tx utxo | ||
| -- p2s ← toP2Script s | ||
| -- (rdmr , exunits) ← indexedRdmrs tx sp | ||
| -- let data' = maybe [_] [] (getDatum tx utxo sp) ++ rdmr ∷ [ valContext (txInfo (language p2s) pp utxo tx) sp ] | ||
| -- costModel = PParams.costmdls pp | ||
| -- just (p2s , data' , exunits , costModel) | ||
|
|
||
| evalP2Scripts : List (P2Script × List Data × ExUnits × CostModel) → Bool | ||
| evalP2Scripts = all (λ (s , d , eu , cm) → runPLCScript cm s eu d) | ||
| ``` | ||
| --> |
11 changes: 11 additions & 0 deletions
11
src/Ledger/Dijkstra/Specification/TokenAlgebra/Base.lagda.md
This file contains hidden or 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,11 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Dijkstra/Specification/TokenAlgebra/Base.lagda.md | ||
| --- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
| open import Prelude using (Type) | ||
| module Ledger.Dijkstra.Specification.TokenAlgebra.Base (PolicyId : Type) where | ||
|
|
||
| open import Ledger.Conway.Specification.TokenAlgebra.Base PolicyId public | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.