Skip to content

Commit

Permalink
Fix zk init
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbochok committed Dec 10, 2020
1 parent a459c3e commit 0617794
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 253 deletions.
11 changes: 0 additions & 11 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@ if ! cargo fmt -- --check; then
echo "Please format the code via 'cargo fmt', cannot commit unformatted code"
exit 1
fi

VERFIER_CONTRACT_FILE="contracts/contracts/Verifier.sol"

# Check if diff for contract contains setting the `DUMMY_VERIFIER` to the true.
if git diff --cached $VERFIER_CONTRACT_FILE | grep -lq 'constant DUMMY_VERIFIER = true'; then
echo -e "${RED}Commit error!${NC}"
echo "It seems that line 'constant DUMMY_VERIFIER = true' in 'Verifier.sol' is staged to be committed"
echo "Cannot commit the code with enabled DUMMY_VERIFIER"
echo "Please disable the DUMMY_VERIFIER and try to commit changes again"
exit 1
fi
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
yarn lint:sol
# So database will be created for compilation.
zk db setup
zk dummy-prover ensure-disabled
cargo fmt --all -- --check
# For some reason, `cargo clippy` currently doesn't work in sqlx offline mod. So, we're checking it in online mode.
zk f cargo clippy --tests --benches -- -D warnings
Expand All @@ -53,7 +52,7 @@ jobs:
# Unpack keys to build dev contracts
zk run verify-keys unpack
# EIP1271 contract is used in Rust & JS unit tests.
zk contract build-dev
zk contract build
zk run deploy-eip1271
- name: integration-tests
Expand Down
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"core/bin/key_generator",
"core/bin/server",
"core/bin/prover",
"core/bin/gen_token_add_contract",
"core/bin/parse_pub_data",

# Server micro-services
Expand Down
2 changes: 0 additions & 2 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/build
# /contracts/keys
/contracts/KeysWithPlonkVerifier.sol
/contracts/TokenInit.sol
/artifacts
/cache
/contracts/dev-contracts/generated
/typechain
2 changes: 0 additions & 2 deletions contracts/config/prod.json

This file was deleted.

10 changes: 10 additions & 0 deletions contracts/contracts/TokenInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

pragma solidity ^0.7.0;

contract TokenDeployInit {
function getTokens() internal pure returns (address[] memory) {
address[] memory tokens = new address[](0);
return tokens;
}
}
6 changes: 3 additions & 3 deletions contracts/contracts/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import "./KeysWithPlonkVerifier.sol";

