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

Add incremental deployment and manual nonce management options #728

Merged
merged 19 commits into from
Mar 21, 2024
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
23 changes: 17 additions & 6 deletions .github/workflows/cancel-round.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
name: Cancel current round

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
clrfund:
description: 'Clrfund contract address'
required: true
default: '0x87790498127ff044f43b9230506833ca89113757'
network:
description: 'Network'
required: true
default: 'arbitrum-sepolia'
jsonrpc_url:
description: jsonrpc url to node
required: false

env:
NODE_VERSION: 20.x
SUBGRPAH_URL: "https://api.thegraph.com/subgraphs/name/clrfund/clrfund-testnet"
WALLET_PRIVATE_KEY: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}
NETWORK: "arbitrum-sepolia"

jobs:
cancel-round:
Expand All @@ -26,6 +37,6 @@ jobs:
- name: Run the cancel round script
run: |
cd contracts
export CLRFUND=$(curl -X POST -d '{"query":"{clrFunds {id}}"}' $SUBGRPAH_URL)
export CLRFUND_ADDRESS=$(node -e 'console.log(JSON.parse(process.env.CLRFUND).data.clrFunds[0].id)')
yarn hardhat clr-cancel --clrfund "${CLRFUND_ADDRESS}" --network ${NETWORK}
yarn hardhat cancel-round \
--clrfund ${{ github.event.inputs.clrfund }} \
--network ${{ github.event.inputs.network }}
9 changes: 4 additions & 5 deletions .github/workflows/finalize-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ on:
default: '0x87790498127ff044f43b9230506833ca89113757'
maci_tx_hash:
description: 'MACI creation transaction hash'
required: true
default: '0x1280527bdb23cbd4906c94e152722792fc59400bfccfc89709beb2531fc55365'
required: false
blocks_per_batch:
description: 'Blocks of logs to fetch per batch'
required: true
default: '9000'
network:
description: 'Network'
required: true
default: 'optimism-sepolia'
default: 'arbitrum-sepolia'
jsonrpc_url:
description: jsonrpc url to node
required: false
Expand Down Expand Up @@ -83,12 +82,12 @@ jobs:
# tally and finalize
cd monorepo/contracts
mkdir -p proof_output
yarn hardhat clr-tally --clrfund "${CLRFUND_ADDRESS}" --network "${NETWORK}" \
yarn hardhat tally --clrfund "${CLRFUND_ADDRESS}" --network "${NETWORK}" \
--rapidsnark ${RAPID_SNARK} \
--circuit-directory ${CIRCUIT_DIRECTORY} \
--blocks-per-batch ${BLOCKS_PER_BATCH} \
--maci-tx-hash "${MACI_TX_HASH}" --output-dir "./proof_output"
curl --location --request POST 'https://api.pinata.cloud/pinning/pinFileToIPFS' \
--header "Authorization: Bearer ${{ secrets.PINATA_JWT }}" \
--form 'file=@"./proof_output/tally.json"'
yarn hardhat --network "${NETWORK}" clr-finalize --clrfund "${CLRFUND_ADDRESS}"
yarn hardhat --network "${NETWORK}" finalize --clrfund "${CLRFUND_ADDRESS}"
21 changes: 14 additions & 7 deletions .github/workflows/new-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ name: Create new round
on:
workflow_dispatch:
inputs:
clrfund_address:
description: 'Clrfund contract address'
required: true
default: '0x87790498127ff044f43b9230506833ca89113757'
duration:
description: 'Round duration'
required: true
default: 3600

network:
description: 'Network'
required: true
default: 'arbitrum-sepolia'
jsonrpc_url:
description: jsonrpc url to node
required: false

env:
NODE_VERSION: 20.x
SUBGRPAH_URL: "https://api.thegraph.com/subgraphs/name/clrfund/clrfund-testnet"
WALLET_PRIVATE_KEY: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}
NETWORK: arbitrum-sepolia

