Skip to content

Commit

Permalink
refactor deployment scripts to allow increment deployment and manuall…
Browse files Browse the repository at this point in the history
…y manage nonce
  • Loading branch information
yuetloo committed Mar 11, 2024
1 parent a53286e commit 2bf1d1c
Show file tree
Hide file tree
Showing 89 changed files with 3,818 additions and 2,157 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,24 @@ yarn && yarn build
husky - Git hooks installed
```

### Copy configuration for contract deployment

```sh
# adjust the configuration for localhost if necessary
cp contracts/deploy-config-example.json contracts/deploy-config.json
```

### Generate coordinator MACI key
```sh
yarn hardhat new-maci-key
```

### Copy env for contracts

```sh
cp contracts/.env.example contracts/.env # adjust if necessary
# update COORDINATOR_MACISK with the MACI key from previous step
# adjust other configuration if necessary
cp contracts/.env.example contracts/.env
```

### Copy env for the webapp
Expand Down
2 changes: 2 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ proof_output
typechain-types
params
local-state.json
deploy-config.json
deployed-contracts.json
28 changes: 21 additions & 7 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ yarn e2e
```

## Scripts
### Generate coordinator key

```
yarn hardhat new-maci-key
```

### Copy env for contracts

```sh
# update COORDINATOR_MACISK with the MACI key from previous step
# adjust other configuration if necessary
cp contracts/.env.example contracts/.env
```

### Copy configuration for contract deployment

```sh
# adjust the configuration for localhost if necessary
cp contracts/deploy-config-example.json contracts/deploy-config.json
```

### Deploy the ClrFund contract

Expand Down Expand Up @@ -50,12 +70,6 @@ The test includes setting coordinator keys, contribute funds, vote, tally, final
The following command will verify all clr.fund contracts. It will log a warning if contract already verified or missing.

```
yarn hardhat verify-all --clrfund <clrfund-address> --network <network>
yarn hardhat verify-all --network <network>
```

### Generate coordinator key
If you want to genereate a single key to coordinate multiple rounds.

```
yarn ts-node tasks/maciNewKey.ts
```
58 changes: 58 additions & 0 deletions contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"localhost": {
"VkRegistry": {
"circuit": "micro",
"paramsDirectory": "./params"
},
"ClrFund": {
"template": false,
"coordinator": "",
"token": "",
"userRegistry": "SimpleUserRegistry",
"recipientRegistry": "SimpleRecipientRegistry"
},
"FundingRound": {
"duration": 900
},
"AnyOldERC20Token": {
"initialSupply": "10000000000000000000000"
},
"OptimisticRecipientRegistry": {
"challengePeriodSeconds": 9007199254740990,
"deposit": "0.001"
},
"BrightIdUserRegistry": {
"deploy": false,
"context": "clrfund-arbitrum-goerli",
"verifier": "0xdbf0b2ee9887fe11934789644096028ed3febe9c"
}
},
"optimism-sepolia": {
"VkRegistry": {
"circuit": "micro",
"paramsDirectory": "./params"
},
"ClrFund": {
"template": false,
"coordinator": "",
"token": "0x65bc8dd04808d99cf8aa6749f128d55c2051edde",
"userRegistry": "SemaphoreUserRegistry",
"recipientRegistry": "OptimisticRecipientRegistry"
},
"FundingRound": {
"duration": 900
},
"AnyOldERC20Token": {
"initialSupply": "10000000000000000000000"
},
"OptimisticRecipientRegistry": {
"challengePeriodSeconds": 9007199254740990,
"deposit": "0.001"
},
"BrightIdUserRegistry": {
"context": "clrfund-arbitrum-goerli",
"verifier": "0xdbf0b2ee9887fe11934789644096028ed3febe9c",
"sponsor": "0xC7c81634Dac2de4E7f2Ba407B638ff003ce4534C"
}
}
}
37 changes: 7 additions & 30 deletions contracts/sh/deployLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,22 @@ set -e
# Local settings
export CLRFUND_ROOT=$(cd $(dirname $0) && cd ../.. && pwd)
export CONTRACTS_DIRECTORY=${CLRFUND_ROOT}/contracts
export CIRCUIT=micro
export NETWORK=localhost
export CIRCUIT_DIRECTORY=${CONTRACTS_DIRECTORY}/params
export HARDHAT_NETWORK=localhost
export STATE_FILE=${CONTRACTS_DIRECTORY}/local-state.json

