From 7a56bfd3fb6556b109f9b7f95349be0bbf524f93 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Wed, 2 Mar 2022 20:30:32 +0100 Subject: [PATCH 1/7] flake: add graphviz --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 103fea2..ca4ede1 100644 --- a/flake.nix +++ b/flake.nix @@ -60,6 +60,7 @@ pkgs'.hlint pkgs'.haskellPackages.cabal-fmt pkgs'.nixpkgs-fmt + pkgs'.graphviz ]; inherit (plutarch) tools; From 13d7089021edba30f453ab57deea3cd37e72ecfb Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Wed, 2 Mar 2022 20:46:22 +0100 Subject: [PATCH 2/7] update overview diagram --- docs/diagrams/gov-overview.dot | 5 +- docs/diagrams/gov-overview.svg | 127 +++++++++++++++------------------ 2 files changed, 59 insertions(+), 73 deletions(-) diff --git a/docs/diagrams/gov-overview.dot b/docs/diagrams/gov-overview.dot index 5b1ab3c..0ee05d6 100644 --- a/docs/diagrams/gov-overview.dot +++ b/docs/diagrams/gov-overview.dot @@ -1,8 +1,7 @@ digraph { - "Staking pool" -> Stakes [label="tracks"] - Stakes -> Proposals [label="are put on"] + Stakes -> Proposals [label="vote on"] Proposals -> Effects [label="have"] Governor -> Effects [label="issues GATs to"] Users -> Stakes [label="lock GT in"] - Users -> Treasury [label="claim GT from"] + Effects -> Treasury [label="release GT from"] } diff --git a/docs/diagrams/gov-overview.svg b/docs/diagrams/gov-overview.svg index 008d286..b52362d 100644 --- a/docs/diagrams/gov-overview.svg +++ b/docs/diagrams/gov-overview.svg @@ -1,96 +1,83 @@ - - - - - - -Staking pool - -Staking pool - + + + - + Stakes - -Stakes - - - -Staking pool->Stakes - - -tracks + +Stakes - + Proposals - -Proposals + +Proposals - + Stakes->Proposals - - -are put on + + +vote on - + Effects - -Effects + +Effects - + Proposals->Effects - - -have - - - -Governor - -Governor - - - -Governor->Effects - - -issues GATs to - - - -Users - -Users - - - -Users->Stakes - - -lock GT in + + +have - + Treasury - -Treasury + +Treasury - - -Users->Treasury - - -claim GT from + + +Effects->Treasury + + +release GT from + + + +Governor + +Governor + + + +Governor->Effects + + +issues GATs to + + + +Users + +Users + + + +Users->Stakes + + +lock GT in From 51cdba2ddf8d1690c65951a052394bcbba188908 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Wed, 2 Mar 2022 21:23:24 +0100 Subject: [PATCH 3/7] add section on destroying Stake in tech-design --- README.md | 6 +----- docs/tech-design/staking-pool.md | 6 +++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 35870f8..a0f2905 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Non-goals: An up to date version of the [Nix package manager](nixos.org) (>=2.3) is required to build this project. For information on how to install, see the [NixOS website](https://nixos.org/download.html). Important: see also [this section](https://github.com/input-output-hk/plutus#nix-advice) on binary caches. -Open a development shell with `nix develop` and build the project with `cabal build`. Those pained by the need to remember to enter a Nix shell may consider using [nix-direnv](https://github.com/nix-community/nix-direnv). +Open a development shell with `nix develop` and build the project with `cabal build`. Those pained by the need to remember to enter a Nix shell may consider using [nix-direnv](https://github.com/nix-community/nix-direnv). ## Documentation @@ -88,10 +88,6 @@ The treasury of a governance system is responsible for determining which users a Users are required to 'lock' their GT in stakes, so that the system has some idea of their eligibility to vote on proposal. -### Staking pool - -A staking pool can be introduced, for the purpose of tracking the aggregate status of all stakes in the system. Some systems may not require a staking pool. - ### Proposal A proposal suggests for some specified changes to be made to a Cardano system. It is voted upon by the community and, if passed, its effects are applied to the system. diff --git a/docs/tech-design/staking-pool.md b/docs/tech-design/staking-pool.md index 2262bbb..bb9c569 100644 --- a/docs/tech-design/staking-pool.md +++ b/docs/tech-design/staking-pool.md @@ -47,7 +47,7 @@ stake.lockedByProposals += (hash proposal.settings, vote) This forms a mutual binding between the proposal and the stake. -A stake may be used to vote on an unlimited number of proposals. Consider a user staking 50GT. They may pledge that 50GT against a proposal `p` _and_ another proposal `p'`. +A stake may be used to vote on an unlimited number of proposals. Consider a user staking 50GT. They may pledge that 50GT against a proposal `p` _and_ another proposal `q`. Altering the amount positioned in a stake is not possible, for as long as that stake is locked against any proposals. This is to prevent vote manipulation. Consider: @@ -78,6 +78,10 @@ data Stake = Stake When voting on a proposal, a user can check which stakes have delegated to them off-chain and include them in the voting transaction. _This will lock the delegator's stake_, however they will be themselves be able to unlock it as usual. It should be noted that delegation of stakes only extends to voting on proposals and not, for example, withdrawing GT from a stake. +## Destroying stake + +In order to recover the ADA and potentially any other funds sent on accident, Stake UTXOs must be destroyable. + ## Staking pool There are a number of reasons that a protocol would wish to track the global state of stakes in its system. For example, a protocol may wish to implement a proposal system where a certain proportion of the globally available GT must be staked in-favour of a proposal, in order to allow it to pass. This is the equivalent of mandating a certain voter turnout be met in a national referendum. The ability to do such a thing is conferred by the creation of a _staking pool_. From 93c3f700b8d79226b0767b3b6f154b5140c86a91 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Wed, 2 Mar 2022 21:23:40 +0100 Subject: [PATCH 4/7] add signer assertion to Stake validator --- src/Agora/Stake.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Agora/Stake.hs b/src/Agora/Stake.hs index a4dcc24..74a4c65 100644 --- a/src/Agora/Stake.hs +++ b/src/Agora/Stake.hs @@ -215,6 +215,7 @@ stakeValidator stake = PJust txInInfo <- pmatch $ pfindTxInByTxOutRef # (pfield @"_0" # txOutRef) # txInfo' ownAddress <- plet $ pfield @"address" #$ pfield @"resolved" # txInInfo let continuingValue = pfield @"value" #$ pfield @"resolved" # txInInfo + ownerSignsTransaction <- plet $ ptxSignedBy # ctx.txInfo # stakeDatum.owner stCurrencySymbol <- plet $ pconstant $ mintingPolicySymbol $ mkMintingPolicy (stakePolicy stake) mintedST <- plet $ psymbolValueOf # stCurrencySymbol # txInfo.mint spentST <- plet $ psymbolValueOf # stCurrencySymbol #$ pvalueSpent # txInfo' @@ -227,12 +228,16 @@ stakeValidator stake = mintedST #== -1 passert "Stake unlocked" $ pnot #$ stakeLocked # stakeDatum' + passert "Owner signs this transaction" $ + ownerSignsTransaction popaque (pconstant ()) PDepositWithdraw r -> P.do passert "ST at inputs must be 1" $ spentST #== 1 passert "Stake unlocked" $ pnot #$ stakeLocked # stakeDatum' + passert "Owner signs this transaction" $ + ownerSignsTransaction passert "A UTXO must exist with the correct output" $ anyOutput @(PStakeDatum gt) # txInfo' #$ plam From 0e045d6f106cf8f5e6568e88068d3fcef18058c9 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Thu, 3 Mar 2022 14:03:33 +0100 Subject: [PATCH 5/7] elaborate Stake destruction --- docs/tech-design/staking-pool.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tech-design/staking-pool.md b/docs/tech-design/staking-pool.md index bb9c569..2e1e35f 100644 --- a/docs/tech-design/staking-pool.md +++ b/docs/tech-design/staking-pool.md @@ -80,7 +80,7 @@ When voting on a proposal, a user can check which stakes have delegated to them ## Destroying stake -In order to recover the ADA and potentially any other funds sent on accident, Stake UTXOs must be destroyable. +In order to recover the ADA and potentially any other funds sent on accident, Stake UTXOs must be destroyable. For the same reasons as for withdrawing and depositing, the Stake must not be locked by a proposal when destroying it. ## Staking pool From af06b8fb51c6a32e34d6f6195df820a3538fb455 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Thu, 3 Mar 2022 16:11:25 +0100 Subject: [PATCH 6/7] fix hlint --- src/Agora/Stake.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Agora/Stake.hs b/src/Agora/Stake.hs index 74a4c65..cc87ae8 100644 --- a/src/Agora/Stake.hs +++ b/src/Agora/Stake.hs @@ -228,7 +228,8 @@ stakeValidator stake = mintedST #== -1 passert "Stake unlocked" $ pnot #$ stakeLocked # stakeDatum' - passert "Owner signs this transaction" $ + passert + "Owner signs this transaction" ownerSignsTransaction popaque (pconstant ()) PDepositWithdraw r -> P.do @@ -236,7 +237,8 @@ stakeValidator stake = spentST #== 1 passert "Stake unlocked" $ pnot #$ stakeLocked # stakeDatum' - passert "Owner signs this transaction" $ + passert + "Owner signs this transaction" ownerSignsTransaction passert "A UTXO must exist with the correct output" $ anyOutput @(PStakeDatum gt) # txInfo' From 20ae854bde44dda85a8829f7923101209fe8b688 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Fri, 4 Mar 2022 14:11:46 +0100 Subject: [PATCH 7/7] reword destroying staking pool section with Jack's suggestion --- docs/tech-design/staking-pool.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/tech-design/staking-pool.md b/docs/tech-design/staking-pool.md index 2e1e35f..200a807 100644 --- a/docs/tech-design/staking-pool.md +++ b/docs/tech-design/staking-pool.md @@ -80,7 +80,8 @@ When voting on a proposal, a user can check which stakes have delegated to them ## Destroying stake -In order to recover the ADA and potentially any other funds sent on accident, Stake UTXOs must be destroyable. For the same reasons as for withdrawing and depositing, the Stake must not be locked by a proposal when destroying it. +In order to recover the ADA spent on creating the stake UTXO (and any other funds, which may have been locked by accident), stake UTXOs must be destroyable. As is the case with the depositing and withdrawal of GT from a stake, the stake must *not* be locked by any proposals, before it may be destroyed. + ## Staking pool