Skip to content

Commit

Permalink
Merge pull request #388 from chnejohnson/docs/add-demo
Browse files Browse the repository at this point in the history
docs: add demo in cli.md
  • Loading branch information
corydickson committed Apr 5, 2022
2 parents dd3c34a + 1ad2f9b commit cc14505
Showing 1 changed file with 296 additions and 1 deletion.
297 changes: 296 additions & 1 deletion docs_src/src/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,300 @@ node build/index.js verify \

## Demonstration

TODO
### Scenario:
1. Alice votes for Party A
2. Alice changes her key
3. Eve tries to bribe Alice to change her vote to Party B
4. Alice submits an invalid vote for Party B
5. The coordinator processes the votes, computes, and verifies the final tally
6. The expected result is: Party A has some votes and Party B has 0 votes.

Implication: Alice's invalid vote was not counted, and Eve had no way to tell.

### Examples of serialized public and private keys:

```
Coordinator:
Private key: macisk.49953af3585856f539d194b46c82f4ed54ec508fb9b882940cbe68bbc57e59e
Public key: macipk.c974f4f168b79727ac98bfd53a65ea0b4e45dc2552fe73df9f8b51ebb0930330
Alice:
Private key: macisk.fd7aa614ec4a82716ffc219c24fd7e7b52a2b63b5afb17e81c22fe21515539c
Public key: macipk.3e7bb2d7f0a1b7e980f1b6f363d1e3b7a12b9ae354c2cd60a9cfa9fd12917391
```

### Coordinator: Deploy VkRegistry

```bash
node build/index.js deployVkRegistry
```

Output:
```bash
VkRegistry: 0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0
```

### Coordinator: Set verifying keys

```bash
node build/index.js setVerifyingKeys \
--vk_registry 0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0 \
--state-tree-depth 10 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--vote-option-tree-depth 2 \
--msg-batch-depth 1 \
--process-messages-zkey ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey \
--tally-votes-zkey ./zkeys/TallyVotes_10-1-2_test.0.zkey
```

Output:
```bash
Setting verifying keys...
Transaction hash: 0x16236fe5e124f3d0c33ddf20a37ceba9730a659630258a1e858b3e335e057b8e
```

### Coordinator: Create MACI instance

```bash
node build/index.js create \
--vk-registry 0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0
```

Output:
```bash
Deploying InitialVoiceCreditProxy
Deploying Poseidon contracts
Linking Poseidon libraries to MACI
Linking Poseidon libraries to PollFactory
Linking Poseidon libraries to MessageAqFactory
Deploying MACI
Transferring PollFactory ownership to MACI
Transferring MessageAqFactory ownership to PollFactory
Initialising MACI
MACI: 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a
```

### Coordinator: Deploy poll

```bash
node ./build/index.js deployPoll \
--maci-address 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--pubkey macipk.c974f4f168b79727ac98bfd53a65ea0b4e45dc2552fe73df9f8b51ebb0930330 \
--duration 1000 \
--max-messages 25 \
--max-vote-options 25 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--msg_batch_depth 1 \
--vote-option-tree-depth 2
```

Output:
```bash
Verifier: 0x0d8cc4b8d15D4c3eF1d70af0071376fb26B5669b
Poll ID: 0
Poll contract: 0x08e8f54262de52fe7Dfd0Bc0C9Ea87689d70e985
PollProcessorAndTallyer contract: 0xEcFcaB0A285d3380E488A39B4BB21e777f8A4EaC
```

### Alice: sign up

```bash
node ./build/index.js signup \
--pubkey macipk.3e7bb2d7f0a1b7e980f1b6f363d1e3b7a12b9ae354c2cd60a9cfa9fd12917391 \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a
```

Output:
```bash
Transaction hash: 0xcdff1e0cd3021cdc3ba2c65cfd74bac3715c32efdd2052c0e8f3a677a81a758b
State index: 1
```

### Alice: votes for Party A (option index 0)

```bash
node build/index.js publish \
--pubkey macipk.3e7bb2d7f0a1b7e980f1b6f363d1e3b7a12b9ae354c2cd60a9cfa9fd12917391 \
--privkey macisk.fd7aa614ec4a82716ffc219c24fd7e7b52a2b63b5afb17e81c22fe21515539c \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--state-index 1 \
--vote-option-index 0 \
--new-vote-weight 9 \
--nonce 1 \
--poll-id 0
```

Output:
```bash
Transaction hash: 0xc0964069834b171bb698ffc61e31e1be456c740ff1967ccad7d8cd8ed362e545
Ephemeral private key: macisk.1bf4bba7086c213606bb4a775b1ceaa4c2e7119c329748e675375f0d79c900dc
```