# the sample config has default configuration for localhost deployment
cp deploy-config-example.json deploy-config.json

# download the circuit params if not exists
if ! [ -f "${CIRCUIT_DIRECTORY}/ProcessMessages_6-9-2-3/ProcessMessages_6-9-2-3.zkey" ]; then
if ! [ -f "${CONTRACTS_DIRECTORY}/params/ProcessMessages_6-9-2-3/ProcessMessages_6-9-2-3.zkey" ]; then
${CLRFUND_ROOT}/.github/scripts/download-6-9-2-3.sh
fi

# 20 mins
ROUND_DURATION=1800

# A helper to extract field value from the JSON state file
# The pattern "field": "value" must be on 1 line
# Usage: extract 'clrfund'
function extract() {
val=$(cat "${STATE_FILE}" | grep -o "${1}\": *\"[^\"]*" | grep -o "[^\"]*$")
echo ${val}
}

# create a new maci key for the coordinator
MACI_KEYPAIR=$(yarn ts-node tasks/maciNewKey.ts)
MACI_KEYPAIR=$(yarn hardhat new-maci-key)
export COORDINATOR_MACISK=$(echo "${MACI_KEYPAIR}" | grep -o "macisk.*$")

# create a new instance of ClrFund
yarn hardhat new-clrfund \
--circuit "${CIRCUIT}" \
--directory "${CIRCUIT_DIRECTORY}" \
--user-registry-type simple \
--recipient-registry-type simple \
--state-file ${STATE_FILE} \
--network ${HARDHAT_NETWORK}
yarn hardhat new-clrfund --network ${NETWORK}

# deploy a new funding round
CLRFUND=$(extract 'clrfund')
yarn hardhat new-round \
--clrfund "${CLRFUND}" \
--duration "${ROUND_DURATION}" \
--state-file ${STATE_FILE} \
--network ${HARDHAT_NETWORK}
yarn hardhat new-round --network ${NETWORK}
63 changes: 14 additions & 49 deletions contracts/sh/runScriptTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,42 @@ set -e
# Test settings
NOW=$(date +%s)
export OUTPUT_DIR="./proof_output/${NOW}"
export CIRCUIT=micro
export CIRCUIT_DIRECTORY=${CIRCUIT_DIRECTORY:-"./params"}
export STATE_FILE=${OUTPUT_DIR}/state.json
export TALLY_FILE=${OUTPUT_DIR}/tally.json
export HARDHAT_NETWORK=localhost
export RAPID_SNARK=${RAPID_SNARK:-~/rapidsnark/package/bin/prover}

# 20 mins
ROUND_DURATION=1800

mkdir -p ${OUTPUT_DIR}

# A helper to extract field value from the JSON state file
# The pattern "field": "value" must be on 1 line
# Usage: extract 'clrfund'
function extract() {
val=$(cat "${STATE_FILE}" | grep -o "${1}\": *\"[^\"]*" | grep -o "[^\"]*$")
echo ${val}
}
# create a deploy config using the example version
cp deploy-config-example.json deploy-config.json

# create a new maci key for the coordinator
MACI_KEYPAIR=$(yarn ts-node tasks/maciNewKey.ts)
MACI_KEYPAIR=$(yarn hardhat new-maci-key)
export COORDINATOR_MACISK=$(echo "${MACI_KEYPAIR}" | grep -o "macisk.*$")