jobs:
create-new-round:
Expand All @@ -33,8 +41,7 @@ jobs:
- name: Run create new round script
run: |
cd contracts
export CLRFUND=$(curl -X POST -d '{"query":"{clrFunds {id}}"}' $SUBGRPAH_URL)
export CLRFUND_ADDRESS=$(node -e 'console.log(JSON.parse(process.env.CLRFUND).data.clrFunds[0].id)')
yarn hardhat new-round --network "${NETWORK}" \
yarn hardhat new-round \
--network ${{ github.event.inputs.network }} \
--duration ${{ github.event.inputs.duration }} \
--clrfund ${CLRFUND_ADDRESS}
--clrfund ${{ github.event.inputs.clrfund_address }}
5 changes: 3 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
path: monorepo
- name: Download micro zk circuit params
run: |
$GITHUB_WORKSPACE/monorepo/.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
cd monorepo/contracts
../.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
- name: Build Clrfund
run: |
# use https to avoid error: unable to connect to github.com
Expand All @@ -57,7 +58,7 @@ jobs:
yarn start:node &
- name: Run tests
run: |
export CIRCUIT_DIRECTORY="$GITHUB_WORKSPACE/params"
export CIRCUIT_DIRECTORY="$GITHUB_WORKSPACE/monorepo/contracts/params"
export RAPID_SNARK="$GITHUB_WORKSPACE/rapidsnark/package/bin/prover"
cd monorepo
yarn test:e2e
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
path: monorepo
- name: Download circuit params
run: |
$GITHUB_WORKSPACE/monorepo/.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
cd monorepo/contracts
../.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
- name: Build CLR
run: |
cd monorepo
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ In a future version, we plan to address this by routing ETH and token contributi

## Development

### Install Node v18 with nvm
### Install Node v20 with nvm

