Skip to content

Commit

Permalink
Merge pull request #2 from vitwit/vishal/modify
Browse files Browse the repository at this point in the history
Rename Modules, Update Links, and Relocate Dispatcher
  • Loading branch information
anilcse authored Dec 10, 2024
2 parents d7c4813 + 4487d96 commit d26e71d
Show file tree
Hide file tree
Showing 37 changed files with 153 additions and 150 deletions.
50 changes: 25 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,19 @@ generate-zk-keys:
.PHONY: generate-zk-keys

######################################################################
####### Relayer ############
####### dispatcher ############
######################################################################

run-alice-relayer:
zkappd tx zk-gov run-relayer --from alice --keyring-backend test --chain-id demo -y
run-bob-relayer:
zkappd tx zk-gov run-relayer --from bob --keyring-backend test --chain-id demo
run-sai-relayer:
zkappd tx zk-gov run-relayer --from sai --keyring-backend test --chain-id demo
run-teja-relayer:
zkappd tx zk-gov run-relayer --from teja --keyring-backend test --chain-id demo
run-alice-dispatcher:
zkappd tx zk-gov run-dispatcher --from alice --keyring-backend test --chain-id demo -y
run-bob-dispatcher:
zkappd tx zk-gov run-dispatcher --from bob --keyring-backend test --chain-id demo
run-charlie-dispatcher:
zkappd tx zk-gov run-dispatcher --from charlie --keyring-backend test --chain-id demo
run-david-dispatcher:
zkappd tx zk-gov run-dispatcher --from david --keyring-backend test --chain-id demo

.PHONY: run-alice-relayer run-bob-relayer run-sai-relayer run-teja-relayer
.PHONY: run-alice-dispatcher run-bob-dispatcher run-charlie-dispatcher run-david-dispatcher

######################################################################
####### Transactions ############
Expand All @@ -521,28 +521,28 @@ register-alice-vote:
zkappd tx zk-gov register-vote 1 "NO" --from alice --keyring-backend test --chain-id demo
register-bob-vote:
zkappd tx zk-gov register-vote 1 "YES" --from bob --keyring-backend test --chain-id demo
register-sai-vote:
zkappd tx zk-gov register-vote 1 "NO" --from sai --keyring-backend test --chain-id demo
register-teja-vote:
zkappd tx zk-gov register-vote 1 "YES" --from teja --keyring-backend test --chain-id demo
register-charlie-vote:
zkappd tx zk-gov register-vote 1 "NO" --from charlie --keyring-backend test --chain-id demo
register-david-vote:
zkappd tx zk-gov register-vote 1 "YES" --from david --keyring-backend test --chain-id demo

broadcast-alice-vote:
zkappd tx zk-gov vote 1 cosmos1ux2hl3y42nz6vtdl8k7t7f05k9p3r2k62zfvtv --from unknown --keyring-backend test --chain-id demo
broadcast-bob-vote:
zkappd tx zk-gov vote 1 cosmos13j3mn8n2d3scd2yy3urmw5vqhn53rej6p050np --from unknown --keyring-backend test --chain-id demo
broadcast-sai-vote:
broadcast-charlie-vote:
zkappd tx zk-gov vote 1 cosmos1mg4t0l2nc98vhjdmg6kzee5wh6uhx9jlfrgfu9 --from unknown --keyring-backend test --chain-id demo
broadcast-teja-vote:
broadcast-david-vote:
zkappd tx zk-gov vote 1 cosmos1pf0m5ch2673r6lv5lwm2mkyw433xapzx7nuemu --from unknown --keyring-backend test --chain-id demo

broadcast-alice-vote-via-relayer:
zkappd tx zk-gov vote 1 cosmos1ux2hl3y42nz6vtdl8k7t7f05k9p3r2k62zfvtv --relayer "http://localhost:8080"
broadcast-bob-vote-via-relayer:
zkappd tx zk-gov vote 1 cosmos13j3mn8n2d3scd2yy3urmw5vqhn53rej6p050np --relayer "http://localhost:8080"
broadcast-sai-vote-via-relayer:
zkappd tx zk-gov vote 1 cosmos1mg4t0l2nc98vhjdmg6kzee5wh6uhx9jlfrgfu9 --relayer "http://localhost:8080"
broadcast-teja-vote-via-relayer:
zkappd tx zk-gov vote 1 cosmos1pf0m5ch2673r6lv5lwm2mkyw433xapzx7nuemu --relayer "http://localhost:8080"
broadcast-alice-vote-via-dispatcher:
zkappd tx zk-gov vote 1 cosmos1ux2hl3y42nz6vtdl8k7t7f05k9p3r2k62zfvtv --dispatcher "http://localhost:8080"
broadcast-bob-vote-via-dispatcher:
zkappd tx zk-gov vote 1 cosmos13j3mn8n2d3scd2yy3urmw5vqhn53rej6p050np --dispatcher "http://localhost:8080"
broadcast-charlie-vote-via-dispatcher:
zkappd tx zk-gov vote 1 cosmos1mg4t0l2nc98vhjdmg6kzee5wh6uhx9jlfrgfu9 --dispatcher "http://localhost:8080"
broadcast-david-vote-via-dispatcher:
zkappd tx zk-gov vote 1 cosmos1pf0m5ch2673r6lv5lwm2mkyw433xapzx7nuemu --dispatcher "http://localhost:8080"