# create a new instance of ClrFund
yarn hardhat new-clrfund \
--circuit "${CIRCUIT}" \
--directory "${CIRCUIT_DIRECTORY}" \
--user-registry-type simple \
--recipient-registry-type simple \
--state-file ${STATE_FILE} \
--network ${HARDHAT_NETWORK}
yarn hardhat new-clrfund --network ${HARDHAT_NETWORK}

# # deploy a new funding round
CLRFUND=$(extract 'clrfund')
yarn hardhat new-round \
--clrfund "${CLRFUND}" \
--duration "${ROUND_DURATION}" \
--state-file ${STATE_FILE} \
--network ${HARDHAT_NETWORK}

yarn hardhat test-add-contributors --clrfund "${CLRFUND}" --network ${HARDHAT_NETWORK}
yarn hardhat test-add-recipients --clrfund "${CLRFUND}" --network ${HARDHAT_NETWORK}
# deploy a new funding round
yarn hardhat new-round --network ${HARDHAT_NETWORK}

yarn hardhat test-contribute --state-file ${STATE_FILE} --network ${HARDHAT_NETWORK}
yarn hardhat test-vote --state-file ${STATE_FILE} --network ${HARDHAT_NETWORK}
yarn hardhat add-recipients --network ${HARDHAT_NETWORK}
yarn hardhat contribute --network ${HARDHAT_NETWORK}

yarn hardhat test-time-travel --seconds ${ROUND_DURATION} --network ${HARDHAT_NETWORK}
ROUND_DURATION=$(node -e 'const config=JSON.parse(fs.readFileSync(`./deploy-config.json`).toString()); console.log(config.localhost?.FundingRound?.duration || 1000)')
yarn hardhat time-travel --seconds ${ROUND_DURATION} --network ${HARDHAT_NETWORK}

# run the tally script
MACI_TRANSACTION_HASH=$(extract 'maciTxHash')
NODE_OPTIONS="--max-old-space-size=4096"
yarn hardhat clr-tally \
--clrfund ${CLRFUND} \
--circuit-directory ${CIRCUIT_DIRECTORY} \
--circuit "${CIRCUIT}" \
yarn hardhat tally \
--rapidsnark ${RAPID_SNARK} \
--batch-size 8 \
--output-dir ${OUTPUT_DIR} \
--maci-tx-hash "${MACI_TRANSACTION_HASH}" \
--network "${HARDHAT_NETWORK}"

# finalize the round
yarn hardhat clr-finalize --clrfund "${CLRFUND}" --tally-file ${TALLY_FILE} --network ${HARDHAT_NETWORK}
yarn hardhat finalize --tally-file ${TALLY_FILE} --network ${HARDHAT_NETWORK}

# claim funds
FUNDING_ROUND=$(extract 'fundingRound')
yarn hardhat clr-claim --funding-round "${FUNDING_ROUND}" --tally-file ${TALLY_FILE} \
--recipient 1 \
--network ${HARDHAT_NETWORK}

yarn hardhat clr-claim --funding-round "${FUNDING_ROUND}" --tally-file ${TALLY_FILE} \
--recipient 2 \
--network ${HARDHAT_NETWORK}
yarn hardhat claim --recipient 1 --tally-file ${TALLY_FILE} --network ${HARDHAT_NETWORK}
yarn hardhat claim --recipient 2 --tally-file ${TALLY_FILE} --network ${HARDHAT_NETWORK}
36 changes: 0 additions & 36 deletions contracts/tasks/configure/setCoordinator.ts

This file was deleted.

47 changes: 0 additions & 47 deletions contracts/tasks/configure/setFundingRoundFactory.ts

This file was deleted.

37 changes: 0 additions & 37 deletions contracts/tasks/configure/setMaciParameters.ts

This file was deleted.

Loading

0 comments on commit 2bf1d1c

Please sign in to comment.