@maci-protocol/website 0.0.0-ci.da13fbb → 0.0.0-ci.de6bbd5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -204,9 +204,15 @@ async function getConfig(): Promise<Config> {
204
204
  phpLoader: "matomo.php",
205
205
  jsLoader: "matomo.js",
206
206
  },
207
+ mermaid: {
208
+ theme: { light: "neutral", dark: "forest" },
209
+ },
207
210
  } satisfies Preset.ThemeConfig,
211
+ markdown: {
212
+ mermaid: true,
213
+ },
214
+ themes: ["@docusaurus/theme-mermaid"],
208
215
  };
209
-
210
216
  return config;
211
217
  }
212
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maci-protocol/website",
3
- "version": "0.0.0-ci.da13fbb",
3
+ "version": "0.0.0-ci.de6bbd5",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,7 +25,8 @@
25
25
  "@docusaurus/preset-classic": "^3.8.1",
26
26
  "@docusaurus/theme-classic": "^3.8.1",
27
27
  "@docusaurus/theme-common": "^3.8.1",
28
- "@easyops-cn/docusaurus-search-local": "^0.51.0",
28
+ "@docusaurus/theme-mermaid": "^3.8.1",
29
+ "@easyops-cn/docusaurus-search-local": "^0.52.1",
29
30
  "@mdx-js/react": "^3.1.0",
30
31
  "clsx": "^2.1.1",
31
32
  "docusaurus-plugin-image-zoom": "^3.0.1",
@@ -41,7 +42,7 @@
41
42
  "@docusaurus/module-type-aliases": "^3.8.1",
42
43
  "@docusaurus/tsconfig": "^3.8.1",
43
44
  "@docusaurus/types": "^3.8.1",
44
- "@types/node": "^22.15.17",
45
+ "@types/node": "^24.0.13",
45
46
  "@types/react": "^19.1.8",
46
47
  "ts-node": "^10.9.2",
47
48
  "typescript": "^5.8.3"
@@ -61,5 +62,5 @@
61
62
  "engines": {
62
63
  "node": ">=18.0"
63
64
  },
64
- "gitHead": "d5c6bf10c4097b1d21e4f3c3e40df127a222696b"
65
+ "gitHead": "b1ed6c9c3a7dc3ca3081242d67438b96779c285a"
65
66
  }
