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

Merge fixes from latest MACI #723

Merged
merged 80 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
0285acb
test with maci version 0.0.0-ci.45668db
yuetloo Jan 9, 2024
06199c0
upgrade ethers v5 to v6 temporary checkin
yuetloo Jan 14, 2024
197a624
ignore formatting on typechain_types
yuetloo Jan 14, 2024
c94710b
remove BigNumber
yuetloo Jan 14, 2024
bd3ff7a
remove unused code
yuetloo Jan 16, 2024
8a3a620
use maci v0.0.0-ci.2e62774
yuetloo Jan 16, 2024
96831f8
code refactoring and allow coordinator to reset tally result
yuetloo Jan 16, 2024
8f451fa
fix unit test cases
yuetloo Jan 17, 2024
a3b865a
use node v18
yuetloo Jan 17, 2024
923f925
update e2e to use latest version of MACI v1
yuetloo Jan 17, 2024
92e0d4d
fix e2e test bigint and contract address error
yuetloo Jan 17, 2024
1edf7c8
add sepolia to hardhat config
yuetloo Jan 18, 2024
3000493
update contract address to target for ether v6
yuetloo Jan 18, 2024
6c6eafb
fix formatting
yuetloo Jan 18, 2024
77f0b44
update readme
yuetloo Jan 18, 2024
e4b7382
remove obsolete script
yuetloo Jan 18, 2024
2af42d0
update with ethers v6 syntax
yuetloo Jan 18, 2024
8224941
use ethers v6
yuetloo Jan 18, 2024
64e0067
use ethers v6 and hardhat network helper
yuetloo Jan 18, 2024
d45ee7a
fix contract address
yuetloo Jan 18, 2024
02a7206
fix contract address
yuetloo Jan 18, 2024
5f4346a
fix contract address
yuetloo Jan 18, 2024
a9cbe02
fix signer address
yuetloo Jan 18, 2024
7b56ada
MACI interface change
yuetloo Jan 18, 2024
895f058
code refacting
yuetloo Jan 18, 2024
08b8eb8
fix custom error
yuetloo Jan 18, 2024
332f1d0
move the regiter function to a registry contract later
yuetloo Jan 18, 2024
9dde92f
use node v18
yuetloo Jan 18, 2024
fbeab5f
ensure properly init before deploying new round
yuetloo Jan 18, 2024
30c528b
fix missing rapidsnark path when running in unix environment
yuetloo Jan 18, 2024
5b409a4
add missing constant
yuetloo Jan 18, 2024
22c088f
missing rapidSnark
yuetloo Jan 18, 2024
9c80834
remove obsolete batchSizes as it's calculated by MACI contract
yuetloo Jan 18, 2024
a2f3c98
remove obsolete batchSizes as it's calculated by MACI contract
yuetloo Jan 18, 2024
b4238b0
fix typescript error
yuetloo Jan 18, 2024
4306054
remove messageBatchSize as MACI calculate that value based on treeDepth
yuetloo Jan 19, 2024
8ed7339
ethers v6 interface change
yuetloo Jan 19, 2024
1f261e2
refactor getEventArgs
yuetloo Jan 19, 2024
68d5036
refactor maci parameters and getEventArg
yuetloo Jan 19, 2024
40d001d
fix script error
yuetloo Jan 19, 2024
f1eae60
use MACI v0.0.0-ci.a5a9137
yuetloo Jan 19, 2024
5ebecd6
fix toNumber error
yuetloo Jan 19, 2024
e40f6ec
build clrfund common package
yuetloo Jan 19, 2024
6e4eab6
fix bigint and number mismatch error
yuetloo Jan 19, 2024
8f6bac1
refactor bnSqrt and added unit tests
yuetloo Jan 20, 2024
783a182
make public key id in subgraph uniquebetween different rounds
yuetloo Jan 20, 2024
66626fc
fix formatting
yuetloo Jan 20, 2024
e9cc400
use ethers v6
yuetloo Jan 21, 2024
83db900
fix address validation error
yuetloo Jan 22, 2024
2e7a369
add arbitrum sepolia
yuetloo Jan 22, 2024
5ff4ba6
add arbitrum sepolia
yuetloo Jan 22, 2024
d362b93
log error when loading failed
yuetloo Jan 22, 2024
8e59aa8
use bigint syntax
yuetloo Jan 22, 2024
87d466f
fixes for ethers v6 migration
yuetloo Jan 22, 2024
ab204e4
update default circuit params directory
yuetloo Jan 22, 2024
9edabf5
add local-state.json
yuetloo Jan 22, 2024
8910e95
add local-state.json
yuetloo Jan 22, 2024
b5a5f6d
fix bigint issues and maci v1 interface change
yuetloo Jan 22, 2024
915d219
fix parser error caused by rlpEncode interface change
yuetloo Jan 22, 2024
3d64ebd
add graph node docker compose file
yuetloo Jan 22, 2024
a91285d
save test data to local state file
yuetloo Jan 22, 2024
698680c
fix parameter name change
yuetloo Jan 23, 2024
6d70868
remove tally and message processor factories from funding round and u…
yuetloo Jan 23, 2024
c711ce4
ignore file not found error when updating the file
yuetloo Jan 23, 2024
f795bea
remove init check as onlyOwner ensures initialized
yuetloo Jan 23, 2024
7452f56
remove obsolete parameters
yuetloo Jan 23, 2024
ffcafdf
deploy standalone clrfund without deployer
yuetloo Jan 23, 2024
db6de00
deploy standalone clrfund without deployer
yuetloo Jan 23, 2024
9b8dc2d
subgraph handling of recipient registry change events
yuetloo Jan 23, 2024
2a2d846
use MACI 0.0.0-ci.45d1156
yuetloo Jan 23, 2024
f4e1e01
use MACI 0.0.0-ci.45d1156
yuetloo Jan 23, 2024
4409894
update doc with new command syntax
yuetloo Jan 23, 2024
4556f1a
allow re-running tally script on failure
yuetloo Jan 23, 2024
17621c1
remove zkutil
yuetloo Jan 24, 2024
4f628dc
fix tally.mp() not a function error
yuetloo Jan 24, 2024
13c748d
fix tally.mp() not a function error
yuetloo Jan 24, 2024
b70134e
remove obsolete steps
yuetloo Jan 24, 2024
6dd80f6
add missing await and check receipt status
yuetloo Jan 25, 2024
a64cd06
add standalone verify poll script
yuetloo Jan 25, 2024
312ce52
add set funding round factory task
yuetloo Jan 25, 2024
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: 1 addition & 1 deletion .github/workflows/cancel-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Cancel current round
on: workflow_dispatch

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
SUBGRPAH_URL: "https://api.thegraph.com/subgraphs/name/clrfund/clrfund-arbitrum-goerli"
WALLET_PRIVATE_KEY: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- major

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
VITE_CLRFUND_FACTORY_ADDRESS: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
VITE_ETHEREUM_API_CHAINID: 1
VITE_ETHEREUM_API_URL: "dummy"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/finalize-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ on:
default: 'yuetloo/clrfund-dev'

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
NETWORK: "arbitrum-goerli"
COORDINATOR_ETH_PK: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}
COORDINATOR_PK: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_MACI_PRIVATE_KEY }}
JSONRPC_HTTP_URL: ${{ secrets.JSONRPC_HTTP_URL }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY_ARBITRUM }}
ETHERSCAN_URL: "https://api-goerli.arbiscan.io"
CIRCUIT_TYPE: micro
ZKEYS_DOWNLOAD_SCRIPT: "download-6-8-2-3.sh"

