Skip to content

Commit

Permalink
Merge pull request #723 from clrfund/feat/maci-v1-bundle-size
Browse files Browse the repository at this point in the history
Merge fixes from latest MACI
  • Loading branch information
yuetloo authored Jan 26, 2024
2 parents 38e8919 + 312ce52 commit 568a8ed
Show file tree
Hide file tree
Showing 173 changed files with 6,533 additions and 6,002 deletions.
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

0 comments on commit 568a8ed

Please sign in to comment.