// Hardcoded constants to avoid accessing store
contract Verifier is KeysWithPlonkVerifier {
bool constant DUMMY_VERIFIER = $(DUMMY_VERIFIER);

function initialize(bytes calldata) external {}

/// @notice Verifier contract upgrade. Can be external because Proxy contract intercepts illegal calls of this function.
Expand All @@ -23,7 +21,8 @@ contract Verifier is KeysWithPlonkVerifier {
uint256[16] memory _subproofs_limbs,
bool blockProof
) external view returns (bool) {
if (DUMMY_VERIFIER && blockProof) {
// #if DUMMY_VERIFIER
if (blockProof) {
uint256 oldGasValue = gasleft();
uint256 tmp;
while (gasleft() + 500000 > oldGasValue) {
Expand All @@ -36,6 +35,7 @@ contract Verifier is KeysWithPlonkVerifier {
uint256 mask = (~uint256(0)) >> 3;
_individual_vks_inputs[i] = uint256(commitment) & mask;
}
// #endif
VerificationKey memory vk = getVkAggregated(uint32(_vkIndexes.length));

uint256 treeRoot = blockProof ? VK_TREE_ROOT : VK_EXIT_TREE_ROOT;
Expand Down
38 changes: 5 additions & 33 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-solpp';
import '@nomiclabs/hardhat-etherscan';
import 'hardhat-typechain';
import 'hardhat-contract-sizer';
import '@nomiclabs/hardhat-etherscan';

const prodConfig = {
// UPGRADE_NOTICE_PERIOD: 0,
MAX_AMOUNT_OF_REGISTERED_TOKENS: 127,
// PRIORITY_EXPIRATION: 101,
DUMMY_VERIFIER: false
};
const testnetConfig = {
UPGRADE_NOTICE_PERIOD: 0,
MAX_AMOUNT_OF_REGISTERED_TOKENS: 127,
// PRIORITY_EXPIRATION: 101,
DUMMY_VERIFIER: false
};
const testConfig = {
UPGRADE_NOTICE_PERIOD: 0,
MAX_AMOUNT_OF_REGISTERED_TOKENS: 5,
PRIORITY_EXPIRATION: 101,
DUMMY_VERIFIER: true
};

const localConfig = Object.assign({}, prodConfig);
localConfig.DUMMY_VERIFIER = process.env.DUMMY_VERIFIER ? true : localConfig.DUMMY_VERIFIER;

const contractDefs = {
rinkeby: testnetConfig,
ropsten: testnetConfig,
mainnet: prodConfig,
test: testConfig,
localhost: localConfig
};
import { Network, loadDefs } from './hardhat.utils';

export default {
defaultNetwork: 'env',
solidity: {
version: '0.7.3',
settings: {
Expand All @@ -51,11 +23,11 @@ export default {
sources: './contracts'
},
solpp: {
defs: process.env.ETH_NETWORK ? contractDefs[process.env.ETH_NETWORK] : contractDefs['test']
defs: loadDefs(process.env.ETH_NETWORK as Network)
},
networks: {
env: {
url: process.env.WEB3_URL
url: `${process.env.WEB3_URL}`
}
},
etherscan: {
Expand Down
38 changes: 38 additions & 0 deletions contracts/hardhat.test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-solpp';
import '@nomiclabs/hardhat-etherscan';
import 'hardhat-contract-sizer';
import { loadDefs } from './hardhat.utils';

export default {
defaultNetwork: 'env',
solidity: {
version: '0.7.3',
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
contractSizer: {
runOnCompile: false
},
paths: {
sources: './contracts',
cache: './cache/test-contracts',
artifacts: './artifacts/test-contracts'
},
solpp: {
defs: loadDefs('test')
},
networks: {
env: {
url: `${process.env.WEB3_URL}`,
allowUnlimitedContractSize: true
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY
}
};
15 changes: 15 additions & 0 deletions contracts/hardhat.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as fs from 'fs';
import * as path from 'path';

export type Network = 'localhost' | 'mainnet' | 'ropsten' | 'rinkeby' | 'test';

export function loadDefs(network: Network) {
try {
const configPath = path.join(process.env.ZKSYNC_HOME, `etc/contracts`);

return JSON.parse(fs.readFileSync(`${configPath}/${network}.json`, { encoding: 'utf-8' }));
} catch (err) {
console.warn('Invalid Configuration file');
return;
}
}
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
},
"scripts": {
"build": "hardhat compile",
"build-dev": "hardhat compile",
"test": "zk f yarn run hardhat test",
"test": "zk f yarn run hardhat test --config hardhat.test-config.ts",
"deploy-no-build": "ts-node scripts/deploy.ts",
"upgrade-testnet-no-build": "ts-node scripts/upgrade-testnet.ts",
"deploy-eip1271": "ts-node scripts/deploy-eip1271.ts",
"deploy-erc20": "ts-node scripts/deploy-erc20.ts",
"governance-add-erc20": "ts-node scripts/add-erc20-token.ts",
"deploy-testkit": "ts-node scripts/deploy-testkit.ts",
"publish-sources": "hardhat run --network env scripts/publish.ts",
"deploy-testnet-erc20": "ts-node scripts/deploy-testnet-token.ts"
Expand Down
61 changes: 38 additions & 23 deletions contracts/scripts/add-erc20-token.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
import { ArgumentParser } from 'argparse';
import { Command } from 'commander';
import { BigNumber, Wallet, ethers } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import * as fs from 'fs';
import * as path from 'path';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));
const deployer = new Deployer({ deployWallet: ethers.Wallet.createRandom() });
const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const governorWallet = Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

async function main() {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true,
description: 'Add erc20 token to the governance'
});

parser.addArgument('--tokenAddress', { required: true, help: 'Address erc20 token' });
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });

const args = parser.parseArgs(process.argv.slice(2));

const deployer = new Deployer({ deployWallet: ethers.Wallet.createRandom() });

const governorWallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);

console.log('Adding new ERC20 token to network: ', args.tokenAddress);
async function governanceAddToken(address: string) {
console.log('Adding new ERC20 token to network: ', address);

const tx = await deployer
.governanceContract(governorWallet)
.addToken(args.tokenAddress, { gasLimit: BigNumber.from('1000000') });
.addToken(address, { gasLimit: BigNumber.from('1000000') });
console.log('tx hash: ', tx.hash);
const receipt = await tx.wait();
console.log('status: ', receipt.status);

if (receipt.status) {
console.log('tx success');
} else {
throw new Error(`failed add token to the governance`);
}
}

async function main() {
const program = new Command();

program.version('0.1.0').name('governance-add-erc20').description('add testnet erc20 token to the governance');

program
.command('add')
.option('-a, --address <address>')
.description('Adds a new token with a given address')
.action(async (address: string) => {
await governanceAddToken(address);
});

program
.command('add-multi <tokens_json>')
.description('Adds a multiple tokens given in JSON format')
.action(async (tokens_json: string) => {
const tokens: Array<string> = JSON.parse(tokens_json);

for (const token of tokens) {
await governanceAddToken(token);
}
});
}

main();
19 changes: 0 additions & 19 deletions core/bin/gen_token_add_contract/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions core/bin/gen_token_add_contract/src/TokenInitTemplate.sol

This file was deleted.

52 changes: 0 additions & 52 deletions core/bin/gen_token_add_contract/src/main.rs

This file was deleted.

Loading

0 comments on commit 0617794

Please sign in to comment.