jobs:
finalize:
Expand Down Expand Up @@ -47,7 +49,7 @@ jobs:
- name: Download batch 64 params
run: |
ls -la $GITHUB_WORKSPACE
$GITHUB_WORKSPACE/.github/scripts/download-batch64-params.sh
$GITHUB_WORKSPACE/monorepo/.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
- name: Build
run: |
# use https to avoid error: unable to connect to github.com
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/new-round.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Create new round
on: workflow_dispatch

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
SUBGRPAH_URL: "https://api.thegraph.com/subgraphs/name/clrfund/clrfund-arbitrum-goerli"
WALLET_PRIVATE_KEY: ${{ secrets.ARBITRUM_GOERLI_COORDINATOR_WALLET_PRIVATE_KEY }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'contracts/**'

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x

jobs:
test-contracts:
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Install
run: |
git config --global url."https://".insteadOf git://
yarn
yarn && yarn build
- name: Run tests
run: yarn test:contracts

22 changes: 1 addition & 21 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'develop'

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
CIRCUIT_TYPE: micro
ZKEYS_DOWNLOAD_SCRIPT: "download-6-8-2-3.sh"

Expand All @@ -23,20 +23,6 @@ jobs:
run: |
sudo apt update
sudo apt-get install cmake build-essential libgmp-dev libsodium-dev nlohmann-json3-dev nasm g++ curl
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Checkout circom
uses: actions/checkout@v3
with:
repository: iden3/circom
path: circom
- name: Build circom
run: |
cd circom
cargo build --release
cargo install --path circom
- name: Checkout rapidsnark source code
uses: actions/checkout@v3
with:
Expand All @@ -52,12 +38,6 @@ jobs:
mkdir build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
- name: Find rapidsnark
run: |
cd rapidsnark
pwd
echo "$GITHUB_WORKSPACE"
find . -name "prover"
- name: Checkout Clrfund
uses: actions/checkout@v3
with:
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
- '.github/workflows/test-scripts.yml'

env:
NODE_VERSION: 16.x
NODE_VERSION: 18.x
ZKEYS_DOWNLOAD_SCRIPT: "download-6-8-2-3.sh"

jobs:
script-tests:
Expand All @@ -22,13 +23,6 @@ jobs:
run: |
sudo apt update
sudo apt-get install build-essential libgmp-dev libsodium-dev nlohmann-json3-dev nasm g++ curl
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Install zkutil
run: |
cargo install zkutil --version 0.3.2
- name: Checkout rapidsnark source code
uses: actions/checkout@v3
with:
Expand All @@ -44,19 +38,13 @@ jobs:
mkdir build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
- name: Find rapidsnark
run: |
cd rapidsnark
pwd
echo "$GITHUB_WORKSPACE"
find . -name "prover"
- name: Checkout source code
uses: actions/checkout@v3
with:
path: monorepo
- name: Download batch 64 params
run: |
$GITHUB_WORKSPACE/monorepo/.github/scripts/download-6-8-2-3.sh
$GITHUB_WORKSPACE/monorepo/.github/scripts/${ZKEYS_DOWNLOAD_SCRIPT}
- name: Build CLR
run: |
cd monorepo
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ contracts/state.json
contracts/tally.json
contracts/proofs.json
contracts/proof_output
contracts/typechain-types
contracts/local-state.json

# local env files
.env
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ In a future version, we plan to address this by routing ETH and token contributi

## Development

### Install Node v16 with nvm
### Install Node v18 with nvm

```sh
nvm install 16
nvm use 16
nvm install 18
nvm use 18
```

### Install the dependencies
### Install the dependencies and build

```sh
yarn
yarn && yarn build

# Along with the dependencies, git hooks are also installed. At the end of the installation, you will see the following line after a successful setup.
husky - Git hooks installed
Expand Down Expand Up @@ -102,9 +102,8 @@ In a 2nd terminal you will need to run your graph node (more on this
[here](docs/subgraph.md))

```sh
# go to the thegraph repo directory and init the node
cd graph-node/docker
docker-compose up
cd subgraph/graph-node
docker compose up -d
```

And finally, in a 3rd terminal
Expand Down
5 changes: 5 additions & 0 deletions common/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts"],
"spec": "src/**/*.spec.ts",
"require": "ts-node/register"
}
17 changes: 12 additions & 5 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
"name": "@clrfund/common",
"version": "0.0.1",
"description": "Common utility functions used by clrfund scripts and app",
"main": "src/index",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/esm/index.d.ts",
"scripts": {
"build": "tsc",
"build": "yarn build:esm && yarn build:cjs && yarn test",
"build:esm": "tsc -p tsconfig.json --outDir build/esm --module ES6",
"build:cjs": "tsc -p tsconfig.json --outDir build/cjs",
"test": "mocha",
"lint": "eslint 'src/**/*.ts'",
"clean": "rm -rf build"
},
"license": "GPL-3.0",
"devDependencies": {
"eslint": "^8.31.0",
"mocha": "^10.2.0",
"ts-node": "^10.9.2",
"typescript": "^4.9.3"
},
"dependencies": {
"@openzeppelin/merkle-tree": "^1.0.5",
"ethers": "^5.7.2",
"@clrfund/maci-crypto": "^1.1.7",
"@clrfund/maci-domainobjs": "^1.1.7"
"ethers": "^6.9.2",
"maci-crypto": "0.0.0-ci.45d1156",
"maci-domainobjs": "0.0.0-ci.45d1156"
},
"repository": {
"type": "git",
Expand Down
47 changes: 47 additions & 0 deletions common/src/__tests__/math.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from 'chai'
import { bnSqrt } from '../index'
import { toBigInt } from 'ethers'

const UNIT = BigInt(10) ** BigInt(18)
const cases = [
[0n, 0n],
[1n, 1n],
[4n, 2n],
[100n, 10n],
]

/**
* Get a random number in range
* @param min minimum number
* @param max maximum number
* @returns random number
*/
function getRandom(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min)
}

describe('bnSqrt', function () {
it('should throw if value less than 0', function () {
expect(bnSqrt.bind(bnSqrt, -1n)).to.throw('Complex numbers not support')
})

for (const test of cases) {
const [val, expected] = test
it(`bnSqrt(${val}) === ${expected}`, function () {
expect(bnSqrt(val)).to.eq(expected)
})
}

it('Sqrt(8) throws as it took too long to calculate', function () {
expect(bnSqrt.bind(bnSqrt, 8n)).to.throw('Sqrt took too long to calculate')
})

it('testing random bigints', function () {
for (let i = 0; i < 100; i++) {
const rand = toBigInt(getRandom(5, 200)) * UNIT
const sqrtVal = bnSqrt(rand)
const val = sqrtVal * sqrtVal
expect(bnSqrt(val)).to.eq(sqrtVal)
}
})
})
11 changes: 7 additions & 4 deletions common/src/block.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { providers, utils } from 'ethers'
import { type JsonRpcProvider, toQuantity } from 'ethers'

export interface Block {
blockNumber: number
hash: string
stateRoot: string
}

/*
/**
* get the block stateRoot using eth_getBlockByHash
* @param blockNumber The block number
* @param provider the JSON rpc provider
* @returns the block information with block number, block hash and state root
*/
export async function getBlock(
blockNumber: number,
provider: providers.JsonRpcProvider
provider: JsonRpcProvider
): Promise<Block> {
const blockNumberHex = utils.hexValue(blockNumber)
const blockNumberHex = toQuantity(blockNumber)
const blockParams = [blockNumberHex, false]
const rawBlock = await provider.send('eth_getBlockByNumber', blockParams)
return { blockNumber, hash: rawBlock.hash, stateRoot: rawBlock.stateRoot }
Expand Down
36 changes: 36 additions & 0 deletions common/src/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Contract, TransactionResponse } from 'ethers'

/**
* Get event log argument value
* @param transactionReceipt transaction
* @param contract Contract handle
* @param eventName event name
* @param argumentName argument name
* @returns event argument value
*/
export async function getEventArg(
transaction: TransactionResponse,
contract: Contract,
eventName: string,
argumentName: string
): Promise<any> {
const transactionReceipt = await transaction.wait()
const contractAddress = await contract.getAddress()
// eslint-disable-next-line
for (const log of transactionReceipt?.logs || []) {
if (log.address !== contractAddress) {
continue
}
const event = contract.interface.parseLog({
data: log.data,
topics: [...log.topics],
})
// eslint-disable-next-line
if (event && event.name === eventName) {
return event.args[argumentName]
}
}
throw new Error(
`Event ${eventName} from contract ${contractAddress} not found in transaction ${transaction.hash}`
)
}
2 changes: 2 additions & 0 deletions common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export * from './ipfs'
export * from './keypair'
export * from './tally'
export * from './utils'
export * from './event'
export * from './math'
6 changes: 3 additions & 3 deletions common/src/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { utils } from 'ethers'
import { FetchRequest } from 'ethers'

const IPFS_BASE_URL = 'https://ipfs.io'

Expand All @@ -13,6 +13,6 @@ export async function getIpfsContent(
gatewayUrl = IPFS_BASE_URL
): Promise<any> {
const url = `${gatewayUrl}/ipfs/${hash}`
const result = utils.fetchJson(url)
return result
const req = new FetchRequest(url)
return req.send()
}
Loading
Loading