Skip to content

Commit

Permalink
temp 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wanseob committed Mar 30, 2022
1 parent ebc2375 commit b9f5c74
Show file tree
Hide file tree
Showing 348 changed files with 69,939 additions and 10,012 deletions.
2 changes: 1 addition & 1 deletion compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
contracts:
image: zkoprunet/contracts:2.0.0-beta.0
build:
context: ../packages/contracts/
context: ../
dockerfile: ../../dockerfiles/Contract.dockerfile
contracts-for-integration-test:
image: zkoprunet/contracts-integration-test:2.0.0-beta.0
Expand Down
9 changes: 4 additions & 5 deletions dockerfiles/Contract.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ RUN apk add --no-cache --virtual .gyp \
python3 \
make \
g++ \
&& yarn global add truffle ganache-cli \
&& yarn global add ganache-cli \
&& yarn install \
&& apk del .gyp

COPY ./contracts /proj/contracts
COPY ./utils /proj/utils
COPY ./migrations /proj/migrations
COPY ./truffle-config.js /proj/truffle-config.js
RUN truffle compile
COPY ./hardhat.config.ts /proj/hardhat.config.ts
RUN yarn compile
EXPOSE 5000
COPY ./keys /proj/keys
RUN ganache-cli --db=/data -i 20200406 -p 5000 --gasLimit 12000000 --deterministic --host 0.0.0.0 & sleep 5 && truffle migrate --network testnet
RUN ganache-cli --db=/data -i 20200406 -p 5000 --gasLimit 12000000 --deterministic --host 0.0.0.0 & sleep 5 && yarn hardhat run scripts/deploy.ts --network testnet
CMD ganache-cli --db=/data -b 5 -i 20200406 -p 5000 --gasLimit 12000000 --deterministic --host 0.0.0.0 --gasPrice 2000000000
4 changes: 2 additions & 2 deletions dockerfiles/Playground.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk add --no-cache --virtual .gyp \
make \
g++ \
chromium \
&& yarn global add truffle ganache-cli \
&& yarn global add hardhat ganache-cli \
&& yarn \
&& yarn install \
&& npx lerna run build --scope=@zkopru/cli \
Expand All @@ -22,7 +22,7 @@ RUN apk add --no-cache --virtual .gyp \
WORKDIR /proj/zkopru/packages/cli

RUN ganache-cli --db=/proj/data -i 20200406 -p 5000 --gasLimit 12000000 --deterministic --host 0.0.0.0 & \
sleep 5 && cd /proj/zkopru/packages/contracts && truffle migrate --network testnet
sleep 5 && cd /proj/zkopru/packages/contracts && hardhat run --network testnet

COPY ./packages/circuits/keys /proj/zkopru/packages/cli/keys

