privgov, Fairblock’s encrypted voting module, into a Cosmos SDK chain so proposals can be decided by private, tamper-resistant votes.
A walkthrough of this tutorial, alongside context on Fairblock, EVMs, and Cosmos chains, is provided in the video below. If you prefer reading, feel free to skip it and continue below.
privgov tutorial covers a subset of the FairyKit methods available for Cosmos integration with Fairblock. Specifically, it is a combination of the underlying application logic and a mixture of the x/pep module details, that collectively construct today’s privgov integration package.
Again, at a more granular level, Cosmos FairyKit integrates using the following one or more of the following methods:
- Module Integration
- Smart Contract Integration
- Underlying Execution Logic Integration
- A Combination of Any of the Above
privgov.
An Intro to privgov
In today’s tutorial, we will be covering the usage of privgov, a blockchain built using Cosmos SDK and Tendermint, and a mixture of the x/pep module created with Ignite CLI. It is a basic working cosmos chain that uses the Fairblock/cosmos-sdk to enable private governance.
Governance is an important aspect within blockchains. In the Cosmos ecosystems, we can see challenges with today’s solutions including:
- Colluding parties
- Social and monetary pressures for people to vote a certain way
privgov repo was created to showcase an easy-to-use solution to incorporate truly fair, and credible governance systems. Using privgov in a Cosmos chain enables encrypted voting, getting these systems closer to true democracy.
The core code outlined in the next section can be incorporated into your own Cosmos chain such that
privgov enables encrypted voting.Integrating privgov into a Cosmos SDK Project
The core logic for privgov can be incorporated into your own Cosmos SDK project by following these steps.
- Add the following in the
replaceclause of yourgo.modfile:
go.mod change details and reasoning
go.mod change details and reasoning
The reasoning for each of the above changes made within the
go.mod file include:cosmossdk-api v0.7.5→ we replaced it with our fork of the API, because the other one is not maintained well. The version that comes with the default backend is backdated, and typically had to update it manually for our case.keyring v1.2.0→ there’s a bug in the keyring repo. We are using a different fork by cosmos themselves and we are just replacing it with this specific version.- wasmd, fairyring, cosmos-sdk - FairyRing specific
wasmd v0.50.6-fairyring- The default
wasmdhas dependencies on the default gov module. - Now,
wasmdhas dependencies on the priv-vgov module. since it is a modified gov module. - need to replace the wasmd module with the FairyRing one.
fairyring v0.10.2- Within
go.mod, under direct dependencies, there is already a dependency plotted forfaiyring. We have put the replace clause here because it is easier to maintain the proper version.
- Within
cosmos-sdk v0.50.8-fairyring-2- This is the most important change where the existing default
cosmos-sdkis replaced with the fairblock fork. - default sdk module don’t have IBC capabilities as well and do not have support for encrypted votes, processing them, etc. The Fairblock organization forked the SDK repo (and maintains it), took the gov module and made the changes / added functionalities over there. It cannot be merged with the official SDK repo.
- This is the most important change where the existing default
github.com/golang-jwt/jwt/v4 v4.4.2- If you are running an SDK chain, this should be there, the default specified one has a bug.
gin v1.9.1- we’re not changing any repo here. Easier to set because gin has frequent bugs, so it’s handy to update the version this way if it is required ever.
protobuf v1.3.3-alpha.regen.1- FairyRing is using certain clauses that are not supported by the default gogo/protobuf.
If a SDK chain is using a fork of something that then conflicts with our fork, they’ll need to have changes made to their fork accordingly too.
- The custom
govmodule has to be registered with the IBC router. To do that, simply add the route in theapp/ibc.gofile:
The route must be added to the
ibcrouter before calling the SetRouter() function.privgov functionality incorporated into your cosmos chain. Now we will continue with the tutorial to test and showcase the privgov in action.
Setting up the test environment
To set up the testing environment, simply run thepriv_gov_setup.sh file and follow along with the prompts. The script does the following things:
- Sets up and starts the fairying chain (with all its bells and whistles)
- Sets up and starts the
privgovchain - Creates a IBC channel between the FairyRing chain and privgov chain and starts the Hermes relayer
For macOS systems
If you are operating on a MacOS system, you may need to carry out the following installations to ensure that this tutorial works with your machine:- Make sure to install
ignite,hermes, andrustonto your machine. Download link and instructions for each are listed below (these assume you havehomebrewinstalled): - bash version: this tutorial requires an updated bash version compared to the default MacOS 3.x version. If it’s less than 4.x then the script will exit.
- Use
goversion 1.22.10. If you need to have multiple versions ofgoinstalled on your local machine, check out this link from thegodocs.
Proposal and Voting
A governance proposal can be created by executing the txprivgovd tx gov submit-proposal [path-to-proposal-file] --from [user] --chain-id privgov. A sample proposal file can be found in draft_proposal.json.
So to start the governance process, make a governance proposal by running the following command:
You can then use the encrypt-vote functionality to encrypt your vote. Use the bash command and details from querying the proposal, such as the identity, and pubkey to submit the tx:
Congratulations
You have successfully carried out a private governance proposal, submitted an encrypted vote, and saw that it successfully passed! Let’s recap what you’ve accomplished through this quickstart:- Shown and understood how to implement the
privgovfunctionality, using Fairblock, in your own Cosmos SDK chain. - Ran a successful private governance proposal
- Submitted successful encrypted votes to said proposal