Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the genProofs and proveOnChain instructions #560

Merged
merged 5 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions contracts/tests/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 4 additions & 1 deletion contracts/utils/maci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 totalProcessed = i + data[1].length
callback(totalProcessed, receipt)
}
totalGasUsed = totalGasUsed.add(receipt.gasUsed)
}
Expand Down
20 changes: 12 additions & 8 deletions docs/tally-verify.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ 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
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
Expand All @@ -64,31 +66,33 @@ 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 <ETH_HOSTNAME> \
--contract <MACI_CONTRACT_ADDR> \
--privkey <COORDINATOR_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`).
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 <json-rpc-api-url> \
--contract <maci-address> \
--privkey <coordinator-private-key> \
--eth-privkey <eth-private-key> \
--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:
Expand Down