@@ -41,9 +41,7 @@ Refer to the [Glossary](#glossary) for definitions of terms.
41
41
  3. The signup period ends after a fixed amount of time. From that point onwards, users may no longer invoke `signUp()` in this contract.
42
42
 
43
43
  4. Each user votes. To do this, they:
44
-
45
44
  - Sign their command using the key which they had signed up with and then use a random (ephemeral) key as well as the coordinator's public key to generate a shared key (via ECDH) encrypt it.
46
-
47
45
  - If they are bribed, the user should sign it using an old public key which has already been replaced with a new one.
48
46
 
49
47
  - Otherwise, the user should use the most current public key they have registered.
@@ -53,9 +51,7 @@ Refer to the [Glossary](#glossary) for definitions of terms.
53
51
  5. The coordinator processes all the commands after the voting period ends.
54
52
 
55
53
  6. For each batch of commands, they perform the following steps:
56
-
57
54
  - Generate a new state root which is the result of:
58
-
59
55
  - For each valid command, in reverse order, update the state leaf accordingly
60
56
 
61
57
  - Ignore all invalid commands
@@ -0,0 +1,121 @@
1
+ ---
2
+ title: MACI SDK
3
+ description: How to use the MACI SDK
4
+ sidebar_label: MACI SDK
5
+ sidebar_position: 6
6
+ ---
7
+
8
+ In this guide we will be looking at how to use the MACI SDK to interact with the MACI protocol.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @maci-protocol/sdk
14
+ ```
15
+
16
+ ## Browser compatibility
17
+
18
+ As the SDK imports functions from the `@maci-protocol/contracts` package which uses hardhat, certain functionality is not browser compatible.
19
+ However, all it takes to use browser compatible functions is to import from `@maci-protocol/sdk/browser`.
20
+
21
+ As an example, we can import the `signUp` function from the `@maci-protocol/sdk/browser` package.
22
+
23
+ ```typescript
24
+ import { signUp } from "@maci-protocol/sdk/browser";
25
+ ```
26
+
27
+ Let's take a look at an example of how to use the `joinPoll` function to register a user to a poll.
28
+
29
+ ### JoinPoll
30
+
31
+ This step is required to register a user to a specific poll for which they want to vote. In short, it requires the user to generate a zk-SNARK proof that they know the private key to a public key registered to the MACI contract (proving they passed the initial gatekeeping requirements). This forces them to join with the same MACI key to each poll, greatly increasing the value of the key. Should they have been allowed to join with a throwaway key, they could simply sell their key for polls they do not care about.
32
+
33
+ **How does the flow look like?**
34
+
35
+ 1. Reconstruct the MACI state tree by pulling all public keys from the MACI contract (events from RPC or from Subgraph)
36
+ 2. Generate a merkle tree inclusion proof for the user's public key
37
+ 3. Generate a zk-SNARK proof that the user knows the private key to the public key in the merkle tree inclusion proof
38
+ 4. Call the `joinPoll` function on the Poll smart contract
39
+
40
+ **How to use the SDK for this?**
41
+
42
+ > This example is browser specific, as it uses the `@maci-protocol/sdk/browser` package and WASM for witness generation
43
+
44
+ Option 1: Use the `joinPoll` function from the `@maci-protocol/sdk/browser` package.
45
+
46
+ 1. Download the `pollJoining` zk artifacts using [downloadPollJoiningArtifactsBrowser](https://github.com/privacy-scaling-explorations/maci/blob/dev/packages/sdk/ts/proof/download.ts#L46)
47
+
48
+ ```typescript
49
+ import { downloadPollJoiningArtifactsBrowser } from "@maci-protocol/sdk/browser";
50
+
51
+ const artifacts = await downloadPollJoiningArtifactsBrowser({
52
+ testing: true,
53
+ stateTreeDepth: 10,
54
+ });
55
+ ```
56
+
57
+ 2. Use the `joinPoll` function to join the poll
58
+
59
+ ```typescript
60
+ import { joinPoll } from "@maci-protocol/sdk/browser";
61
+
62
+ const joinedPollData = await joinPoll({
63
+ maciAddress: PUBLIC_MACI_ADDRESS,
64
+ privateKey: maciKeypair.privateKey.serialize(),
65
+ signer,
66
+ pollId,
67
+ inclusionProof,
68
+ pollJoiningZkey: artifacts.zKey as unknown as string,
69
+ pollWasm: artifacts.wasm as unknown as string,
70
+ sgDataArg: DEFAULT_SG_DATA,
71
+ ivcpDataArg: DEFAULT_IVCP_DATA,
72
+ blocksPerBatch: 1000,
73
+ });
74
+ ```
75
+
76
+ This is not really efficient, as we are using the user RPC to fetch events, which can be quite slow and prone to errors. A better approach is to use a Subgraph to fetch the events.
77
+
78
+ Option 2: Fetch the MACI keys using a subgraph and reconstruct the state tree locally.
79
+
80
+ 1. Deploy the subgraph - instructions [here](/guides/subgraph)
81
+ 2. Fetch the MACI keys
82
+
83
+ ```typescript
84
+ import { MaciSubgraph } from "@maci-protocol/sdk/browser";
85
+
86
+ const subgraph = new MaciSubgraph("https://api.studio.thegraph.com/query/x/maci/version/latest");
87
+
88
+ const keys = await subgraph.getKeys();
89
+ ```
90
+
91
+ 3. Generate the merkle tree
92
+
93
+ ```typescript
94
+ import { generateSignUpTreeFromKeys } from "@maci-protocol/sdk/browser";
95
+
96
+ const signUpTree = generateSignUpTreeFromKeys(keys);
97
+ ```
98
+
99
+ 4. Generate the inclusion proof - you will need to know the index of the user's public key in the merkle tree
100
+
101
+ ```typescript
102
+ const inclusionProof = signUpTree.generateProof(publicKeyIndex);
103
+ ```
104
+
105
+ 5. Generate the zk-SNARK proof and join the poll
106
+
107
+ ```typescript
108
+ import { joinPoll } from "@maci-protocol/sdk/browser";
109
+
110
+ const joinedPollData = await joinPoll({
111
+ maciAddress: PUBLIC_MACI_ADDRESS,
112
+ privateKey: maciKeypair.privateKey.serialize(),
113
+ signer,
114
+ pollId,
115
+ inclusionProof,
116
+ pollJoiningZkey: artifacts.zKey as unknown as string,
117
+ pollWasm: artifacts.wasm as unknown as string,
118
+ sgDataArg: DEFAULT_SG_DATA,
119
+ ivcpDataArg: DEFAULT_IVCP_DATA,
120
+ });
121
+ ```
@@ -19,7 +19,7 @@ The MACI smart contracts handle the on-chain aspects - both the functionality an
19
19
 
20
20
  The MACI smart contracts are written in [Solidity](https://soliditylang.org/).
21
21
 
22
- Contracts are released through the [`@maci-contracts`](https://www.npmjs.com/package/maci-contracts) NPM package.
22
+ Contracts are released through the [`@maci-protocol/contracts`](https://www.npmjs.com/package/@maci-protocol/contracts) NPM package.
23
23
 
24
24
  [Learn more about MACI contracts](/docs/technical-references/smart-contracts/)
25
25
 
@@ -29,12 +29,12 @@ The TypeScript libraries manage the business logic between the smart contracts a
29
29
 
30
30
  The MACI [TypeScript](https://www.typescriptlang.org/) libraries are released through the following NPM packages:
31
31
 
32
- - [`@maci-cli`](https://www.npmjs.com/package/maci-cli)
33
- - [`@maci-core`](https://www.npmjs.com/package/maci-core)
34
- - [`@maci-crypto`](https://www.npmjs.com/package/maci-crypto)
35
- - [`@maci-domainobjs`](https://www.npmjs.com/package/maci-domainobjs)
36
- - [`@maci-integrationtests`](https://www.npmjs.com/package/maci-integrationtests)
37
- - [`@maci-sdk`](https://www.npmjs.com/package/maci-sdk)
32
+ - [`@maci-protocol/cli`](https://www.npmjs.com/package/@maci-protocol/cli)
33
+ - [`@maci-protocol/core`](https://www.npmjs.com/package/@maci-protocol/core)
34
+ - [`@maci-protocol/crypto`](https://www.npmjs.com/package/@maci-protocol/crypto)
35
+ - [`@maci-protocol/domainobjs`](https://www.npmjs.com/package/@maci-protocol/domainobjs)
36
+ - [`@maci-protocol/integrationtests`](https://www.npmjs.com/package/@maci-protocol/integrationtests)
37
+ - [`@maci-protocol/sdk`](https://www.npmjs.com/package/@maci-protocol/sdk)
38
38
 
39
39
  ## Circuits
40
40
 
@@ -43,6 +43,6 @@ MACI has multiple circuits that ensure all off-chain computation is completed co
43
43
  The circuits for these zero-knowledge proofs are written
44
44
  in [Circom](https://iden3.io/circom).
45
45
 
46
- The MACI circuits are released through the [`@maci-circuits`](https://www.npmjs.com/package/maci-circuits) NPM package.
46
+ The MACI circuits are released through the [`@maci-protocol/circuits`](https://www.npmjs.com/package/@maci-protocol/circuits) NPM package.
47
47
 
48
48
  [Learn more about MACI circuits](/docs/technical-references/zk-snark-circuits/)
@@ -18,7 +18,67 @@ The pre-requisites for this circuit are:
18
18
 
19
19
  This circuit requires the coordinator's private key, hence a proof for this circuit can only be generated by the coordinator. The private key is needed in order to generate the ECDH shared key used to decrypt the messages.
20
20
 
21
- ![ProcessMessages](/img/circuits/processMessages_2_0.svg)
21
+ ```mermaid
22
+ flowchart LR
23
+ parameters(["MessageProcessorQv - Parameters"])
24
+ parameters --> stateTreeDepth["stateTreeDepth"]
25
+ parameters --> batchSize["batchSize"]
26
+ parameters --> voteOptionTreeDepth["voteOptionTreeDepth"]
27
+
28
+ stateTreeDepth & batchSize & voteOptionTreeDepth --> publicInputs["Public inputs"]
29
+
30
+ subgraph publicInputs
31
+ direction LR
32
+ totalSignups ~~~ index
33
+ batchEndIndex ~~~ currentSbCommitment
34
+ newSbCommitment ~~~ outputBatchHash
35
+ actualStateTreeDepth ~~~ coordinatorPublicKeyHash
36
+ voteOptions
37
+ end
38
+
39
+ publicInputs --> privateInputs
40
+
41
+ subgraph privateInputs
42
+ direction LR
43
+ inputBatchHash ~~~ messages
44
+ coordinatorPrivateKey ~~~ encryptionPublicKeys
45
+ currentStateRoot ~~~ currentStateLeaves
46
+ currentStateLeavesPathElements ~~~ currentSbSalt
47
+ newSbSalt ~~~ currentBallotRoot
48
+ currentBallots ~~~ currentBallotsPathElements
49
+ currentVoteWeights ~~~ currentVoteWeightsPathElements
50
+ end
51
+
52
+ privateInputs --> step1["1 - Verify currentSbCommitment"]
53
+ step1 --> step1B["hash(currentStateRoot, currentBallotRoot, currentSbSalt)"]
54
+
55
+ privateInputs --> step2["2 – Check voteOptions upper-bound"]
56
+ step2 --> step2B["voteOptions <= 5 ** voteOptionTreeDepth"]
57
+
58
+ privateInputs --> step3["3 – Ensure totalSignups within capacity"]
59
+ step3 --> step3B["totalSignups <= 2 ** stateTreeDepth"]
60
+
61
+ privateInputs --> step4["4 – Hash each message + pub-key"]
62
+ step4 --> step4B["MessageHasher template loop"]
63
+
64
+ privateInputs --> step5["5 – Build and verify chainHash"]
65
+ step5 --> step5B["PoseidonHasher template loop + Mux1"]
66
+
67
+ privateInputs --> step6["6 – Derive & verify coordinator pubKey"]
68
+ step6 --> step6B["PrivateToPublicKey -> derivedPublicKeyHash == coordinatorPublicKeyHash"]
69
+
70
+ privateInputs --> step7["7 – Decrypt each message to a command using MessageToCommand"]
71
+ step7 --> step7B["MessageToCommand template loop"]
72
+
73
+ privateInputs --> step8["8 – Process messages in reverse order"]
74
+ step8 --> step8B["SingleMessageProcessorQv template loop"]
75
+
76
+ privateInputs --> step9["9 – Compute newSbCommitment"]
77
+ step9 --> step9B["hash(stateRoot, ballotRoot, newSbSalt)"]
78
+
79
+ privateInputs --> step10["10 – Verify provided newSbCommitment"]
80
+ step10 --> step10B["equality with computed commitment"]
81
+ ```
22
82
 
23
83
  :::info
24
84
  A version working with non quadratic voting (non-qv) is also [available](https://github.com/privacy-scaling-explorations/maci/blob/dev/circuits/circom/coordinator/non-qv/MessageProcessor.circom). This version is called `MessageProcessorNonQV` and is to be used when the Poll is not using the quadratic voting feature. Note that by default MACI works with quadratic voting.