### Alice: submits an invalid vote for Party B (option index 1) with different public key
```bash
node build/index.js publish \
--pubkey macipk.d5788ea6ccf1ec295df99aaef859031fe7bd359e7e03acb80eb6e8a192f2ce19 \
--privkey macisk.fd7aa614ec4a82716ffc219c24fd7e7b52a2b63b5afb17e81c22fe21515539c \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--state-index 1 \
--vote-option-index 1 \
--new-vote-weight 9 \
--nonce 2 \
--poll-id 0
```

Output:
```bash
Transaction hash: 0xc13b97e23b387d8c160e0f8b1bfb33dc0ff4441fe63a37f0fc3ec84a0cfa0600
Ephemeral private key: macisk.5bc9f217a29c5defad1ca9be3d649add1eca30037589527476e8335b24cf75b
```


Time Travel
```
node build timeTravel -s 1000
```

### Coordinator: merge state tree

```bash
node build/index.js mergeSignups \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--poll-id 0
```

Output:
```bash
Merging state subroots 1 / 1
Executed mergeMaciStateAqSubRoots(); gas used: 723525
Transaction hash: 0x14621b208fdadbf277edf80b393f1a9694099ae9676903e148fa485eecfadd4b

All state subtrees have been merged.
Merging subroots to a main state root...
Executed mergeStateAq(); gas used: 1015876
Transaction hash: 0xf2903b1c3c83b87c551a71f29e07762b464691ca58b0c6849b2f9b8f5783011f
The state tree has been merged.
```

### Coordinator: merge message tree

```bash
node build/index.js mergeMessages \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--poll-id 0
```

Output:
```bash
Merging message subroots 1 / 1
Executed mergeMaciStateAqSubRoots(); gas used: 604387
Transaction hash: 0xe0c0306b80febe1f6947b6ccbefabef38d01abce0b7611f49ce1cc7e20f196a5

All message subtrees have been merged.
Merging subroots to a main message root...
Executed mergeMessageAq(); gas used: 174376
Transaction hash: 0x424581f08d5f8e9f4fd63b083f9446cc2bff3b8e4b67ebc834076d6e9c34ec20
The message tree has been merged.
```

### Coordinator: generate proofs

```bash
node build/index.js genProofs \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--privkey macisk.49953af3585856f539d194b46c82f4ed54ec508fb9b882940cbe68bbc57e59e \
--poll-id 0 \
--tally-file tally.json \
--output proofs \
--rapidsnark ~/rapidsnark/build/prover \
--process-witnessgen ./zkeys/ProcessMessages_10-2-1-2_test \
--tally-witnessgen ./zkeys/TallyVotes_10-1-2_test \
--process-zkey ./zkeys/ProcessMessages_10-2-1-2_test.0.zkey \
--tally-zkey ./zkeys/TallyVotes_10-1-2_test.0.zkey
```

Output:
```bash
fromBlock = 0
Generating proofs of message processing...

Progress: 1 / 1

Generating proofs of vote tallying...

Progress: 1 / 1

OK
```

### Coordinator: prove on chain

```bash
node build/index.js proveOnChain \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--poll-id 0 \
--ppt 0xEcFcaB0A285d3380E488A39B4BB21e777f8A4EaC \
--proof-dir proofs/
```

Output:
```bash
Submitting proofs of message processing...
Transaction hash: 0x59388e69899612390ef22de235629e9355e14f888bb330b46511cc06d8f2035d
Progress: 1 / 1
All message processing proofs have been submitted.

Submitting proofs of vote tallying...
Progress: 1 / 1
Transaction hash: 0xc90e3bd0618def86b709c995485271f806c60701a3f4246903498f27346b9f5e
All vote tallying proofs have been submitted.

OK
```

### Anyone: verify

```bash
node build/index.js verify \
--contract 0xf204a4Ef082f5c04bB89F7D5E6568B796096735a \
--poll-id 0 \
--tally-file tally.json \
--ppt 0xEcFcaB0A285d3380E488A39B4BB21e777f8A4EaC
```

Output:
```bash
{
provider: 'http://localhost:8545',
maci: '0xf204a4Ef082f5c04bB89F7D5E6568B796096735a',
pollId: 0,
newTallyCommitment: '0x29b47e79c10709047ba9788580c2dc8528f003eab42d30670df78a47b121aa6c',
results: {
tally: [
'9', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0'
],
salt: '0x132065c8ad3968008aeb7c114a04de228fa5b3618743ad00f64ad3f773a2e4d2'
},
totalSpentVoiceCredits: {
spent: '81',
salt: '0x2940f93e085350a04f6ff85e1ebffbc391fc3498f1cb41ab47f8899dc9c6efc6'
},
perVOSpentVoiceCredits: {
tally: [
'81', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0',
'0'
],
salt: '0x2db5c3d6b015f8e2ea1cf7ffed7a44af0db8a8c09a5077415c076b6ebcee0571'
}
}
OK
```

0 comments on commit cc14505

Please sign in to comment.