.PHONY: create-proposal-a create-proposal-b broadcast-alice-vote broadcast-bob-vote broadcast-sai-vote broadcast-teja-vote broadcast-alice-vote-via-relayer broadcast-bob-vote-via-relayer broadcast-sai-vote-via-relayer broadcast-teja-vote-via-relayer
.PHONY: create-proposal-a create-proposal-b broadcast-alice-vote broadcast-bob-vote broadcast-charlie-vote broadcast-david-vote broadcast-alice-vote-via-dispatcher broadcast-bob-vote-via-dispatcher broadcast-charlie-vote-via-dispatcher broadcast-david-vote-via-dispatcher
79 changes: 41 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Cosmos ZK Voting is a governance voting system designed to ensure voter anonymit
* **Anonymous Voting:** Protects voter identities using Zero-Knowledge proofs.
* **Decentralized:** Built on the Cosmos blockchain for enhanced security and scalability.
* **Secure Key Management:** Ensures the safety of prover and verifier keys.
* **Relayer Support:** Facilitates seamless vote transactions through a dedicated relayer service.
* **dispatcher Support:** Facilitates seamless vote transactions through a dedicated dispatcher service.
* **Flexible Proposal Management:** Create and manage governance proposals with ease.

## **Getting Started**
Expand All @@ -25,10 +25,13 @@ Follow the steps below to set up and run Cosmos ZK Voting locally.
* [Git](https://git-scm.com/downloads)

### **Clone the Repository**

```bash
git clone https://github.com/your-username/cosmos-zk-voting
cd cosmos-zk-voting

git clone https://github.com/vitwit/cosmos-zk-gov

git fetch

git checkout main
```

Expand All @@ -44,18 +47,15 @@ make install

Initialize and start a local testnet.

**Initialize the Chain:**
1. **Initialize and Start the Chain:**
Modify the `scripts/init-simapp.sh` script according to your requirements.
```bash
`make init-simapp` will the run chain.
```bash
make init-simapp
```

1. **Start the Testnet:**
```bash
zkappd start
```

2. ## **ZK Prover and Verifier Keys**
## **ZK Prover and Verifier Keys**

Before setting up the chain, generate the ZK prover and verifier keys.

Expand All @@ -76,34 +76,28 @@ make generate-zk-keys

* **Optimize Merkle Implementation:** Aim for a constant Merkle tree size of 2^31 and improve update operations from O(n) to O(log n).

## **Relayer**

The Relayer is an HTTP server that listens for vote transactions, signs them with a valid chain address, and broadcasts them on-chain.

### **Why Use a Relayer?**
## **Dispatcher**

Vote transactions must be sent from a different, unlinkable address than the registered address. Since most users may not have multiple unlinkable addresses, the Relayer serves as an intermediary to handle this securely.
The Dispatcher is an HTTP server that listens for vote transactions, signs them with a valid chain address, and broadcasts them on-chain.

**Security Assurance:** The Relayer cannot manipulate transactions because the ZK proof guarantees transaction validity without exposing user secrets.
### **Why Use a Dispatcher?**

### **Running the Relayer**
Vote transactions must be sent from a different, unlinkable address than the registered address. Since most users may not have multiple unlinkable addresses, the dispatcher serves as an intermediary to handle this securely.

**Navigate to the Relayer Directory:**
```bash
cd /x/zkgov/client/relayer
```
**Security Assurance:** The Dispatcher cannot manipulate transactions because the ZK proof guarantees transaction validity without exposing user secrets.

1. **Start the Relayer:**
```bash
zkappd tx zk-gov run-relayer --from {key} --keyring-backend test --chain-id {chain-id} -y
### **Running the Dispatcher**
1.**Start the dispatcher:**
```bash
zkappd tx zk-gov run-dispatcher --from {key} --keyring-backend test --chain-id {chain-id} -y
```

Alternatively, you can run a predefined relayer (e.g., Alice):
```bash
make run-alice-relayer
Alternatively, you can run a predefined dispatcher (e.g., alice):
```bash
make run-alice-dispatcher
```

2. This command starts an HTTP server on port `8080` by default. You can change the port using the `--relayerPort {port}` flag.
2. This command starts an HTTP server on port `8080` by default. You can change the port using the `--dispatcherPort {port}` flag.

## **Transactions**

Expand All @@ -125,6 +119,12 @@ Or use a make command for convenience:
make create-proposal-a
```

**Create Commitments Directory:**
```bash
mkdir commitments
```


### **Register a Vote**

Register a vote commitment, which will be used later to anonymize the actual vote.
Expand All @@ -136,20 +136,22 @@ zkappd tx zk-gov register-vote [proposal-id] {"YES"/"NO"} --from [actual-voter-
Alternatively, use predefined make commands:

```bash
mkdir commitments
make register-alice-vote

make register-bob-vote
make register-sai-vote
make register-teja-vote

make register-charlie-vote

make register-david-vote
```

### **Cast a Vote**

After registering a vote commitment, generate a ZK proof to cast the actual vote. This proof verifies that you know the valid commitment without revealing your identity.

**Important:** The vote transaction must be signed by a different, unlinkable address from the one used to register the vote commitment. Use the Relayer to facilitate this process.
**Important:** The vote transaction must be signed by a different, unlinkable address from the one used to register the vote commitment. Use the dispatcher to facilitate this process.

#### **Without Relayer**
#### **Without dispatcher**

```bash
zkappd tx zk-gov vote [proposal-id] [register-vote-address] --from [different-unlinkable-address] --keyring-backend test --chain-id [chain-id]
Expand All @@ -162,17 +164,18 @@ make broadcast-alice-vote
make broadcast-bob-vote
```

#### **With Relayer**
#### **With Dispatcher**

```bash
zkappd tx zk-gov vote [proposal-id] [register-vote-address] --relayer [relayer-address]
zkappd tx zk-gov vote [proposal-id] [register-vote-address] --dispatcher [dispatcher-address]
```

Or use make commands:

```bash
make broadcast-sai-vote-via-relayer
make broadcast-teja-vote-via-relayer
make broadcast-charlie-vote-via-dispatcher

make broadcast-david-vote-via-dispatcher
```

### **Query a Proposal**
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
"github.com/spf13/cast"
"github.com/vishal-kanna/zk/zk-gov/x/zkgov"
zkgovKeeper "github.com/vishal-kanna/zk/zk-gov/x/zkgov/keeper"
zktypes "github.com/vishal-kanna/zk/zk-gov/x/zkgov/types"
"github.com/vitwit/cosmos-zk-gov/x/zkgov"
zkgovKeeper "github.com/vitwit/cosmos-zk-gov/x/zkgov/keeper"
zktypes "github.com/vitwit/cosmos-zk-gov/x/zkgov/types"
)

const AppName = "App"
Expand Down
2 changes: 1 addition & 1 deletion app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package app_test
// simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
// "github.com/stretchr/testify/require"

// "github.com/vishal-kanna/zk/zk-gov/app"
// "github.com/vitwit/cosmos-zk-gov/app"
// )

// // Profile with:
Expand Down
2 changes: 1 addition & 1 deletion app/zkappd/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"
simapp "github.com/vishal-kanna/zk/zk-gov/app"
simapp "github.com/vitwit/cosmos-zk-gov/app"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand Down
2 changes: 1 addition & 1 deletion app/zkappd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"
simapp "github.com/vishal-kanna/zk/zk-gov/app"
simapp "github.com/vitwit/cosmos-zk-gov/app"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down
4 changes: 2 additions & 2 deletions app/zkappd/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package cmd_test

// "github.com/stretchr/testify/require"

// simapp "github.com/vishal-kanna/zk/zk-gov/app"
// "github.com/vishal-kanna/zk/zk-gov/app/zkappd/cmd"
// simapp "github.com/vitwit/cosmos-zk-gov/app"
// "github.com/vitwit/cosmos-zk-gov/app/zkappd/cmd"

// "github.com/cosmos/cosmos-sdk/client/flags"
// svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
Expand Down
2 changes: 1 addition & 1 deletion app/zkappd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"cosmossdk.io/math"
"cosmossdk.io/math/unsafe"
simapp "github.com/vishal-kanna/zk/zk-gov/app"
simapp "github.com/vitwit/cosmos-zk-gov/app"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down
4 changes: 2 additions & 2 deletions app/zkappd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"

simapp "github.com/vishal-kanna/zk/zk-gov/app"
"github.com/vishal-kanna/zk/zk-gov/app/zkappd/cmd"
simapp "github.com/vitwit/cosmos-zk-gov/app"
"github.com/vitwit/cosmos-zk-gov/app/zkappd/cmd"

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import (
"net/http"
"time"

"github.com/vishal-kanna/zk/zk-gov/x/zkgov/types"
"github.com/vitwit/cosmos-zk-gov/x/zkgov/types"
)

type RelayerClient struct {
type DispatcherClient struct {
Address string
}

func NewRelayerClient(address string) *RelayerClient {
return &RelayerClient{
func NewdispatcherClient(address string) *DispatcherClient {
return &DispatcherClient{
Address: address,
}
}

func (relayerClient *RelayerClient) BroadCastTx(msg types.MsgVoteProposal) error {
func (dispatcherClient *DispatcherClient) BroadCastTx(msg types.MsgVoteProposal) error {
// Marshal the message to JSON
msgBytes, err := msg.Marshal()
if err != nil {
return fmt.Errorf("failed to marshal message: %w", err)
}

// Create a new POST request
url := relayerClient.Address + "/broadCastTransaction"
url := dispatcherClient.Address + "/broadCastTransaction"
req, err := http.NewRequest("POST", url, bytes.NewBuffer(msgBytes))
if err != nil {
return fmt.Errorf("failed to create HTTP request: %w", err)
Expand Down
Loading

0 comments on commit d26e71d

Please sign in to comment.