Skip to content

Commit

Permalink
adjust tally scripts for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Apr 3, 2024
1 parent d20877a commit 4b513e8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
10 changes: 6 additions & 4 deletions contracts/sh/runScriptTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ yarn hardhat contribute --network ${HARDHAT_NETWORK}

yarn hardhat time-travel --seconds ${ROUND_DURATION} --network ${HARDHAT_NETWORK}

# run the tally script
# tally the votes
NODE_OPTIONS="--max-old-space-size=4096"
yarn hardhat tally \
yarn hardhat gen-proofs \
--rapidsnark ${RAPID_SNARK} \
--batch-size 8 \
--output-dir ${OUTPUT_DIR} \
--proof-dir ${OUTPUT_DIR} \
--maci-start-block 0 \
--network "${HARDHAT_NETWORK}"
yarn hardhat prove-on-chain --proof-dir ${OUTPUT_DIR} --network "${HARDHAT_NETWORK}"
yarn hardhat publish-tally-results --proof-dir ${OUTPUT_DIR} --network "${HARDHAT_NETWORK}"

# finalize the round
yarn hardhat finalize --tally-file ${TALLY_FILE} --network ${HARDHAT_NETWORK}
Expand Down
10 changes: 7 additions & 3 deletions contracts/tasks/runners/genProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* Sample usage:
*
* yarn hardhat tally --clrfund <clrfund-address> --proof-dir <proof output directory> \
* yarn hardhat gen-proofs --clrfund <clrfund-address> --proof-dir <proof output directory> \
* --maci-tx-hash <hash> --network <network>
*
*/
Expand All @@ -36,9 +36,10 @@ import { getMaciStateFilePath } from '../../utils/misc'
import { EContracts } from '../../utils/types'
import { Subtask } from '../helpers/Subtask'
import { getCurrentFundingRoundContract } from '../../utils/contracts'
import { ContractStorage } from '../helpers/ContractStorage'

task('gen-proofs', 'Generate MACI proofs offchain')
.addParam('clrfund', 'FundingRound contract address')
.addOptionalParam('clrfund', 'FundingRound contract address')
.addParam('proofDir', 'The proof output directory')
.addOptionalParam('maciTxHash', 'MACI creation transaction hash')
.addOptionalParam(
Expand Down Expand Up @@ -89,6 +90,7 @@ task('gen-proofs', 'Generate MACI proofs offchain')
console.log('Verbose logging enabled:', !quiet)

const { ethers, network } = hre
const storage = ContractStorage.getInstance()
const subtask = Subtask.getInstance(hre)
subtask.setHre(hre)

Expand Down Expand Up @@ -121,8 +123,10 @@ task('gen-proofs', 'Generate MACI proofs offchain')

await subtask.logStart()

const clrfundContractAddress =
clrfund ?? storage.mustGetAddress(EContracts.ClrFund, network.name)
const fundingRoundContract = await getCurrentFundingRoundContract(
clrfund,
clrfundContractAddress,
coordinator,
ethers
)
Expand Down
10 changes: 7 additions & 3 deletions contracts/tasks/runners/proveOnChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { HardhatEthersHelpers } from '@nomicfoundation/hardhat-ethers/types'
import { EContracts } from '../../utils/types'
import { Subtask } from '../helpers/Subtask'
import { getCurrentFundingRoundContract } from '../../utils/contracts'
import { ContractStorage } from '../helpers/ContractStorage'

/**
* Get the message processor contract address from the tally contract
Expand All @@ -40,7 +41,7 @@ async function getMessageProcessorAddress(
}

task('prove-on-chain', 'Prove on chain with the MACI proofs')
.addParam('clrfund', 'ClrFund contract address')
.addOptionalParam('clrfund', 'ClrFund contract address')
.addParam('proofDir', 'The proof output directory')
.addFlag('manageNonce', 'Whether to manually manage transaction nonce')
.addOptionalParam(
Expand All @@ -52,7 +53,8 @@ task('prove-on-chain', 'Prove on chain with the MACI proofs')
.setAction(async ({ clrfund, quiet, manageNonce, proofDir }, hre) => {
console.log('Verbose logging enabled:', !quiet)

const { ethers } = hre
const { ethers, network } = hre
const storage = ContractStorage.getInstance()
const subtask = Subtask.getInstance(hre)
subtask.setHre(hre)

Expand All @@ -67,8 +69,10 @@ task('prove-on-chain', 'Prove on chain with the MACI proofs')

await subtask.logStart()

const clrfundContractAddress =
clrfund ?? storage.mustGetAddress(EContracts.ClrFund, network.name)
const fundingRoundContract = await getCurrentFundingRoundContract(
clrfund,
clrfundContractAddress,
coordinator,
ethers
)
Expand Down
10 changes: 7 additions & 3 deletions contracts/tasks/runners/publishTallyResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { EContracts } from '../../utils/types'
import { Subtask } from '../helpers/Subtask'
import { getCurrentFundingRoundContract } from '../../utils/contracts'
import { getTalyFilePath } from '../../utils/misc'
import { ContractStorage } from '../helpers/ContractStorage'

/**
* Publish the tally IPFS hash on chain if it's not already published
Expand Down Expand Up @@ -94,7 +95,7 @@ async function getRecipientTreeDepth(
}

task('publish-tally-results', 'Publish tally results')
.addParam('clrfund', 'ClrFund contract address')
.addOptionalParam('clrfund', 'ClrFund contract address')
.addParam('proofDir', 'The proof output directory')
.addOptionalParam(
'batchSize',
Expand All @@ -106,7 +107,8 @@ task('publish-tally-results', 'Publish tally results')
.addFlag('quiet', 'Whether to log on the console')
.setAction(
async ({ clrfund, proofDir, batchSize, manageNonce, quiet }, hre) => {
const { ethers } = hre
const { ethers, network } = hre
const storage = ContractStorage.getInstance()
const subtask = Subtask.getInstance(hre)
subtask.setHre(hre)

Expand All @@ -119,8 +121,10 @@ task('publish-tally-results', 'Publish tally results')

await subtask.logStart()

const clrfundContractAddress =
clrfund ?? storage.mustGetAddress(EContracts.ClrFund, network.name)
const fundingRoundContract = await getCurrentFundingRoundContract(
clrfund,
clrfundContractAddress,
coordinator,
ethers
)
Expand Down

0 comments on commit 4b513e8

Please sign in to comment.