diff --git a/README.md b/README.md index ae7c111..6764d5d 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,10 @@ Ensure you have the following tools installed before you proceed: Jumpstart your development with these simple steps: -1. **Clone and Set Up the Project** +1. **Clone this repo and Set Up the Project** ```bash -git clone https://github.com/scaffold-eth/scaffold-eth-2.git -cd scaffold-eth-2 +git clone https://github.com/Vote-tech/voto-tech.git yarn install ``` @@ -38,7 +37,7 @@ In your first terminal window, run: yarn download-zkeys ``` -3. **Update the environment variables** +3. (Optional step) **Update the environment variables (if the .env files are present) ** Copy the env example files to env files @@ -79,12 +78,45 @@ yarn start 7. **Compute Results** -- In a fourth terminal, clone the maci repo - `git clone git@github.com:privacy-scaling-explorations/maci.git` and then reset to `ee3e2a6` commit using `git reset --hard ee3e2a6` -- Copy the zkeys generated from the maci wrapper repo to the cli directory of the maci repo using `cp -r maci-wrapper/packages/hardhat/zkeys maci/cli`. -- Install the dependencies using `pnpm i` and build the maci project using `pnpm run build` -- Copy the new contract addresses from the maci wrapper repo to the maci repo using `cp -r maci-wrapper/packages/contractAddresses.json maci/cli/build/contractAddresses.json`. +- In a fourth terminal, clone the maci repo - `git clone git@github.com:privacy-scaling-explorations/maci.git` and then reset to `ee3e2a6` commit using `git reset --hard ee3e2a6` +- Copy the zkeys generated from the maci wrapper repo to the cli directory of the maci repo using `cp -r maci-wrapper/packages/hardhat/zkeys maci/cli`. +- Inside maci/cli install the dependencies using `pnpm i` and build the maci project using `pnpm run build` +- Copy the new contract addresses from the maci wrapper repo to the maci repo using `cp -r maci-wrapper/packages/hardhat/contractAddresses.json maci/cli/build/contractAddresses.json`. - After this you should be able to run the commands written in the [maci documentation](https://maci.pse.dev/docs/v1.2/cli). -- First merge signups, then merge messages, and then generate proof, and upload the tally.json file which is generated in the process to the admin panel after the poll is over. + +In MACI cli (maci/cli folder): + +- First merge signups using (replace --poll-id 0 with the poll you are merging) + +```bash +node build/ts/index.js mergeSignups --poll-id 0 +``` + +- Second merge signups using (replace --poll-id 0 with the poll you are merging) + +```bash +node build/ts/index.js mergeMessages --poll-id 0 +``` + +- Third tally votes + Replace: + "--poll-id 0" with the poll you are merging + "--privkey coordinator-private-key" with the private key of the vote coordinator located in voto-tech/packages/hardhat/coordinatorKeyPair.json + +```bash +node build/ts/index.js genProofs \ +--privkey coordinator-private-key \ +--poll-id 0 \ +--process-zkey ./zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \ +--tally-zkey ./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey \ +--tally-file tally.json \ +--output proofs/ \ +--tally-wasm ./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test_js/TallyVotes_10-1-2_test.wasm \ +--process-wasm ./zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test_js/ProcessMessages_10-2-1-2_test.wasm \ +--wasm \ +``` + +- G and then generate proof, and upload the tally.json file which is generated in the process to the admin panel after the poll is over. Navigate to `http://localhost:3000` to interact with your dApp. Modify your app configuration in `packages/nextjs/scaffold.config.ts` and `packages/hardhat/constants.ts` as necessary. diff --git a/package-lock.json b/package-lock.json index f758ae3..68f8fd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26420,6 +26420,126 @@ "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0" } + }, + "packages/nextjs/node_modules/@next/swc-darwin-x64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", + "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", + "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", + "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", + "integrity": "sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.3.tgz", + "integrity": "sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", + "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", + "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/nextjs/node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", + "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/packages/nextjs/app/polls/[id]/page.tsx b/packages/nextjs/app/polls/[id]/page.tsx index 974cf34..d25a4d3 100644 --- a/packages/nextjs/app/polls/[id]/page.tsx +++ b/packages/nextjs/app/polls/[id]/page.tsx @@ -2,9 +2,12 @@ import { useParams } from "next/navigation"; import PollDetail from "~~/components/PollDetail"; +import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; + export default function PollDetailPage() { const { id } = useParams<{ id: string }>(); + useAuthUserOnly({}); return ; } diff --git a/packages/nextjs/app/polls/page.tsx b/packages/nextjs/app/polls/page.tsx index a13fd97..3347319 100644 --- a/packages/nextjs/app/polls/page.tsx +++ b/packages/nextjs/app/polls/page.tsx @@ -4,6 +4,7 @@ import { useState } from "react"; import { useRouter } from "next/navigation"; import Paginator from "~~/components/Paginator"; import HoverBorderCard from "~~/components/card/HoverBorderCard"; +import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; import { useFetchPolls } from "~~/hooks/useFetchPolls"; import { useTotalPages } from "~~/hooks/useTotalPages"; @@ -12,6 +13,7 @@ export default function Polls() { const [limit] = useState(10); const { totalPolls, polls } = useFetchPolls(currentPage, limit); const totalPages = useTotalPages(totalPolls, limit); + useAuthUserOnly({}); console.log(polls); diff --git a/packages/nextjs/components/PollDetail.tsx b/packages/nextjs/components/PollDetail.tsx index af81a18..f61ac1d 100644 --- a/packages/nextjs/components/PollDetail.tsx +++ b/packages/nextjs/components/PollDetail.tsx @@ -7,7 +7,6 @@ import { useContractRead, useContractWrite } from "wagmi"; import PollAbi from "~~/abi/Poll"; import VoteCard from "~~/components/card/VoteCard"; import { useAuthContext } from "~~/contexts/AuthContext"; -import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; import { useFetchPoll } from "~~/hooks/useFetchPoll"; import { getPollStatus } from "~~/hooks/useFetchPolls"; import { PollStatus, PollType } from "~~/types/poll"; @@ -18,8 +17,6 @@ export default function PollDetail({ id }: { id: bigint }) { const { data: poll, error, isLoading } = useFetchPoll(id); const [pollType, setPollType] = useState(PollType.NOT_SELECTED); - useAuthUserOnly({}); - const { keypair, stateIndex } = useAuthContext(); const [votes, setVotes] = useState<{ index: number; votes: number }[]>([]); diff --git a/packages/nextjs/contexts/AuthContext.tsx b/packages/nextjs/contexts/AuthContext.tsx index 5fdd785..05c235f 100644 --- a/packages/nextjs/contexts/AuthContext.tsx +++ b/packages/nextjs/contexts/AuthContext.tsx @@ -75,9 +75,12 @@ export default function AuthContextProvider({ children }: { children: React.Reac setStateIndex(null); return; } - - const lastSignUpEvent = SignUpEvents[SignUpEvents.length - 1]; - setStateIndex(lastSignUpEvent.args._stateIndex || null); + const event = SignUpEvents.filter( + log => + log.args._userPubKeyX?.toString() === keypair.pubKey.asContractParam().x && + log.args._userPubKeyY?.toString() === keypair.pubKey.asContractParam().y, + )[0]; + setStateIndex(event?.args?._stateIndex || null); }, [keypair, SignUpEvents]); useScaffoldEventSubscriber({ diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index d995afb..8083724 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "../utils/scaffold-eth/contract"; const deployedContracts = { 31337: { ConstantInitialVoiceCreditProxy: { - address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", + address: "0xDC11f7E700A4c898AE5CAddB1082cFfa76512aDD", abi: [ { inputs: [ @@ -45,10 +45,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 1, + deploymentBlockNumber: 101, }, FreeForAllGatekeeper: { - address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + address: "0x51A1ceB83B83F1985a81C295d1fF28Afef186E02", abi: [ { inputs: [], @@ -87,10 +87,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 3, + deploymentBlockNumber: 103, }, MACIWrapper: { - address: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e", + address: "0x2B0d36FACD61B71CC05ab8F3D2355ec3631C0dd5", abi: [ { inputs: [ @@ -1538,10 +1538,10 @@ const deployedContracts = { topupCredit: "maci-contracts/contracts/MACI.sol", transferOwnership: "maci-contracts/contracts/MACI.sol", }, - deploymentBlockNumber: 23, + deploymentBlockNumber: 123, }, MessageProcessorFactory: { - address: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318", + address: "0xBEc49fA140aCaA83533fB00A2BB19bDdd0290f25", abi: [ { inputs: [], @@ -1596,10 +1596,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 19, + deploymentBlockNumber: 119, }, PollFactory: { - address: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", + address: "0x4EE6eCAD1c2Dae9f525404De8555724e3c35d07B", abi: [ { inputs: [], @@ -1720,10 +1720,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 17, + deploymentBlockNumber: 117, }, PoseidonT3: { - address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", + address: "0x0355B7B8cb128fA5692729Ab3AAa199C1753f726", abi: [ { inputs: [ @@ -1745,10 +1745,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 9, + deploymentBlockNumber: 109, }, PoseidonT4: { - address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", + address: "0x202CCe504e04bEd6fC0521238dDf04Bc9E8E15aB", abi: [ { inputs: [ @@ -1770,10 +1770,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 11, + deploymentBlockNumber: 111, }, PoseidonT5: { - address: "0x0165878A594ca255338adfa4d48449f69242Eb8F", + address: "0xf4B146FbA71F41E0592668ffbF264F1D186b2Ca8", abi: [ { inputs: [ @@ -1795,10 +1795,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 13, + deploymentBlockNumber: 113, }, PoseidonT6: { - address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", + address: "0x172076E0166D1F9Cc711C77Adf8488051744980C", abi: [ { inputs: [ @@ -1820,10 +1820,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 15, + deploymentBlockNumber: 115, }, TallyFactory: { - address: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788", + address: "0xD84379CEae14AA33C123Af12424A37803F885889", abi: [ { inputs: [], @@ -1883,10 +1883,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 21, + deploymentBlockNumber: 121, }, TopupCredit: { - address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", + address: "0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7", abi: [ { inputs: [], @@ -2338,10 +2338,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 7, + deploymentBlockNumber: 107, }, Verifier: { - address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + address: "0x36b58F5C1969B7b6591D752ea6F5486D069010AB", abi: [ { inputs: [], @@ -2498,10 +2498,10 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 5, + deploymentBlockNumber: 105, }, VkRegistry: { - address: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82", + address: "0x46b142DD1E924FAb83eCc3c08e4D46E82f005e0E", abi: [ { inputs: [], @@ -3761,7 +3761,7 @@ const deployedContracts = { type: "function", }, ], - deploymentBlockNumber: 26, + deploymentBlockNumber: 126, }, }, } as const;