-
Notifications
You must be signed in to change notification settings - Fork 20
Adding Example Smart Contracts and Traces. #955
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
base: master
Are you sure you want to change the base?
Changes from all commits
c72d606
fc12e15
6319b75
bfe047b
13666bd
9faef0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the contents of this file relate to scripts I suggest to move it to the Script folder.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @carlostome I think the first option will create a cyclic module dependency so we could either go with the second option, or we could simply move the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- | ||
| source_branch: master | ||
| source_path: src/Ledger/Conway/Specification/Script/ScriptPurpose.lagda.md | ||
| --- | ||
|
|
||
| # Script Purpose {#sec:script-purpose} | ||
|
|
||
| <!-- | ||
| ```agda | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Conway.Specification.Transaction | ||
|
|
||
| module Ledger.Conway.Specification.Script.ScriptPurpose (txs : TransactionStructure) where | ||
|
|
||
| open import Ledger.Prelude | ||
| open TransactionStructure txs | ||
| open import Ledger.Conway.Specification.Certs govStructure | ||
| ``` | ||
| --> | ||
|
|
||
| ```agda | ||
| data ScriptPurpose : Type where | ||
| Cert : DCert → ScriptPurpose | ||
| Rwrd : RwdAddr → ScriptPurpose | ||
| Mint : ScriptHash → ScriptPurpose | ||
| Spend : TxIn → ScriptPurpose | ||
| Vote : GovVoter → ScriptPurpose | ||
| Propose : GovProposal → ScriptPurpose | ||
|
|
||
| record TxInfo : Type where | ||
| field realizedInputs : UTxO | ||
| txOuts : Ix ⇀ TxOut | ||
| fee : Value | ||
| mint : Value | ||
| txCerts : List DCert | ||
| txWithdrawals : Withdrawals | ||
| txVldt : Maybe Slot × Maybe Slot | ||
| vkKey : ℙ KeyHash | ||
| txdats : ℙ Datum | ||
| txId : TxId | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,8 @@ module Ledger.Conway.Specification.Script.Validation | |
| open import Ledger.Prelude | ||
| open import Ledger.Conway.Specification.Certs govStructure | ||
|
|
||
| data ScriptPurpose : Type where | ||
| Cert : DCert → ScriptPurpose | ||
| Rwrd : RwdAddr → ScriptPurpose | ||
| Mint : ScriptHash → ScriptPurpose | ||
| Spend : TxIn → ScriptPurpose | ||
| Vote : GovVoter → ScriptPurpose | ||
| Propose : GovProposal → ScriptPurpose | ||
| open import Ledger.Conway.Specification.Abstract txs | ||
| open import Ledger.Conway.Specification.Script.ScriptPurpose txs | ||
|
|
||
| rdptr : TxBody → ScriptPurpose → Maybe RdmrPtr | ||
| rdptr txb = λ where | ||
|
|
@@ -51,18 +46,6 @@ getDatum tx utxo (Spend txin) = | |
| m = setToMap (mapˢ < hash , id > (TxWitnesses.txdats (Tx.wits tx))) | ||
| getDatum tx utxo _ = nothing | ||
|
|
||
| record TxInfo : Type where | ||
| field realizedInputs : UTxO | ||
| txOuts : Ix ⇀ TxOut | ||
| fee : Value | ||
| mint : Value | ||
| txCerts : List DCert | ||
| txWithdrawals : Withdrawals | ||
| txVldt : Maybe Slot × Maybe Slot | ||
| vkKey : ℙ KeyHash | ||
| txdats : ℙ Datum | ||
| txId : TxId | ||
|
|
||
| txInfo : Language → PParams | ||
| → UTxO | ||
| → Tx | ||
|
|
@@ -92,8 +75,8 @@ credsNeeded utxo txb | |
| open RwdAddr | ||
| open GovProposal | ||
|
|
||
| valContext : TxInfo → ScriptPurpose → Data | ||
| valContext txinfo sp = toData (txinfo , sp) | ||
| -- valContext : TxInfo → ScriptPurpose → Data | ||
| -- valContext txinfo sp = toData (txinfo , sp) | ||
|
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these lines commented out? |
||
|
|
||
| txOutToDataHash : TxOut → Maybe DataHash | ||
| txOutToDataHash (_ , _ , d , _) = d >>= isInj₂ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Prelude using (DecEq; Show) | ||
| import Ledger.Conway.Specification.Script.ScriptPurpose as SP | ||
| open import Ledger.Conway.Specification.Test.LedgerImplementation using (SVTransactionStructure) | ||
|
|
||
| module Ledger.Conway.Specification.Test.AbstractImplementation | ||
| {T D : Set} {{DecEq-Data : DecEq D}} {{Show-Data : Show D}} | ||
| (open SP (SVTransactionStructure T D) using (TxInfo; ScriptPurpose)) | ||
| (valContext' : TxInfo → ScriptPurpose → D) | ||
| where | ||
|
|
||
| open import Ledger.Prelude using (nothing; _,_) | ||
|
|
||
| open import Ledger.Conway.Specification.Test.LedgerImplementation T D | ||
| renaming (SVTransactionStructure to SVTransactionStructure') | ||
| open import Ledger.Conway.Specification.Abstract SVTransactionStructure' | ||
|
|
||
| open Implementation | ||
|
|
||
| SVAbstractFunctions : AbstractFunctions | ||
| SVAbstractFunctions = record | ||
| { Implementation | ||
| ; txscriptfee = λ tt y → 0 | ||
| ; serSize = λ v → 0 -- changed to 0 | ||
| ; indexOfImp = record | ||
| { indexOfDCert = λ _ _ → nothing | ||
| ; indexOfRwdAddr = λ _ _ → nothing | ||
| ; indexOfTxIn = indexOfTxInImp | ||
| ; indexOfPolicyId = λ _ _ → nothing | ||
| ; indexOfVote = λ _ _ → nothing | ||
| ; indexOfProposal = λ _ _ → nothing | ||
| } | ||
| ; runPLCScript = λ { x (sh , script) x₂ x₃ → script x₃ } | ||
| ; scriptSize = λ _ → 0 | ||
| ; valContext = valContext' | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| module Ledger.Conway.Specification.Test.Examples where | ||
|
|
||
| import Ledger.Conway.Specification.Test.Examples.SucceedIfNumber | ||
| import Ledger.Conway.Specification.Test.Examples.HelloWorld | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSig.Datum | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSig.Validator | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSig.Test.Trace | ||
| import Ledger.Conway.Specification.Test.Examples.AccountSim.Datum | ||
| import Ledger.Conway.Specification.Test.Examples.AccountSim.Validator | ||
| import Ledger.Conway.Specification.Test.Examples.AccountSim.Test.Trace | ||
| import Ledger.Conway.Specification.Test.Examples.DEx.Datum | ||
| import Ledger.Conway.Specification.Test.Examples.DEx.Validator | ||
| import Ledger.Conway.Specification.Test.Examples.DEx.Test.Trace | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSigV2.Datum | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSigV2.Validator | ||
| import Ledger.Conway.Specification.Test.Examples.MultiSigV2.Test.Trace |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| open import Ledger.Prelude hiding (fromList; ε); open Computational | ||
|
|
||
| module Ledger.Conway.Specification.Test.Examples.AccountSim.Datum where | ||
|
|
||
| open import Tactic.Derive.DecEq | ||
| open import Data.Vec as Vec | ||
| hiding (fromList) | ||
| import stdlib.Data.Vec.Instances as Vec | ||
| import Data.Vec.Relation.Binary.Pointwise.Inductive as Vec | ||
|
|
||
| data Label : Set where | ||
| Always : List (ℕ × ℕ) -> Label | ||
| instance | ||
| unquoteDecl DecEq-Label = derive-DecEq | ||
| ((quote Label , DecEq-Label) ∷ []) | ||
|
|
||
| data Input : Set where | ||
| Open : ℕ -> Input | ||
| Close : ℕ -> Input | ||
| Withdraw : ℕ -> ℕ -> Input | ||
| Deposit : ℕ -> ℕ -> Input | ||
| Transfer : ℕ -> ℕ -> ℕ -> Input | ||
| Cleanup : Input | ||
| instance | ||
| unquoteDecl DecEq-Input = derive-DecEq | ||
| ((quote Input , DecEq-Input) ∷ []) | ||
|
|
||
| AccountSimData = Label ⊎ Input |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| module Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Cleanup where | ||
|
|
||
| open import Ledger.Prelude | ||
| open import Ledger.Conway.Specification.Transaction | ||
|
|
||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Datum | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Lib | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Validator | ||
| open import Ledger.Conway.Specification.Test.Prelude AccountSimData | ||
| open import Ledger.Conway.Specification.Test.SymbolicData AccountSimData | ||
| open import Ledger.Conway.Specification.Test.LedgerImplementation SData SData | ||
| open import Ledger.Conway.Specification.Test.AbstractImplementation valContext | ||
| open import Ledger.Conway.Specification.Test.Lib valContext | ||
|
|
||
| open import Ledger.Conway.Specification.Utxo SVTransactionStructure SVAbstractFunctions | ||
|
|
||
| open TransactionStructure SVTransactionStructure | ||
| open Implementation | ||
|
|
||
| makeCleanupTx : (id : ℕ) → UTxOState → PlutusScript → (w : ℕ) → Maybe Tx | ||
| makeCleanupTx id state script@(sh , _) w = | ||
| let | ||
| wutxo = getWalletUTxO w (UTxOState.utxo state) | ||
| in | ||
| maybe (λ { (scIn , (fst , txValue , snd)) → | ||
| just ( | ||
| record { body = record defaultTxBody | ||
| { txIns = Ledger.Prelude.fromList ((scIn ∷ []) ++ (map proj₁ wutxo)) | ||
| ; txOuts = fromListIx (makeFeeUnPaymentTxOut wutxo txValue) | ||
| ; txId = id | ||
| ; collateralInputs = Ledger.Prelude.fromList (map proj₁ wutxo) | ||
| ; reqSignerHashes = Ledger.Prelude.fromList (w ∷ []) | ||
| } ; | ||
| wits = record { vkSigs = fromListᵐ ((w , (_+_ {{addNat}} (getTxId wutxo) w) ) ∷ []) ; | ||
| scripts = Ledger.Prelude.fromList ((inj₂ script) ∷ []) ; | ||
| txdats = ∅ ; | ||
| txrdmrs = fromListᵐ (((Spend , (proj₂ scIn)) , | ||
| inj₁ (inj₂ Cleanup) , | ||
| ((getTxId wutxo) , w)) ∷ []) } ; | ||
| txsize = 10 ; | ||
| isValid = true ; | ||
| txAD = nothing } | ||
| ) | ||
| }) | ||
| nothing | ||
| (getScriptUTxO sh (UTxOState.utxo state)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| module Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Close where | ||
|
|
||
| open import Ledger.Prelude | ||
| open import Ledger.Conway.Specification.Transaction | ||
|
|
||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Datum | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Validator | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Lib | ||
| open import Ledger.Conway.Specification.Test.Prelude AccountSimData | ||
| open import Ledger.Conway.Specification.Test.SymbolicData AccountSimData | ||
| open import Ledger.Conway.Specification.Test.LedgerImplementation SData SData | ||
| open import Ledger.Conway.Specification.Test.AbstractImplementation valContext | ||
| open import Ledger.Conway.Specification.Test.Lib valContext | ||
|
|
||
| open import Ledger.Conway.Specification.Utxo SVTransactionStructure SVAbstractFunctions | ||
|
|
||
| open TransactionStructure SVTransactionStructure | ||
| open Implementation | ||
|
|
||
|
|
||
| makeCloseTxOut : Label → (scriptIx w : ℕ) → TxOut → List (ℕ × TxOut) | ||
| makeCloseTxOut (Always l) ix w (fst , fst' , snd) = | ||
| (ix , (fst , fst' , just (inj₁ (inj₁ (inj₁ (Always (delete' w l))))) , nothing)) ∷ [] | ||
|
|
||
| makeCloseTx : (id : ℕ) → UTxOState → PlutusScript → (w : ℕ) → Maybe Tx | ||
| makeCloseTx id state script@(sh , _) w = | ||
| let | ||
| wutxo = getWalletUTxO w (UTxOState.utxo state) | ||
| in | ||
| maybe (λ { (scIn , scOut) → maybe (λ label → | ||
| just ( | ||
| record { body = record defaultTxBody | ||
| { txIns = Ledger.Prelude.fromList ((scIn ∷ []) ++ (map proj₁ wutxo)) | ||
| ; txOuts = fromListIx (makeFeeTxOut wutxo ++ makeCloseTxOut label (proj₂ scIn) w scOut ) | ||
| ; txId = id | ||
| ; collateralInputs = Ledger.Prelude.fromList (map proj₁ wutxo) | ||
| ; reqSignerHashes = Ledger.Prelude.fromList (w ∷ []) | ||
| } ; | ||
| wits = record { vkSigs = fromListᵐ ((w , (_+_ {{addNat}} (getTxId wutxo) w) ) ∷ []) ; | ||
| scripts = Ledger.Prelude.fromList ((inj₂ script) ∷ []) ; | ||
| txdats = ∅ ; | ||
| txrdmrs = fromListᵐ (((Spend , (proj₂ scIn)) , | ||
| inj₁ (inj₂ (Close w)) , | ||
| ((getTxId wutxo) , w)) ∷ []) } ; | ||
| txsize = 10 ; | ||
| isValid = true ; | ||
| txAD = nothing } | ||
| )) | ||
| nothing | ||
| (getLabel scOut)}) | ||
| nothing | ||
| (getScriptUTxO sh (UTxOState.utxo state)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| {-# OPTIONS --safe #-} | ||
|
|
||
| module Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Deposit where | ||
|
|
||
| open import Ledger.Prelude | ||
| open import Ledger.Conway.Specification.Transaction | ||
|
|
||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Datum | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.OffChain.Lib | ||
| open import Ledger.Conway.Specification.Test.Examples.AccountSim.Validator | ||
| open import Ledger.Conway.Specification.Test.Prelude AccountSimData | ||
| open import Ledger.Conway.Specification.Test.SymbolicData AccountSimData | ||
| open import Ledger.Conway.Specification.Test.LedgerImplementation SData SData | ||
| open import Ledger.Conway.Specification.Test.AbstractImplementation valContext | ||
| open import Ledger.Conway.Specification.Test.Lib valContext | ||
|
|
||
| open import Ledger.Conway.Specification.Utxo SVTransactionStructure SVAbstractFunctions | ||
|
|
||
| open TransactionStructure SVTransactionStructure | ||
| open Implementation | ||
|
|
||
| scriptDTxOut : Label → TxOut → (w : ℕ) → (v : Value) → TxOut | ||
| scriptDTxOut (Always l) (fst , txValue , snd) w v = (fst , (_+_ {{addValue}} txValue v) , (just (inj₁ (inj₁ (inj₁ (Always (insert' w (_+_ {{addValue}} val v) l)))))) , nothing) | ||
| where | ||
| val = getVal (Always l) w | ||
|
|
||
|
|
||
|
|
||
| makeDepositTxOut : Label → (scriptIx : ℕ) → TxOut → (w : ℕ) → (v : Value) → List (ℕ × TxOut) | ||
| makeDepositTxOut (Always l) ix txo w v = | ||
| (ix , scriptDTxOut (Always l) txo w v) | ||
| ∷ [] | ||
|
|
||
|
|
||
|
|
||
| makeDepositTx : (id : ℕ) → UTxOState → PlutusScript → (w : ℕ) → (v : Value) → Maybe Tx | ||
| makeDepositTx id state script@(sh , _) w v = | ||
| let | ||
| wutxo = getWalletUTxO w (UTxOState.utxo state) | ||
| in | ||
| maybe (λ { (scIn , scOut) → maybe (λ label → | ||
| just ( | ||
| record { body = record defaultTxBody | ||
| { txIns = Ledger.Prelude.fromList ((scIn ∷ []) ++ (map proj₁ wutxo)) | ||
| ; txOuts = fromListIx (makeFeePaymentTxOut wutxo v ++ makeDepositTxOut label (proj₂ scIn) scOut w v ) | ||
| ; txId = id | ||
| ; collateralInputs = Ledger.Prelude.fromList (map proj₁ wutxo) | ||
| ; reqSignerHashes = Ledger.Prelude.fromList (w ∷ []) | ||
| } ; | ||
| wits = record { vkSigs = fromListᵐ ((w , (_+_ {{addNat}} (getTxId wutxo) w)) ∷ []) ; | ||
| scripts = Ledger.Prelude.fromList ((inj₂ script) ∷ []) ; | ||
| txdats = ∅ ; | ||
| txrdmrs = fromListᵐ (((Spend , (proj₂ scIn)) , | ||
| inj₁ (inj₂ (Deposit w v)) , | ||
| ((getTxId wutxo) , w)) ∷ []) } ; | ||
| txsize = 10 ; | ||
| isValid = true ; | ||
| txAD = nothing } | ||
| )) | ||
| nothing | ||
| (getLabel scOut)}) | ||
| nothing | ||
| (getScriptUTxO sh (UTxOState.utxo state)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this commented out?