Skip to content

Commit

Permalink
update MACI to 0.0.0-ci.09b7fe7 and use temporary zk params for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Feb 20, 2024
1 parent 093eef3 commit 4268c4f
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 138 deletions.
10 changes: 2 additions & 8 deletions .github/scripts/download-6-8-2-3.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash
set -e

BASE_URL="https://maci-zkeys.s3.amazonaws.com/v1.1.0/6-8-2-3"
# TODO: replace this with params from public ceremony
BASE_URL="https://maci-zkeys.s3.amazonaws.com/v1.1.2/6-8-2-3"
PKGS="maci-zkeys-6-8-2-3.tar.gz"

mkdir -p params
cd params


for p in $PKGS
do
url="$BASE_URL/$p"
Expand All @@ -19,6 +16,3 @@ do
tar -zxvf $p
fi
done

mv zkeys/* .
rm -rf zkeys
6 changes: 3 additions & 3 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
"dependencies": {
"@openzeppelin/merkle-tree": "^1.0.5",
"ethers": "^6.9.2",
"maci-crypto": "0.0.0-ci.da1e442",
"maci-domainobjs": "0.0.0-ci.da1e442"
"ethers": "^6.11.1",
"maci-crypto": "0.0.0-ci.09b7fe7",
"maci-domainobjs": "0.0.0-ci.09b7fe7"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion common/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { id } from 'ethers'
import {
genTreeCommitment as genTallyResultCommitment,
genRandomSalt,
Expand Down
63 changes: 36 additions & 27 deletions contracts/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ethers, config } from 'hardhat'
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
import { time, mine } from '@nomicfoundation/hardhat-network-helpers'
import { expect } from 'chai'
import { BaseContract, Contract, toNumber } from 'ethers'
import { BaseContract, Contract, toNumber, Signer } from 'ethers'
import {
Keypair,
createMessage,
Expand Down Expand Up @@ -32,14 +31,17 @@ import {
addTallyResultsBatch,
getRecipientClaimData,
getGenProofArgs,
TallyData,
} from '../utils/maci'
import { DEFAULT_CIRCUIT } from '../utils/circuits'
import { MaciParameters } from '../utils/maciParameters'
import { readFileSync, existsSync, mkdirSync } from 'fs'
import { existsSync, mkdirSync } from 'fs'
import path from 'path'
import { FundingRound } from '../typechain-types'
import { JSONFile } from '../utils/JSONFile'

type VoteData = { recipientIndex: number; voiceCredits: bigint }
type ClaimData = { [index: number]: bigint }

const ZERO = BigInt(0)
// funding round duration
Expand Down Expand Up @@ -115,14 +117,14 @@ describe('End-to-end Tests', function () {

let maciTransactionHash: string

let deployer: HardhatEthersSigner
let coordinator: HardhatEthersSigner
let poolContributor1: HardhatEthersSigner
let poolContributor2: HardhatEthersSigner
let recipient1: HardhatEthersSigner
let recipient2: HardhatEthersSigner
let recipient3: HardhatEthersSigner
let contributors: HardhatEthersSigner[]
let deployer: Signer
let coordinator: Signer
let poolContributor1: Signer
let poolContributor2: Signer
let recipient1: Signer
let recipient2: Signer
let recipient3: Signer
let contributors: Signer[]

let poseidonLibraries: { [key: string]: string }
let userRegistry: Contract
Expand Down Expand Up @@ -207,8 +209,9 @@ describe('End-to-end Tests', function () {
// Configure factory
await clrfund.setToken(token.target)
coordinatorKeypair = new Keypair()
const coordinatorAddress = await coordinator.getAddress()
await clrfund.setCoordinator(
coordinator.address,
coordinatorAddress,
coordinatorKeypair.pubKey.asContractParam()
)

Expand Down Expand Up @@ -331,14 +334,17 @@ describe('End-to-end Tests', function () {
return { tallyAddress, messageProcessorAddress }
}

async function finalizeRound(testResetTally = false): Promise<any> {
async function finalizeRound(
testResetTally = false
): Promise<{ tally: TallyData; claims: ClaimData }> {
debugLog('Finalizing round')
// Process messages and tally votes
const maciAddress = await maci.getAddress()
await mergeMaciSubtrees({
maciAddress,
pollId,
numQueueOps: DEFAULT_SR_QUEUE_OPS,
signer: coordinator,
})
debugLog('Merged MACI trees')

Expand All @@ -359,6 +365,7 @@ describe('End-to-end Tests', function () {
outputDir,
blocksPerBatch: DEFAULT_GET_LOG_BATCH_SIZE,
maciTxHash: maciTransactionHash,
signer: coordinator,
quiet,
})

Expand All @@ -378,6 +385,7 @@ describe('End-to-end Tests', function () {
maciAddress,
messageProcessorAddress,
tallyAddress,
signer: coordinator,
quiet,
})

Expand All @@ -397,12 +405,13 @@ describe('End-to-end Tests', function () {
maciAddress,
messageProcessorAddress,
tallyAddress,
signer: coordinator,
quiet,
})
}
console.log('finished proveOnChain')

const tally = JSON.parse(readFileSync(genProofArgs.tallyFile).toString())
const tally = JSONFile.read(genProofArgs.tallyFile) as TallyData
const tallyHash = await getIpfsHash(tally)
await (fundingRound.connect(coordinator) as Contract).publishTallyHash(
tallyHash
Expand All @@ -422,13 +431,13 @@ describe('End-to-end Tests', function () {

const newResultCommitment = genTallyResultCommitment(
tally.results.tally.map((x: string) => BigInt(x)),
tally.results.salt,
BigInt(tally.results.salt),
recipientTreeDepth
)

const perVOSpentVoiceCreditsCommitment = genTallyResultCommitment(
tally.perVOSpentVoiceCredits.tally.map((x: string) => BigInt(x)),
tally.perVOSpentVoiceCredits.salt,
BigInt(tally.perVOSpentVoiceCredits.salt),
recipientTreeDepth
)

Expand All @@ -442,7 +451,7 @@ describe('End-to-end Tests', function () {
)

// Claim funds
const claims: { [index: number]: bigint } = {}
const claims: ClaimData = {}
for (const recipientIndex of [1, 2]) {
const recipient = recipientIndex === 1 ? recipient1 : recipient2

Expand All @@ -460,7 +469,7 @@ describe('End-to-end Tests', function () {
'FundsClaimed',
'_amount'
)
claims[recipientIndex] = claimedAmount
claims[recipientIndex] = BigInt(claimedAmount)
}
return { tally, claims }
}
Expand Down Expand Up @@ -532,8 +541,8 @@ describe('End-to-end Tests', function () {
)
)
console.log('expected claim', claims[1], expectedClaims[0])
expect(BigInt(claims[1])).to.equal(expectedClaims[0])
expect(BigInt(claims[2])).to.equal(expectedClaims[1])
expect(claims[1]).to.equal(expectedClaims[0])
expect(claims[2]).to.equal(expectedClaims[1])
})

it('should allocate funds correctly if not all voice credits are spent', async () => {
Expand Down Expand Up @@ -656,8 +665,8 @@ describe('End-to-end Tests', function () {
[voiceCredits1, contribution2.voiceCredits],
]
const expectedTally = tallyVotes(submittedVoiceCredits)
expect(tally.results.tally[1]).to.equal(expectedTally[0])
expect(tally.results.tally[2]).to.equal(expectedTally[1])
expect(BigInt(tally.results.tally[1])).to.equal(expectedTally[0])
expect(BigInt(tally.results.tally[2])).to.equal(expectedTally[1])
const expectedClaims = await calculateClaims(
fundingRound,
submittedVoiceCredits
Expand Down Expand Up @@ -734,7 +743,7 @@ describe('End-to-end Tests', function () {
]
const expectedTally = tallyVotes(submittedVoiceCredits)
expect(tally.results.tally[1]).to.equal('0')
expect(tally.results.tally[2]).to.equal(expectedTally[0])
expect(BigInt(tally.results.tally[2])).to.equal(expectedTally[0])
const expectedClaims = await calculateClaims(
fundingRound,
submittedVoiceCredits
Expand Down Expand Up @@ -821,8 +830,8 @@ describe('End-to-end Tests', function () {
]
const expectedTally = tallyVotes(submittedVoiceCredits)

expect(tally.results.tally[1]).to.equal(expectedTally[0])
expect(tally.results.tally[2]).to.equal(expectedTally[1])
expect(BigInt(tally.results.tally[1])).to.equal(expectedTally[0])
expect(BigInt(tally.results.tally[2])).to.equal(expectedTally[1])
expect(tally.results.tally[3]).to.equal('0')

const expectedClaims = await calculateClaims(
Expand Down Expand Up @@ -1010,7 +1019,7 @@ describe('End-to-end Tests', function () {
)
)
console.log('expected claim', claims[1], expectedClaims[0])
expect(BigInt(claims[1])).to.equal(expectedClaims[0])
expect(BigInt(claims[2])).to.equal(expectedClaims[1])
expect(claims[1]).to.equal(expectedClaims[0])
expect(claims[2]).to.equal(expectedClaims[1])
})
})
10 changes: 5 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@openzeppelin/contracts": "4.9.0",
"dotenv": "^8.2.0",
"maci-contracts": "0.0.0-ci.da1e442",
"maci-contracts": "0.0.0-ci.09b7fe7",
"solidity-rlp": "2.0.8"
},
"devDependencies": {
Expand All @@ -33,14 +33,14 @@
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/mocha": "^10.0.6",
"ethers": "^6.10.0",
"ethers": "^6.11.1",
"hardhat": "^2.19.4",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.8",
"ipfs-only-hash": "^2.0.1",
"maci-circuits": "0.0.0-ci.da1e442",
"maci-cli": "0.0.0-ci.da1e442",
"maci-domainobjs": "0.0.0-ci.da1e442",
"maci-circuits": "0.0.0-ci.09b7fe7",
"maci-cli": "0.0.0-ci.09b7fe7",
"maci-domainobjs": "0.0.0-ci.09b7fe7",
"mocha": "^10.2.0",
"solidity-coverage": "^0.8.1",
"ts-node": "^10.9.2",
Expand Down
4 changes: 4 additions & 0 deletions contracts/tasks/clrTally.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ task('clr-tally', 'Tally votes')
maciAddress,
pollId,
numQueueOps,
signer: coordinator,
quiet,
})

Expand All @@ -272,6 +273,7 @@ task('clr-tally', 'Tally votes')
ethereumProvider: providerUrl,
transactionHash: maciTxHash,
blockPerBatch: blocksPerBatch,
signer: coordinator,
sleep,
})
}
Expand All @@ -287,6 +289,7 @@ task('clr-tally', 'Tally votes')
blocksPerBatch: getNumber(blocksPerBatch),
maciTxHash,
maciStateFile: outputPath,
signer: coordinator,
quiet,
})
await genProofs(genProofArgs)
Expand All @@ -305,6 +308,7 @@ task('clr-tally', 'Tally votes')
maciAddress,
messageProcessorAddress,
tallyAddress,
signer: coordinator,
quiet,
})

Expand Down
8 changes: 4 additions & 4 deletions contracts/utils/circuits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export type CircuitInfo = {

export const CIRCUITS: { [name: string]: CircuitInfo } = {
micro: {
processMessagesZkey: 'processmessages_6-8-2-3_final.zkey',
processWitness: 'processMessages_6-8-2-3_test',
processWasm: 'processmessages_6-8-2-3.wasm',
processDatFile: 'processMessages_6-8-2-3_test.dat',
processMessagesZkey: 'ProcessMessages_6-8-2-3_test.0.zkey',
processWitness: 'ProcessMessages_6-8-2-3_test',
processWasm: 'ProcessMessages_6-8-2-3_test.wasm',
processDatFile: 'ProcessMessages_6-8-2-3_test.dat',
tallyVotesZkey: 'tallyvotes_6-2-3_final.zkey',
tallyWitness: 'tallyVotes_6-2-3_test',
tallyWasm: 'tallyvotes_6-2-3.wasm',
Expand Down
9 changes: 7 additions & 2 deletions contracts/utils/maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
LEAVES_PER_NODE,
genTallyResultCommitment,
Keypair,
Tally as TallyData,
} from '@clrfund/common'
import * as os from 'os'
import {
Expand All @@ -20,7 +21,6 @@ import {
GenProofsArgs,
genLocalState,
verify,
TallyData,
} from 'maci-cli'

import { getTalyFilePath, isPathExist } from './misc'
Expand Down Expand Up @@ -183,6 +183,8 @@ type getGenProofArgsInput = {
endBlock?: number
// MACI state file
maciStateFile?: string
// transaction signer
signer: Signer
// flag to turn on verbose logging in MACI cli
quiet?: boolean
}
Expand All @@ -204,6 +206,7 @@ export function getGenProofArgs(args: getGenProofArgsInput): GenProofsArgs {
startBlock,
endBlock,
maciStateFile,
signer,
quiet,
} = args

Expand Down Expand Up @@ -237,6 +240,7 @@ export function getGenProofArgs(args: getGenProofArgsInput): GenProofsArgs {
startBlock,
endBlock,
stateFile: maciStateFile,
signer,
quiet,
}
} else {
Expand Down Expand Up @@ -267,6 +271,7 @@ export function getGenProofArgs(args: getGenProofArgsInput): GenProofsArgs {
startBlock,
endBlock,
stateFile: maciStateFile,
signer,
quiet,
}
}
Expand All @@ -289,7 +294,7 @@ export async function mergeMaciSubtrees({
}: {
maciAddress: string
pollId: bigint
signer?: Signer
signer: Signer
numQueueOps?: string
quiet?: boolean
}) {
Expand Down
9 changes: 0 additions & 9 deletions contracts/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,3 @@ export type RoundFileContent = {
projects: Project[]
tally: any
}

export type Tally = {
results: {
tally: string[]
}
totalVoiceCreditsPerVoteOption: {
tally: string[]
}
}
2 changes: 1 addition & 1 deletion vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@walletconnect/modal": "^2.6.0",
"crypto-js": "^4.1.1",
"ethereum-blockies-base64": "^1.0.2",
"ethers": "^6.9.2",
"ethers": "^6.11.1",
"floating-vue": "^2.0.0-beta.20",
"google-spreadsheet": "^3.3.0",
"graphql": "^16.6.0",
Expand Down
Loading

0 comments on commit 4268c4f

Please sign in to comment.