Skip to content

Commit

Permalink
Merge branch 'dev' into vb-zks-100-check-confirmations-fail-tx-in-eth…
Browse files Browse the repository at this point in the history
…-sender
  • Loading branch information
popzxc authored Dec 2, 2020
2 parents cf6b4c9 + bb2be16 commit a37579c
Show file tree
Hide file tree
Showing 63 changed files with 1,293 additions and 639 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion contracts/scripts/add-erc20-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ArgumentParser } from 'argparse';
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' }));

async function main() {
const parser = new ArgumentParser({
Expand All @@ -17,9 +21,10 @@ async function main() {
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(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
: Wallet.fromMnemonic(ethTestConfig.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);

console.log('Adding new ERC20 token to network: ', args.tokenAddress);

Expand Down
19 changes: 17 additions & 2 deletions contracts/scripts/contract-info.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { Contract, ethers } from 'ethers';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import { Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
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' }));

async function main() {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

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

const deployer = new Deployer({ deployWallet: wallet });
const upgradeGatekeeper = deployer.upgradeGatekeeperContract(wallet);
const tx = await upgradeGatekeeper.finishUpgrade(['0x', '0x', '0x']);
Expand Down
11 changes: 6 additions & 5 deletions contracts/scripts/deploy-eip1271.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import { deployContract } from 'ethereum-waffle';
import * as fs from 'fs';
import * as path from 'path';

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const EIP1271TestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eip1271.json`, { encoding: 'utf-8' }));
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

(async () => {
try {
if (!['test', 'localhost'].includes(process.env.ETH_NETWORK)) {
console.error('This deploy script is only for localhost-test network');
process.exit(1);
}

const testConfigPath = path.join(process.env.ZKSYNC_HOME, `etc/test_config/constant/eip1271.json`);
const testConfig = JSON.parse(fs.readFileSync(testConfigPath, { encoding: 'utf-8' }));

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
provider.pollingInterval = 10;

const deployWallet = ethers.Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/0").connect(
const deployWallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(
provider
);
const smartWallet = await deployContract(
deployWallet,
readContractCode('AccountMock'),
[testConfig.owner_address],
[EIP1271TestConfig.owner_address],
{
gasLimit: 5000000
}
Expand Down
11 changes: 9 additions & 2 deletions contracts/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { deployContract } from 'ethereum-waffle';
import { ethers, Wallet } from 'ethers';
import { readContractCode } from '../src.ts/deploy';
import { parseEther } from 'ethers/lib/utils';
import * as fs from 'fs';
import * as path from 'path';

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 provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const wallet = Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

type Token = {
address: string | null;
Expand All @@ -24,7 +29,9 @@ async function deployToken(token: Token): Promise<Token> {

await erc20.mint(wallet.address, parseEther('3000000000'));
for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/" + i).connect(provider);
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, "m/44'/60'/0'/0/" + i).connect(
provider
);
await erc20.mint(testWallet.address, parseEther('3000000000'));
}
token.address = erc20.address;
Expand Down
9 changes: 7 additions & 2 deletions contracts/scripts/deploy-testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { ethers, Wallet } from 'ethers';
import { Deployer, readContractCode, readTestContracts, readProductionContracts } from '../src.ts/deploy';
import { deployContract } from 'ethereum-waffle';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';

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' }));

(async () => {
const parser = new ArgumentParser({
Expand All @@ -26,7 +31,7 @@ import { ArgumentParser } from 'argparse';
const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
provider.pollingInterval = 10;

const deployWallet = ethers.Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/0").connect(provider);
const deployWallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(provider);
const contracts = args.prodContracts ? readProductionContracts() : readTestContracts();
const deployer = new Deployer({ deployWallet, contracts, verbose: true });
await deployer.deployAll();
Expand All @@ -47,7 +52,7 @@ import { ArgumentParser } from 'argparse';
}

for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/" + i).connect(provider);
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/" + i).connect(provider);
await (await erc20.mint(testWallet.address, '0x4B3B4CA85A86C47A098A224000000000')).wait();
}
})();
10 changes: 9 additions & 1 deletion contracts/scripts/deploy-testnet-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { ethers, Wallet } from 'ethers';
import { readContractCode } from '../src.ts/deploy';
import { encodeConstructorArgs, publishSourceCodeToEtherscan } from '../src.ts/publish-utils';
import * as fs from 'fs';
import * as path from 'path';
import { ArgumentParser } from 'argparse';

const mainnetTokens = require(`${process.env.ZKSYNC_HOME}/etc/tokens/mainnet`);

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' }));

(async () => {
const parser = new ArgumentParser({
version: '0.1.0',
Expand All @@ -18,10 +22,14 @@ const mainnetTokens = require(`${process.env.ZKSYNC_HOME}/etc/tokens/mainnet`);
action: 'storeTrue',
help: 'Only publish code for deployed tokens'
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

const contractCode = readContractCode('TestnetERC20Token');

if (process.env.ETH_NETWORK === 'mainnet') {
Expand Down
6 changes: 5 additions & 1 deletion contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { ArgumentParser } from 'argparse';
import { ethers, Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import { formatUnits, parseUnits } from 'ethers/lib/utils';
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' }));

(async () => {
const parser = new ArgumentParser({
Expand All @@ -24,7 +28,7 @@ const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

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

const gasPrice = args.gasPrice ? parseUnits(args.gasPrice, 'gwei') : await provider.getGasPrice();
console.log(`Using gas price: ${formatUnits(gasPrice, 'gwei')} gwei`);
Expand Down
27 changes: 23 additions & 4 deletions contracts/scripts/init-faucet-account.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import { ethers } from 'ethers';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import * as zksync from 'zksync';
import { ethers } from 'ethers';

const DEPOSIT_AMOUNT = ethers.utils.parseEther('10000000000');
const network = process.env.ETH_NETWORK;

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const deployerEthWallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const faucetEthWallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/2").connect(provider);
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' }));

async function main() {
const syncProvider = await zksync.Provider.newHttpProvider(process.env.HTTP_RPC_API_ADDR);
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
parser.addArgument('--faucetPrivateKey', { required: false, help: 'Wallet used as faucet' });
const args = parser.parseArgs(process.argv.slice(2));

const deployerEthWallet = args.deployerPrivateKey
? new ethers.Wallet(args.deployerPrivateKey, provider)
: ethers.Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);
const faucetEthWallet = args.faucetPrivateKey
? new ethers.Wallet(args.faucetPrivateKey, provider)
: ethers.Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/2").connect(provider);

const syncProvider = await zksync.getDefaultProvider(network as zksync.types.Network);
const deployerWallet = await zksync.Wallet.fromEthSigner(deployerEthWallet, syncProvider);
const faucetWallet = await zksync.Wallet.fromEthSigner(faucetEthWallet, syncProvider);

Expand Down
19 changes: 17 additions & 2 deletions contracts/scripts/submit-test-proof.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import { deployContract } from 'ethereum-waffle';
import { ethers } from 'ethers';
import { Wallet } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
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 MAX_CONTRACT_SIZE_BYTES = 24576;
async function main() {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

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

const verifierContractCode = require('../build/ConcreteVerifier.json');
const verifier = await deployContract(wallet, verifierContractCode, [], {
gasLimit: 3000000
Expand Down
7 changes: 5 additions & 2 deletions contracts/scripts/test-upgrade-franklin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { ArgumentParser } from 'argparse';
import { deployContract } from 'ethereum-waffle';
import { constants, ethers } from 'ethers';
import { readTestContracts } from '../src.ts/deploy';
import * as fs from 'fs';
import * as path from 'path';

const { expect } = require('chai');

export const FranklinTestUpgradeTargetContractCode = require(`../build/ZkSyncTestUpgradeTarget`);

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 testContracts = readTestContracts();

async function main() {
Expand All @@ -26,7 +29,7 @@ async function main() {

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

const wallet = ethers.Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/0").connect(provider);
const wallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(provider);

const proxyContract = new ethers.Contract(args.contractAddress, testContracts.proxy.abi, wallet);

Expand Down
6 changes: 5 additions & 1 deletion contracts/scripts/upgrade-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { ArgumentParser } from 'argparse';
import { ethers, Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import { formatUnits, parseUnits } from 'ethers/lib/utils';
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' }));

(async () => {
const parser = new ArgumentParser({
Expand Down Expand Up @@ -36,7 +40,7 @@ const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

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

const gasPrice = args.gasPrice ? parseUnits(args.gasPrice, 'gwei') : await provider.getGasPrice();
console.info(`Using gas price: ${formatUnits(gasPrice, 'gwei')} gwei`);
Expand Down
17 changes: 9 additions & 8 deletions core/bin/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use std::cell::RefCell;
use structopt::StructOpt;
use zksync_api::run_api;
use zksync_config::{ConfigurationOptions, ProverOptions};
use zksync_config::{ConfigurationOptions, EthClientOptions, EthSenderOptions, ProverOptions};
use zksync_core::{genesis_init, run_core, wait_for_tasks};
use zksync_eth_sender::run_eth_sender;
use zksync_prometheus_exporter::run_prometheus_exporter;
Expand Down Expand Up @@ -46,6 +46,8 @@ async fn main() -> anyhow::Result<()> {

let connection_pool = ConnectionPool::new(None);
let config_options = ConfigurationOptions::from_env();
let eth_client_options = EthClientOptions::from_env();
let eth_sender_options = EthSenderOptions::from_env();
let prover_options = ProverOptions::from_env();

// Handle Ctrl+C
Expand Down Expand Up @@ -77,16 +79,15 @@ async fn main() -> anyhow::Result<()> {

// Run Ethereum sender actors.
log::info!("Starting the Ethereum sender actors");
let eth_sender_task_handle = run_eth_sender(connection_pool.clone(), config_options.clone());
let eth_sender_task_handle = run_eth_sender(
connection_pool.clone(),
eth_client_options,
eth_sender_options,
);

// Run prover server & witness generator.
log::info!("Starting the Prover server actors");
run_prover_server(
connection_pool,
stop_signal_sender,
prover_options,
config_options,
);
run_prover_server(connection_pool, stop_signal_sender, prover_options);

tokio::select! {
_ = async { wait_for_tasks(core_task_handles).await } => {
Expand Down
Loading

0 comments on commit a37579c

Please sign in to comment.