Skip to content

Commit

Permalink
Merge branch 'dev' into deniallugo-refactor-eth-watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniallugo committed Feb 21, 2022
2 parents 9cfdcf4 + e7f5620 commit 7a90ae5
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 34 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
lint:
runs-on: [self-hosted, CI-worker]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
ci_run zk lint --check
unit-tests:
runs-on: [self-hosted, CI-worker]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
run: ci_run zk test server-rust

integration:
runs-on: [self-hosted, FAST]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
ci_run cat dummy_prover.log
circuit-tests:
runs-on: [self-hosted, CI-worker]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand All @@ -147,6 +147,13 @@ jobs:
run: |
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
- name: start-services
run: |
docker-compose -f docker-compose-runner.yml down
docker-compose -f docker-compose-runner.yml pull
docker-compose -f docker-compose-runner.yml up --build -d geth postgres zk
ci_run sccache --start-server
- name: init
run: |
Expand All @@ -155,10 +162,10 @@ jobs:
ci_run zk run verify-keys unpack
- name: circuit-tests
run: ci_run zk test crypto-rust
run: ci_run zk test circuit 20

testkit:
runs-on: [self-hosted, CI-worker]
runs-on: [self-hosted, ci-runner]

steps:
- uses: actions/checkout@v2
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/zk-environment.publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: publish zk-environment docker image

on:
pull_request:
branches:
- dev
types: [closed]
paths:
- 'docker/zk-environment/Dockerfile'
- '.github/workflows/zk-environment.publish.yml'
workflow_dispatch:
branches:
- 'dev'

jobs:
push_to_registry:
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
name: Push Docker image to Docker Hub
runs-on: [self-hosted, ci-runner]
steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/[email protected]
with:
push: true
tags: "matterlabs/zk-environment:latest"
file: docker/zk-environment/Dockerfile
no-cache: true
3 changes: 3 additions & 0 deletions contracts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../etc/lint-config/ts.js')
};
3 changes: 3 additions & 0 deletions contracts/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../etc/prettier-config/ts.js')
};
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/api_server/rest/v02/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl ApiAccountData {
self.confirmations_for_eth_event,
)
.await?;

let (committed, finalized) = if let Some(account_id) = account_id {
let (finalized_state, committed_state) = transaction
.chain()
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/api_server/rest/v02/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl ApiTransactionData {
}

async fn tx_status(&self, tx_hash: TxHash) -> Result<Option<Receipt>, Error> {
// Try to find in the DB.
let mut storage = self
.tx_sender
.pool
Expand Down
3 changes: 3 additions & 0 deletions core/tests/ts-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../../etc/lint-config/ts.js')
};
3 changes: 3 additions & 0 deletions core/tests/ts-tests/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../../etc/prettier-config/ts.js')
};
4 changes: 4 additions & 0 deletions docker-compose-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ services:
- .:/usr/src/zksync
- /usr/src/cache:/usr/src/cache
- /usr/src/keys:/usr/src/keys
- /etc/sa_secret:/etc/sa_secret
environment:
- IN_DOCKER=true
- CACHE_DIR=/usr/src/cache
- SCCACHE_CACHE_SIZE=50g
- SCCACHE_GCS_BUCKET=sccache-zksync-ci
- SCCACHE_GCS_KEY_PATH=/etc/sa_secret/sa_key.json
- SCCACHE_GCS_RW_MODE=READ_WRITE
- CI=1
8 changes: 6 additions & 2 deletions docker/zk-environment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ FROM debian:bullseye
WORKDIR /usr/src/zksync

# Install required dependencies
RUN apt-get update; apt-get install -y make bash git openssl libssl-dev gcc g++ curl libpq-dev pkg-config software-properties-common jq
RUN apt-get update; apt-get install -y make bash git gnupg openssl libssl-dev gcc g++ curl libpq-dev pkg-config software-properties-common jq

#install docker engine
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
RUN apt update; apt install -y docker-ce-cli

# Install node and yarn
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
Expand Down Expand Up @@ -36,4 +41,3 @@ ENV PATH="${ZKSYNC_HOME}/bin:${PATH}"
ENV CI=1
RUN cargo install sccache
ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache
ENV SCCACHE_DIR=/usr/src/cache/sccache
2 changes: 1 addition & 1 deletion infrastructure/zk/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function serverRust() {
}

export async function cryptoRust() {
await circuit(6);
await circuit(25);
await rustCryptoTests();
}

Expand Down
3 changes: 3 additions & 0 deletions sdk/zksync.js/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../etc/lint-config/ts')
};
3 changes: 3 additions & 0 deletions sdk/zksync.js/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../../etc/prettier-config/ts')
};
2 changes: 1 addition & 1 deletion sdk/zksync.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zksync",
"version": "0.12.0-alpha.3",
"version": "0.12.0-alpha.6",
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
62 changes: 43 additions & 19 deletions sdk/zksync.js/src/remote-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumberish, ethers } from 'ethers';
import { BigNumber, BigNumberish, ethers } from 'ethers';
import { EthMessageSigner } from './eth-message-signer';
import { SyncProvider } from './provider-interface';
import { BatchBuilderInternalTx } from './batch-builder';
Expand Down Expand Up @@ -60,21 +60,6 @@ export class RemoteWallet extends AbstractWallet {
);
wallet.connect(provider);
await wallet.verifyNetworks();

// Before creating the account, we should check that the private key is indeed managed remotely.
try {
wallet.syncSignerPubKeyHash();
} catch (e) {
// TODO: Catching general error is a bad idea, as a lot of things can throw an exception.
// Generally we should catch a concrete error stating that such a method is not supported, and throw an
// exception only in that case. And, probably, have a retry mechanism, so we don't create the wallet if it
// was just a WalletConnect glitch.
throw new Error(
"There was an attempt to create a wallet that manages user keys remotely, \
but the server doesn't seem to have required capabilities"
);
}

return wallet;
}

Expand All @@ -96,7 +81,9 @@ export class RemoteWallet extends AbstractWallet {
}

override async syncSignerPubKeyHash(): Promise<PubKeyHash> {
return await this.callExtSignerPubKeyHash();
let pubKeyHash = await this.callExtSignerPubKeyHash();
pubKeyHash = pubKeyHash.replace('0x', 'sync:');
return pubKeyHash;
}

// *********************
Expand Down Expand Up @@ -393,6 +380,41 @@ export class RemoteWallet extends AbstractWallet {
// Internal methods
//

/**
*
* Makes all fields that represent amount to be of `string` type
* and all fields that represent tokens to be token ids i.e. of `number` type.
* Also, it renames `ethAddress` parameter to `to` for withdrawals.
*
* @param txs A list of transactions
*
* @returns A list of prepared transactions
*/
protected prepareTxsBeforeSending(txs: any[]): any[] {
const amountFields = ['amount', 'fee'];
const tokenFields = ['token', 'feeToken', 'tokenSell', 'tokenBuy'];
return txs.map((tx) => {
for (const field of amountFields) {
if (field in tx) {
tx[field] = BigNumber.from(tx[field]).toString();
}
}
for (const field of tokenFields) {
if (field in tx) {
tx[field] = this.provider.tokenSet.resolveTokenId(tx[field]);
}
}
if ('amounts' in tx) {
tx.amounts = [BigNumber.from(tx.amounts[0]).toString(), BigNumber.from(tx.amounts[1]).toString()];
}
if ('ethAddress' in tx) {
tx.to = tx.ethAddress;
delete tx.ethAddress;
}
return tx;
});
}

/**
* Performs an RPC call to the custom `zkSync_signBatch` method.
* This method is specified here: https://github.com/argentlabs/argent-contracts-l2/discussions/4
Expand All @@ -407,10 +429,11 @@ export class RemoteWallet extends AbstractWallet {
*/
protected async callExtSignZkSyncBatch(txs: any[]): Promise<SignedTransaction[]> {
try {
const preparedTxs = this.prepareTxsBeforeSending(txs);
// Response must be an array of signed transactions.
// Transactions are flattened (ethereum signatures are on the same level as L2 signatures),
// so we need to "unflat" each one.
const response: any[] = await this.web3Provider.send('zkSync_signBatch', [txs]);
const response: any[] = await this.web3Provider.send('zkSync_signBatch', [preparedTxs]);

const transactions = response.map((tx) => {
const ethereumSignature = tx['ethereumSignature'];
Expand Down Expand Up @@ -438,8 +461,9 @@ export class RemoteWallet extends AbstractWallet {
*/
protected async callExtSignOrder(order: any): Promise<Order> {
try {
const preparedOrder = this.prepareTxsBeforeSending([order]);
// For now, we assume that the same method will be used for both signing transactions and orders.
const signedOrder: any = await this.web3Provider.send('zkSync_signBatch', [order]);
const signedOrder: any = (await this.web3Provider.send('zkSync_signBatch', [preparedOrder]))[0];

// Sanity check
if (!signedOrder['signature']) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Wallet extends AbstractWallet {
}

override syncSignerConnected(): boolean {
return this.signer !== null;
return this.signer != null;
}

override async syncSignerPubKeyHash(): Promise<PubKeyHash> {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8618,9 +8618,9 @@ simple-concat@^1.0.0:
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==

simple-get@^2.7.0:
version "2.8.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-2.8.1.tgz#0e22e91d4575d87620620bc91308d57a77f44b5d"
integrity sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==
version "2.8.2"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-2.8.2.tgz#5708fb0919d440657326cd5fe7d2599d07705019"
integrity sha512-Ijd/rV5o+mSBBs4F/x9oDPtTx9Zb6X9brmnXvMW4J7IR15ngi9q5xxqWBKU744jTZiaXtxaPL7uHG6vtN8kUkw==
dependencies:
decompress-response "^3.3.0"
once "^1.3.1"
Expand Down Expand Up @@ -10650,7 +10650,7 @@ yocto-queue@^0.1.0:
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

"zksync@link:sdk/zksync.js":
version "0.11.6"
version "0.12.0-alpha.4"
dependencies:
axios "^0.21.2"
websocket "^1.0.30"
Expand Down

0 comments on commit 7a90ae5

Please sign in to comment.