Expand Down
1 change: 1 addition & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest',
},
setupFilesAfterEnv: ['jest-expect-message'],
testRegex: '(/tests/.*.(test|spec)).(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverage: true,
Expand Down
89 changes: 53 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
{
"name": "zkopru",
"nams": "zkopru",
"version": "2.0.0-beta.8",
"license": "GPL-3.0-or-later",
"private": true,
"license": "GPL-3.0-or-later",
"workspaces": [
"packages/*"
],
"scripts": {
"bootstrap": "yarn && yarn images pull && yarn build && lerna run gendata",
"postinstall": "lerna bootstrap && yarn clean && shx rm -rf packages/*/node_modules",
"images": "docker-compose -f compose/docker-compose.yml",
"images:pull": "docker-compose -f compose/docker-compose.yml pull",
"images:build": "docker-compose -f compose/docker-compose.yml build",
"images:push": "docker-compose -f compose/docker-compose.yml push",
"predevelop": "yarn build:ts && docker-compose -f compose/docker-compose.dev.yml build",
"develop": "(sleep 10; open-cli http://localhost:4321) & (sleep 10; open-cli http://localhost:1234) & docker-compose -f compose/docker-compose.dev.yml up --force-recreate -V",
"develop:instant": "yarn build:ts && docker-compose -f compose/docker-compose.instant-block.yml up --build --force-recreate -V",
"build": "lerna run build:contract && yarn build:ts",
"build": "yarn build:ts",
"build:fresh": "yarn clean && shx rm -rf packages/*/node_modules && yarn build",
"build:keys": "lerna run build-keys --scope=@zkopru/circuits",
"build:ts": "lerna run --parallel build && yarn link-modules",
"build:ts:serial": "lerna run build && yarn link-modules",
"circuit:setup": "lerna run setup:build",
"build:contract": "lerna run --parallel build:contract",
"build:keys": "lerna run build-keys --scope=@zkopru/circuits",
"build:fresh": "yarn clean && shx rm -rf packages/*/node_modules && yarn build",
"clean": "lerna run --parallel clean && shx rm -rf packages/*/node_modules && shx rm -rf .build-cache *.log coverage junit.xml",
"clean:db": "shx rm -rf **/*/.mockup",
"test": "yarn test:parallel",
"test:parallel": "yarn test:serial --parallel",
"test:serial": "lerna run test --stream",
"test:trace": "LOG_LEVEL=trace PRINT_LOG=true yarn test:serial",
"posttest:all": "yarn clean:db",
"pretest:integrate": "docker-compose up -d --build",
"test:integrate": "lerna run test:integrate --parallel || true",
"posttest:integrate": "docker-compose down",
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
"precommit": "lint-staged && lerna run --concurrency 1 --stream precommit --since HEAD",
"commit": "git cz",
"coverage": "jest --coverage",
"coverage:unit": "yarn test:unit --coverage",
"coverage:integration": "yarn test:integration --coverage",
"coverage:show": "live-server coverage",
"coverage:unit": "yarn test:unit --coverage",
"predevelop": "yarn build:ts && docker-compose -f compose/docker-compose.dev.yml build",
"develop": "(sleep 10; open-cli http://localhost:4321) & (sleep 10; open-cli http://localhost:1234) & docker-compose -f compose/docker-compose.dev.yml up --force-recreate -V",
"develop:instant": "yarn build:ts && docker-compose -f compose/docker-compose.instant-block.yml up --build --force-recreate -V",
"format": "yarn lint --fix",
"format:md": "yarn lint:md --fix",
"husky-skip": "cross-env HUSKY_SKIP_HOOKS=1",
"images": "docker-compose -f compose/docker-compose.yml",
"images:build": "docker-compose -f compose/docker-compose.yml build",
"images:pull": "docker-compose -f compose/docker-compose.yml pull",
"images:push": "docker-compose -f compose/docker-compose.yml push",
"postinstall": "#lerna bootstrap && yarn clean && shx rm -rf packages/*/node_modules",
"link-modules": "lerna run --parallel link-modules",
"lint": "eslint --ext js --ext ts --ext md",
"lint:ci": "yarn lint . --format junit",
"lint:md": "markdownlint --ignore node_modules --ignore .git",
"format": "yarn lint --fix",
"format:md": "yarn lint:md --fix",
"husky-skip": "cross-env HUSKY_SKIP_HOOKS=1",
"precommit": "lint-staged && lerna run --concurrency 1 --stream precommit --since HEAD",
"commit": "git cz"
"posttest:all": "yarn clean:db",
"test": "yarn test:parallel",
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
"pretest:integrate": "docker-compose up -d --build",
"test:integrate": "lerna run test:integrate --parallel || true",
"posttest:integrate": "docker-compose down",
"test:parallel": "yarn test:serial --parallel",
"test:serial": "lerna run test --stream",
"test:trace": "LOG_LEVEL=trace PRINT_LOG=true yarn test:serial"
},
"husky": {
"hooks": {
Expand All @@ -72,18 +71,25 @@
"devDependencies": {
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@truffle/artifactor": "^4.0.30",
"@typechain/web3-v1": "^2.2.0",
"@nomiclabs/hardhat-ethers": "^2.0.3",
"@nomiclabs/hardhat-etherscan": "^2.1.8",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@truffle/artifactor": "^4.0.54",
"@typechain/ethers-v5": "^7.2.0",
"@typechain/hardhat": "^2.3.1",
"@types/async-lock": "^1.1.1",
"@types/blessed": "^0.1.17",
"@types/bs58": "^4.0.1",
"@types/chai": "^4.3.0",
"@types/express": "^4.17.4",
"@types/figlet": "^1.2.0",
"@types/fs-extra": "^8.1.0",
"@types/hdkey": "^0.7.1",
"@types/jest": "^24.0.23",
"@types/js-yaml": "^3.12.5",
"@types/keccak": "^3.0.1",
"@types/mocha": "^9.0.0",
"@types/node": "^12.20.37",
"@types/node-fetch": "^2.5.7",
"@types/node-schedule": "^1.3.0",
"@types/pino": "^6.0.0",
Expand All @@ -98,6 +104,7 @@
"@typescript-eslint/parser": "^2.34.0",
"bignumber.js": "^9.0.0",
"bn.js": "^5.2.0",
"chai": "^4.3.4",
"circom": "0.5.42",
"circomlib": "0.5.1",
"commitizen": "^4.0.3",
Expand All @@ -109,16 +116,22 @@
"eslint": "^6.4.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-standard": "^16.0.3",
"eslint-import-resolver-lerna": "^1.1.0",
"eslint-import-resolver-typescript": "^1.1.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.9.0",
"eslint-plugin-markdown": "^1.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-truffle": "^0.3.1",
"eslint-plugin-promise": "^5.2.0",
"eth-gas-reporter": "^0.2.16",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.5.2",
"ffjavascript": "0.2.22",
"fs-extra": "^9.0.0",
"hardhat": "^2.8.0",
"hardhat-gas-reporter": "^1.0.6",
"husky": "^3.1.0",
"jest": "^24.7.1",
"jest-junit": "^10.0.0",
Expand All @@ -131,24 +144,28 @@
"node-docker-api": "^1.1.22",
"open-cli": "^6.0.1",
"prettier": "^1.16.4",
"prettier-plugin-solidity": "^1.0.0-beta.19",
"puppeteer": "^5.0.0",
"serve": "^11.2.0",
"shx": "^0.3.2",
"smt-rollup": "^0.6.3",
"snarkjs": "0.3.33",
"solc": "^0.6.4",
"solc5": "npm:solc@0.5.15",
"solhint": "^3.3.6",
"solidity-coverage": "^0.7.17",
"solium": "^1.2.5",
"tar": "^6.0.2",
"tar-fs": "^2.1.0",
"truffle": "5.4.10",
"truffle-artifactor": "^4.0.30",
"ts-jest": "^24.2.0",
"ts-node": "^10.4.0",
"ts-node-dev": "^1.0.0-pre.44",
"tsconfig-paths": "^3.9.0",
"typechain": "^4.0.3",
"typescript": "3.8.3",
"uuid": "^8.1.0"
"typechain": "^5.2.0",
"typescript": "^4.6.2",
"uuid": "^8.1.0",
"web3-utils": "1.2.11"
},
"publishConfig": {
"access": "public"
Expand Down
15 changes: 10 additions & 5 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ZkViewer } from './viewer'
import { Wallet } from 'ethers'
import { ExternallyOwnedAccount } from '@ethersproject/abstract-signer'
import { BytesLike, hexlify } from 'ethers/lib/utils'
import { Provider } from '@ethersproject/providers'

export class ZkAccount extends ZkViewer {
private privateKey: string // ECDSA private key
Expand All @@ -23,10 +24,10 @@ export class ZkAccount extends ZkViewer {

ethAccount: Wallet

constructor(_privateKey: BytesLike) {
constructor(_privateKey: BytesLike, _provider?: Provider) {
const privateKey = hexlify(_privateKey)

const ethAccount = new Wallet(_privateKey)
const ethAccount = new Wallet(_privateKey, _provider)

const A = Point.fromPrivKey(privateKey)
// https://github.com/zkopru-network/zkopru/issues/34#issuecomment-666988505
Expand All @@ -44,8 +45,11 @@ export class ZkAccount extends ZkViewer {
this.ethAccount = ethAccount
}

static fromEthAccount(account: ExternallyOwnedAccount): ZkAccount {
return new ZkAccount(account.privateKey)
static fromEthAccount(
account: ExternallyOwnedAccount,
provider?: Provider,
): ZkAccount {
return new ZkAccount(account.privateKey, provider)
}

toKeystoreSqlObj(password: string): Keystore {
Expand All @@ -65,9 +69,10 @@ export class ZkAccount extends ZkViewer {
static fromEncryptedKeystoreV3Json(
obj: EncryptedKeystoreV3Json,
password: string,
provider?: Provider,
): ZkAccount {
const web3 = new Web3()
const account = web3.eth.accounts.decrypt(obj, password)
return new ZkAccount(account.privateKey)
return new ZkAccount(account.privateKey, provider)
}
}
7 changes: 4 additions & 3 deletions packages/account/src/hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class HDWallet {
}
}

async retrieveAccounts(): Promise<ZkAccount[]> {
async retrieveAccounts(provider?: Provider): Promise<ZkAccount[]> {
if (!this.seed) throw Error('Not initialized')
const keys: Keystore[] = await this.db.findMany('Keystore', { where: {} })
const accounts: ZkAccount[] = []
Expand All @@ -102,7 +102,7 @@ export class HDWallet {
keys[i].encrypted,
this.password,
)
accounts.push(ZkAccount.fromEthAccount(keystoreAccount))
accounts.push(ZkAccount.fromEthAccount(keystoreAccount, provider))
}
return accounts
}
Expand All @@ -119,8 +119,9 @@ export class HDWallet {
}
const ethAccount = new Wallet(
typeof privateKey === 'string' ? privateKey : privateKey.toString('hex'),
this.provider,
)
const account = ZkAccount.fromEthAccount(ethAccount)
const account = ZkAccount.fromEthAccount(ethAccount, this.provider)
await this.db.create('Keystore', account.toKeystoreSqlObj(this.password))
return account
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babyjubjub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build": "tsc --build tsconfig.build.json",
"clean": "tsc --build tsconfig.build.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache",
"link-modules": "link-module-alias",
"test": "jest",
"test": "jest --env=jsdom",
"test:trace": "LOG_LEVEL=trace PRINT_LOG=true jest",
"test:unit": "jest test/unit",
"test:integration": "jest test/unit",
Expand Down
15 changes: 6 additions & 9 deletions packages/babyjubjub/src/fp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ export class Fp implements BigNumber {
}

static from(number: BigNumberish): Fp {
let n: BigNumber = BigNumber.from(number)
let val: BigNumber
if (n.isNegative()) {
val = n.mod(Fp.ORDER).add(Fp.ORDER)
} else {
val = n.mod(Fp.ORDER)
}
const n: BigNumber = BigNumber.from(number)
const val = n.mod(Fp.ORDER)
return new Fp(_constructorGuard, val.toHexString())
}

Expand Down Expand Up @@ -150,7 +145,9 @@ export class Fp implements BigNumber {
}

neg(): Fp {
return Fp.from(this._hex.startsWith('-') ? this._hex.slice(1) : `-${this._hex}`)
return Fp.from(
this._hex.startsWith('-') ? this._hex.slice(1) : `-${this._hex}`,
)
}

eq(other: BigNumberish): boolean {
Expand Down Expand Up @@ -189,7 +186,7 @@ export class Fp implements BigNumber {
}

toString(): string {
return BigNumber.from(this._hex).toString()
return BigNumber.from(this._hex).toString()
}

toRed(): RedBN {
Expand Down
12 changes: 4 additions & 8 deletions packages/babyjubjub/tests/unit/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,7 @@ describe('finite field', () => {
expect(constant.eq(b)).toBe(true)
})
it('should return same hex', () => {
console.log('should return same hex test')
const f = Fp.from('0xabcd1234abcd1234')
console.log('vall 1')
console.log(f.toHexString())
console.log('vall 2')
console.log(f.toHexString(8))
console.log('vall 3')
console.log(f.toHexString(8))
console.log(f.toHexString(8))
expect(f.toHexString(8)).toStrictEqual('0xabcd1234abcd1234')
})
it('should return cyclic hex for a number beyond the field range', () => {
Expand Down Expand Up @@ -107,4 +99,8 @@ describe('cyclic group', () => {
const b = Fp.from(20)
expect(a.sub(b).gt(a)).toBe(true)
})
it('a + ORDER = a', () => {
const a = Fp.from(18)
expect(a.add(Fp.ORDER).eq(a)).toBe(true)
})
})
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dev:wallet": "ts-node src/apps/wallet/cli.ts --config wallet.json"
},
"dependencies": {
"@ethersproject/providers": "^5.5.3",
"@zkopru/account": "file:../account",
"@zkopru/babyjubjub": "file:../babyjubjub",
"@zkopru/contracts": "file:../contracts",
Expand All @@ -51,13 +52,14 @@
"blessed": "^0.1.81",
"bn.js": "^5.2.0",
"chalk": "^4.0.0",
"ethers": "^5.6.0",
"figlet": "^1.4.0",
"fs-extra": "^9.0.0",
"node-ansiparser": "^2.2.0",
"node-ansiterminal": "^0.2.1-beta",
"node-fetch": "^2.6.0",
"pino-pretty": "^4.5.0",
"soltypes": "^1.3.5",
"soltypes": "^2.0.0",
"tar": "^6.0.2",
"web3": "1.2.11",
"web3-core": "1.2.11",
Expand Down
Loading

0 comments on commit b9f5c74

Please sign in to comment.