```sh
nvm install 20
Expand All @@ -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
```
50 changes: 50 additions & 0 deletions contracts/deploy-config-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"localhost": {
"VkRegistry": {
"circuit": "micro",
"paramsDirectory": "./params"
},
"ClrFund": {
"coordinator": "",
"token": "",
"userRegistry": "SimpleUserRegistry",
"recipientRegistry": "SimpleRecipientRegistry"
},
"AnyOldERC20Token": {
"initialSupply": "10000000000000000000000"
},
"OptimisticRecipientRegistry": {
"challengePeriodSeconds": 9007199254740990,
"deposit": "0.001"
},
"BrightIdUserRegistry": {
"deploy": false,
"context": "clrfund-arbitrum-goerli",
"verifier": "0xdbf0b2ee9887fe11934789644096028ed3febe9c"
}
},
"arbitrum-sepolia": {
"VkRegistry": {
"circuit": "micro",
"paramsDirectory": "./params"
},
"ClrFund": {
"coordinator": "",
"token": "0x65bc8dd04808d99cf8aa6749f128d55c2051edde",
"userRegistry": "BrightIdUserRegistry",
"recipientRegistry": "OptimisticRecipientRegistry"
},
"AnyOldERC20Token": {
"initialSupply": "10000000000000000000000"
},
"OptimisticRecipientRegistry": {
"challengePeriodSeconds": 9007199254740990,
"deposit": "0.001"
},
"BrightIdUserRegistry": {
"context": "clrfund-arbitrum-goerli",
"verifier": "0xdbf0b2ee9887fe11934789644096028ed3febe9c",
"sponsor": "0xC7c81634Dac2de4E7f2Ba407B638ff003ce4534C"
}
}
}
54 changes: 28 additions & 26 deletions contracts/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
DEFAULT_SR_QUEUE_OPS,
} from '../utils/constants'
import { getEventArg } from '../utils/contracts'
import {
deployContract,
deployPoseidonLibraries,
deployMaciFactory,
} from '../utils/deployment'
import { deployPoseidonLibraries, deployMaciFactory } from '../utils/testutils'
import { getIpfsHash } from '../utils/ipfs'
import {
bnSqrt,
Expand All @@ -39,6 +35,7 @@ import { existsSync, mkdirSync } from 'fs'
import path from 'path'
import { FundingRound } from '../typechain-types'
import { JSONFile } from '../utils/JSONFile'
import { EContracts } from '../utils/types'

type VoteData = { recipientIndex: number; voiceCredits: bigint }
type ClaimData = { [index: number]: bigint }
Expand Down Expand Up @@ -142,7 +139,6 @@ describe('End-to-end Tests', function () {
params = await MaciParameters.fromConfig(circuit, circuitDirectory)
poseidonLibraries = await deployPoseidonLibraries({
ethers,
artifactsPath: config.paths.artifacts,
signer: deployer,
})
})
Expand All @@ -168,17 +164,14 @@ describe('End-to-end Tests', function () {
maciParameters: params,
})

clrfund = await deployContract({
name: 'ClrFund',
signer: deployer,
ethers,
})
clrfund = await ethers.deployContract(EContracts.ClrFund, deployer)
await clrfund.waitForDeployment()

const roundFactory = await deployContract({
name: 'FundingRoundFactory',
signer: deployer,
ethers,
})
const roundFactory = await ethers.deployContract(
EContracts.FundingRoundFactory,
deployer
)
await roundFactory.waitForDeployment()

const initClrfundTx = await clrfund.init(
maciFactory.target,
Expand All @@ -188,17 +181,23 @@ describe('End-to-end Tests', function () {
const transferTx = await maciFactory.transferOwnership(clrfund.target)
await transferTx.wait()

userRegistry = await ethers.deployContract('SimpleUserRegistry', deployer)
await clrfund.setUserRegistry(userRegistry.target)
const SimpleRecipientRegistry = await ethers.getContractFactory(
'SimpleRecipientRegistry',
userRegistry = await ethers.deployContract(
EContracts.SimpleUserRegistry,
deployer
)
recipientRegistry = await SimpleRecipientRegistry.deploy(clrfund.target)
await clrfund.setUserRegistry(userRegistry.target)
recipientRegistry = await ethers.deployContract(
EContracts.SimpleRecipientRegistry,
[clrfund.target],
{ signer: deployer }
)
await clrfund.setRecipientRegistry(recipientRegistry.target)

// Deploy ERC20 token contract
const Token = await ethers.getContractFactory('AnyOldERC20Token', deployer)
const Token = await ethers.getContractFactory(
EContracts.AnyOldERC20Token,
deployer
)
const tokenInitialSupply = UNIT * BigInt(10000)
token = await Token.deploy(tokenInitialSupply)
await token.transfer(await poolContributor1.getAddress(), UNIT * BigInt(50))
Expand Down Expand Up @@ -262,15 +261,15 @@ describe('End-to-end Tests', function () {

const fundingRoundAddress = await clrfund.getCurrentRound()
fundingRound = await ethers.getContractAt(
'FundingRound',
EContracts.FundingRound,
fundingRoundAddress
)
const maciAddress = await fundingRound.maci()
maci = await ethers.getContractAt('MACI', maciAddress)
maci = await ethers.getContractAt(EContracts.MACI, maciAddress)

pollId = await fundingRound.pollId()
const pollAddress = await fundingRound.poll()
pollContract = await ethers.getContractAt('Poll', pollAddress)
pollContract = await ethers.getContractAt(EContracts.Poll, pollAddress)

await mine()
})
Expand Down Expand Up @@ -331,7 +330,10 @@ describe('End-to-end Tests', function () {
messageProcessorAddress: string
}> {
const tallyAddress = await fundingRound.tally()
const tallyContact = await ethers.getContractAt('Tally', tallyAddress)
const tallyContact = await ethers.getContractAt(
EContracts.Tally,
tallyAddress
)
const messageProcessorAddress = await tallyContact.messageProcessor()

return { tallyAddress, messageProcessorAddress }
Expand Down
Loading
Loading