Skip to content

Commit

Permalink
fix contract verification error
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Nov 28, 2023
1 parent 781e360 commit 3590b32
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 72 deletions.
55 changes: 48 additions & 7 deletions contracts/cli/newClrFund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* If token is not provided, a new ERC20 token will be created
*/
import { BigNumber } from 'ethers'
import { ethers, network } from 'hardhat'
import { getEventArg } from '../utils/contracts'
import { newMaciPrivateKey } from '../utils/maci'
Expand All @@ -31,11 +32,13 @@ import {
setCoordinator,
} from '../utils/deployment'
import { JSONFile } from '../utils/JSONFile'
import { program } from 'commander'
import { Option, program } from 'commander'
import dotenv from 'dotenv'
import { UNIT } from '../utils/constants'
dotenv.config()

const DEFAULT_DEPOSIT_AMOUNT = '0.001'

program
.description('Deploy a new ClrFund instance')
.requiredOption(
Expand All @@ -44,16 +47,43 @@ program
)
.option('-c --coordinator <coordinator>', 'The coordinator ETH address')
.option('-t --token <address>', 'The native token address')
.option('-a --initial-token-supply <amount>', 'Initial token amount', '1000')
.option('-u --user-registry-type <type>', 'The user registry type')
.addOption(
new Option(
'-a --initial-token-supply <amount>',
'Initial token amount for new token'
).default(1000)
)
.addOption(
new Option(
'-u --user-registry-type <type>',
'The user registry type'
).choices(['simple', 'brightid', 'merkle', 'storage'])
)
.option('-x --brightid-context <context>', 'The brightid context')
.option('-v --brightid-verifier <verifier>', 'The brightid verifier address')
.addOption(
new Option(
'-v --brightid-verifier <verifier>',
'The brightid verifier address'
).default('0xdbf0b2ee9887fe11934789644096028ed3febe9c')
)
.option(
'-o --brightid-sponsor <sponsor>',
'The brightid sponsor contract address'
)
.option('-r --recipient-registry-type <type>', 'The recipient registry type')
.option('-b --deposit <deposit>', 'The optimistic recipient registry deposit')
.addOption(
new Option(
'-r --recipient-registry-type <type>',
'The recipient registry type'
)
.choices(['simple', 'optimistic'])
.default('optimistic')
)
.addOption(
new Option(
'-b --deposit <deposit>',
'The optimistic recipient registry deposit'
).default(DEFAULT_DEPOSIT_AMOUNT)
)
.option(
'-p --challenge-period <period>',
'The optimistic recipient registry challenge period in seconds',
Expand Down Expand Up @@ -149,20 +179,23 @@ async function main(args: any) {
// set recipient registry
let recipientRegistryAddress = args.recipientRegistryAddress
if (!recipientRegistryAddress) {
const deposit = parseDeposit(args.deposit)
const recipientRegistryContract = await deployRecipientRegistry({
ethers,
signer,
type: args.recipientRegistryType,
challengePeriod: args.challengePeriod,
deposit: args.deposit,
deposit,
controller: clrfund,
})
recipientRegistryAddress = recipientRegistryContract.address
}

const setRecipientRegistryTx = await clrfundContract.setRecipientRegistry(
recipientRegistryAddress
)
await setRecipientRegistryTx.wait()

console.log(
`Set ${args.recipientRegistryType} recipient registry: ${recipientRegistryAddress}`
)
Expand All @@ -172,6 +205,14 @@ async function main(args: any) {
}
}

function parseDeposit(deposit: string): BigNumber {
try {
return ethers.utils.parseUnits(deposit)
} catch (e) {
throw new Error(`Error parsing deposit ${(e as Error).message}`)
}
}

main(program.opts())
.then(() => {
process.exit(0)
Expand Down
15 changes: 12 additions & 3 deletions contracts/cli/newRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ program
'Create a new BrightId user registry',
false
)
.option('-x --context <context>', 'The brightid context')
.option('-v --verifier <verifier>', 'The brightid verifier address')
.option('-o --sponsor <sponsor>', 'The brightid sponsor contract address')
.option(
'-x --context <context>',
'The brightid context for the new user registry'
)
.option(
'-v --verifier <verifier>',
'The brightid verifier address for the new user registry'
)
.option(
'-o --sponsor <sponsor>',
'The brightid sponsor contract address for the new user registry'
)
.option(
'-s --state-file <file>',
'File to store the ClrFundDeployer address for e2e testing'
Expand Down
1 change: 1 addition & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '@nomiclabs/hardhat-waffle'
import '@nomiclabs/hardhat-ganache'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-etherscan'
import './tasks'

dotenv.config()

Expand Down
29 changes: 0 additions & 29 deletions contracts/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import './newDeployer'
import './newClrFund'
import './newMaciKey'
import './newRound'
import './setToken'
import './setCoordinator'
import './setUserRegistry'
import './setRecipientRegistry'
import './setMaciParameters'
import './setPollFactory'
import './cancelRound'
import './addContributors'
import './addRecipients'
import './contribute'
import './vote'
import './timeTravel'
import './finalize'
import './claim'

import './verifyAll'
import './verifyMaciFactory'
import './verifyRound'
import './verifyMaci'
import './verifyRecipientRegistry'
import './verifyUserRegistry'
import './auditTally'
import './exportRound'
import './mergeAllocations'
import './deploySponsor'
import './loadUsers'
import './findStorageSlot'
import './setStorageRoot'
import './loadMerkleUsers'

import './pubkey'
3 changes: 2 additions & 1 deletion contracts/tasks/verifyAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ async function verifyTally(tally: Contract, run: any): Promise<string> {

async function verifyPoll(pollContract: Contract, run: any): Promise<string> {
try {
const [, duration] = await pollContract.getDeployTimeAndDuration()
const constructorArguments = await Promise.all([
pollContract.duration(),
Promise.resolve(duration),
pollContract.maxValues(),
pollContract.treeDepths(),
pollContract.batchSizes(),
Expand Down
40 changes: 8 additions & 32 deletions contracts/tasks/verifyMaci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,19 @@ import { task } from 'hardhat/config'
* Verifies the MACI contract
* - it constructs the constructor arguments by querying the MACI contract
* - it calls the etherscan hardhat plugin to verify the contract
*
* Sample usage:
* yarn hardhat verify-maci <maci-address> --network <network>
*/
task('verify-maci', 'Verify a MACI contract')
.addPositionalParam('maciAddress', 'MACI contract address')
.setAction(async ({ maciAddress }, { run, ethers }) => {
const maci = await ethers.getContractAt('MACI', maciAddress)
const treeDepths = await maci.treeDepths()
const tallyBatchSize = await maci.tallyBatchSize()
const messageBatchSize = await maci.messageBatchSize()
const maxUsers = await maci.maxUsers()
const maxMessages = await maci.maxMessages()
const maxVoteOptions = await maci.voteOptionsMaxLeafIndex()
const signUpGatekeeper = await maci.signUpGatekeeper()
const batchUstVerifier = await ethers.provider.getStorageAt(maciAddress, 1)
const qvtVerifier = await ethers.provider.getStorageAt(maciAddress, 2)
const signUpDurationSeconds = await maci.signUpDurationSeconds()
const votingDurationSeconds = await maci.votingDurationSeconds()
const initialVoiceCreditProxy = await maci.initialVoiceCreditProxy()
const coordinatorAddress = await maci.coordinatorAddress()
const coordinatorPubKey = await maci.coordinatorPubKey()

const constructorArguments = [
{
stateTreeDepth: treeDepths[0],
messageTreeDepth: treeDepths[1],
voteOptionTreeDepth: treeDepths[2],
},
{ tallyBatchSize, messageBatchSize },
{ maxUsers, maxMessages, maxVoteOptions },
signUpGatekeeper,
ethers.utils.hexDataSlice(batchUstVerifier, 12),
ethers.utils.hexDataSlice(qvtVerifier, 12),
signUpDurationSeconds,
votingDurationSeconds,
initialVoiceCreditProxy,
{ x: coordinatorPubKey.x, y: coordinatorPubKey.y },
coordinatorAddress,
]
const constructorArguments = await Promise.all([
maci.pollFactory(),
maci.signUpGatekeeper(),
maci.initialVoiceCreditProxy(),
])

console.log('Verifying the MACI contract', maciAddress)
console.log('Constructor arguments', constructorArguments)
Expand Down

0 comments on commit 3590b32

Please sign in to comment.