From 9ed63aa9eeff4e1cd3b83def14bb21075515f1eb Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 16 Sep 2022 14:07:07 -0400 Subject: [PATCH 1/5] add the BrightId sponsor environment variable used to deploy BrightId user registry --- contracts/.env.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/.env.example b/contracts/.env.example index 2000284fd..0ff8d6387 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -7,6 +7,8 @@ USER_REGISTRY_TYPE=simple BRIGHTID_CONTEXT=clr.fund # BrightId node addr that signs verifications. Node One uses this one BRIGHTID_VERIFIER_ADDR=0xb1d71F62bEe34E9Fc349234C201090c33BCdF6DB +# The contract that emits the sponsor events that the BrightId node is listening for +BRIGHTID_SPONSOR= # JSON-RPC endpoint to the selected network JSONRPC_HTTP_URL=https://eth-goerli.alchemyapi.io/v2/ADD_API_KEY From 2f4f597202db50561b8fe0d3e7b706fbb52cc78b Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 16 Sep 2022 14:08:04 -0400 Subject: [PATCH 2/5] fix the incorrect report of total tally results processed in the finalize script --- contracts/utils/maci.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/utils/maci.ts b/contracts/utils/maci.ts index 0f80d27f2..b5784a1c7 100644 --- a/contracts/utils/maci.ts +++ b/contracts/utils/maci.ts @@ -203,7 +203,10 @@ export async function addTallyResultsBatch( const tx = await fundingRound.addTallyResultsBatch(...data) const receipt = await tx.wait() if (callback) { - callback(i + batchSize, receipt) + // the 2nd element in the data array has the array of + // recipients to be processed for the batch + const totalProccessed = i + data[1].length + callback(totalProccessed, receipt) } totalGasUsed = totalGasUsed.add(receipt.gasUsed) } From d48df05e84070ae90e54d2ab34ca107c629c17bf Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 16 Sep 2022 14:09:07 -0400 Subject: [PATCH 3/5] fix tally instruction to run genProof instead of duplicate proveOnChain --- docs/tally-verify.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/tally-verify.md b/docs/tally-verify.md index 6a4e2ecd3..cd846f5d9 100644 --- a/docs/tally-verify.md +++ b/docs/tally-verify.md @@ -33,6 +33,7 @@ The contract deployment scripts, `deploy*.ts` in the [clrfund repository](https: ``` ### Recompile the contracts: +Compile the contracts to generate the ABI that the MACI command lines use in the next step. ``` cd ../contracts @@ -40,6 +41,7 @@ npm run compileSol ``` ### Generate coordinator key +Generate the coordinator key used to encrypt messages. The key will be used when deploying new round. ``` cd ../cli @@ -64,18 +66,20 @@ node build/index.js fetchLogs \ --output logs ``` -Decrypt messages and tally the votes: +Decrypt messages, tally the votes and generate proofs: ``` -node build/index.js proveOnChain \ +node build/index.js genProofs \ --eth-provider \ --contract \ --privkey \ - --output proofs.json \ - --tally-file tally.json + --tally-file tally.json \ + --logs-file logs \ + --macistate macistate \ + --output proofs.json ``` -Coordinator private key must be in MACI key format (starts with `macisk`). +Coordinator private key must be in the MACI key format (starts with `macisk`). Ethereum private key can be any private key that controls the necessary amount of ETH to pay for gas. The `genProofs` command will create two files: `proofs.json` and `tally.json`. The `proofs.json` file will be needed to run the next command which submits proofs to MACI contract: From 59ef416e93ea9b61153b681f9f0452c34428a335 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 16 Sep 2022 14:43:26 -0400 Subject: [PATCH 4/5] add unit test case to verify process count from the callback of addTallyResults --- contracts/tests/round.ts | 26 ++++++++++++++++++++++++++ contracts/utils/maci.ts | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/contracts/tests/round.ts b/contracts/tests/round.ts index 2f76db7c6..cb922080f 100644 --- a/contracts/tests/round.ts +++ b/contracts/tests/round.ts @@ -1329,6 +1329,32 @@ describe('Funding Round', () => { ) ).to.revertedWith('FundingRound: Vote results already verified') }) + + it('returns correct proccessed count in the callback for processing tally results', async () => { + const startIndex = 0 + const batchSize = 10 + let batchCount = 0 + const total = smallTallyTestData.results.tally.length + const lastBatch = Math.ceil(total / batchSize) + await addTallyResultsBatch( + fundingRound.connect(coordinator), + tallyTreeDepth, + smallTallyTestData, + batchSize, + startIndex, + (processed) => { + batchCount++ + if (batchCount === lastBatch) { + expect(processed).to.equal(total, 'Incorrect last batch count') + } else { + expect(processed).to.equal( + batchCount * batchSize, + 'Incorrect proccesed count' + ) + } + } + ) + }) }) describe('getRecipientTallyResultsBatch', () => { diff --git a/contracts/utils/maci.ts b/contracts/utils/maci.ts index b5784a1c7..62af5db3d 100644 --- a/contracts/utils/maci.ts +++ b/contracts/utils/maci.ts @@ -205,8 +205,8 @@ export async function addTallyResultsBatch( if (callback) { // the 2nd element in the data array has the array of // recipients to be processed for the batch - const totalProccessed = i + data[1].length - callback(totalProccessed, receipt) + const totalProcessed = i + data[1].length + callback(totalProcessed, receipt) } totalGasUsed = totalGasUsed.add(receipt.gasUsed) } From 6c253b440eb0bedd43c81c9650a3d26dbbcb39e8 Mon Sep 17 00:00:00 2001 From: yuetloo Date: Fri, 16 Sep 2022 15:51:43 -0400 Subject: [PATCH 5/5] fix the argument list for proveOnChain --- docs/tally-verify.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tally-verify.md b/docs/tally-verify.md index cd846f5d9..9d117e3bd 100644 --- a/docs/tally-verify.md +++ b/docs/tally-verify.md @@ -79,20 +79,20 @@ node build/index.js genProofs \ --output proofs.json ``` -Coordinator private key must be in the MACI key format (starts with `macisk`). -Ethereum private key can be any private key that controls the necessary amount of ETH to pay for gas. +The coordinator private key (`COORDINATOR_PRIVKEY`) must be in the MACI key format (starts with `macisk`). It is used to decrypt messages. -The `genProofs` command will create two files: `proofs.json` and `tally.json`. The `proofs.json` file will be needed to run the next command which submits proofs to MACI contract: +The `genProofs` command will create two files: `proofs.json` and `tally.json`. The `proofs.json` file will be needed to run the next command, `proveOnChain`, which submits proofs to the MACI contract: ``` node build/index.js proveOnChain \ --eth-provider \ --contract \ - --privkey \ --eth-privkey \ --proof-file proofs.json ``` +The Ethereum private key (`eth-private-key`) can be any private key that controls the necessary amount of ETH to pay for gas. + The process may take several hours. Results can be found in `tally.json` file, which must then be published via IPFS. Finally, the [CID](https://ipfs.io/ipns/docs.ipfs.io/concepts/content-addressing/) of tally file must be submitted to `FundingRound` contract: