Skip to content

Commit

Permalink
Merge branch 'dev' into ib/680/fast_block_revert
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush authored Jul 2, 2020
2 parents d547270 + beeefad commit 2b05381
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 207 deletions.
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"chai": "^4.2.0",
"ethereum-waffle": "2.0.12",
"ethereumjs-abi": "^0.6.8",
"ethers": "4.0.46",
"ethers": "4.0.47",
"ethjs": "^0.4.0",
"fs": "^0.0.1-security",
"mocha": "^6.2.0",
Expand Down Expand Up @@ -44,6 +44,6 @@
"prettier:solidity": "prettier --write contracts/**/*.sol"
},
"resolutions": {
"ethereum-waffle/ethers": "4.0.46"
"ethereum-waffle/ethers": "4.0.47"
}
}
12 changes: 6 additions & 6 deletions contracts/test/unit_tests/zksync_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("zkSync signature verification unit tests", function() {
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const nonce = 0x11223344;
const accountId = 0xdeadba;
const signature = await zksync.utils.signChangePubkeyMessage(randomWallet, pubkeyHash, nonce, accountId);
const signature = await randomWallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId));
const {revertReason, result} = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(signature, pubkeyHash.replace("sync:", "0x"), nonce, randomWallet.address, accountId));
expect(result).eq(true);
Expand All @@ -45,7 +45,7 @@ describe("zkSync signature verification unit tests", function() {
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const nonce = 0x11223344;
const accountId = 0xdeadba;
const signature = await zksync.utils.signChangePubkeyMessage(randomWallet, pubkeyHash, nonce, accountId);
const signature = await randomWallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId));
const {result} = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(signature, pubkeyHash.replace("sync:", "0x"), incorrectNonce, randomWallet.address, accountId));
expect(result).eq(false);
Expand All @@ -56,7 +56,7 @@ describe("zkSync signature verification unit tests", function() {
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const nonce = 0x11223344;
const accountId = 0xdeadba;
const signature = await zksync.utils.signChangePubkeyMessage(randomWallet, pubkeyHash, nonce, accountId);
const signature = await randomWallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId));
const {result} = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(signature, incorrectPubkeyHash.replace("sync:", "0x"), nonce, randomWallet.address, accountId));
expect(result).eq(false);
Expand All @@ -67,7 +67,7 @@ describe("zkSync signature verification unit tests", function() {
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const nonce = 0x11223344;
const accountId = 0xdeadba;
const signature = await zksync.utils.signChangePubkeyMessage(randomWallet, pubkeyHash, nonce, accountId);
const signature = await randomWallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId));
const {result} = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(signature, pubkeyHash.replace("sync:", "0x"), nonce, incorrectSignerAddress, accountId));
expect(result).eq(false);
Expand All @@ -78,7 +78,7 @@ describe("zkSync signature verification unit tests", function() {
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const nonce = 0x11223344;
const accountId = 0xdeadba;
const signature = await zksync.utils.signChangePubkeyMessage(randomWallet, pubkeyHash, nonce, accountId);
const signature = await randomWallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId));
const {result} = await getCallRevertReason(() =>
testContract.changePubkeySignatureCheck(signature, pubkeyHash.replace("sync:", "0x"), nonce, randomWallet.address, incorrectAccountId));
expect(result).eq(false);
Expand Down Expand Up @@ -645,7 +645,7 @@ describe("zkSync test process next operation", function() {
const nonce = 0x1234;
const pubkeyHash = "sync:fefefefefefefefefefefefefefefefefefefefe";
const accountId = 0x00ffee12;
const ethWitness = await zksync.utils.signChangePubkeyMessage(wallet, pubkeyHash, nonce, accountId);
const ethWitness = await wallet.signMessage(zksync.utils.getChangePubkeyMessage(pubkeyHash, nonce, accountId))

const committedPriorityRequestsBefore = await zksyncContract.totalCommittedPriorityRequests();

Expand Down
8 changes: 4 additions & 4 deletions contracts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2285,10 +2285,10 @@ [email protected]:
utf8 "^3.0.0"
uuid "^3.3.2"

[email protected].46, ethers@^4.0.0:
version "4.0.46"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.46.tgz#13cd3ed099487f43ece00194b89a8a8781f71507"
integrity sha512-/dPMzzpInhtiip4hKFvsDiJKeRk64IhyA+Po7CtNXneQFSOCYXg8eBFt+jXbxUQyApgWnWOtYxWdfn9+CvvxDA==
[email protected].47, ethers@^4.0.0:
version "4.0.47"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.47.tgz#91b9cd80473b1136dd547095ff9171bd1fc68c85"
integrity sha512-hssRYhngV4hiDNeZmVU/k5/E8xmLG8UpcNUzg6mb7lqhgpFPH/t7nuv20RjRrEf0gblzvi2XwR5Te+V3ZFc9pQ==
dependencies:
aes-js "3.0.0"
bn.js "^4.4.0"
Expand Down
7 changes: 6 additions & 1 deletion js/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1701,11 +1701,16 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"
integrity sha1-UzRK2xRhehP26N0s4okF0cC6MhU=

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==

bn.js@^4.4.0:
version "4.11.9"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==

bn.js@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5"
Expand Down
7 changes: 6 additions & 1 deletion js/explorer/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1749,11 +1749,16 @@ bluebird@^3.1.1, bluebird@^3.5.5:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==

bn.js@^4.4.0:
version "4.11.9"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==

bn.js@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5"
Expand Down
2 changes: 1 addition & 1 deletion js/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@types/node": "^12.12.14",
"array-flat-polyfill": "^1.0.1",
"cli-progress": "^3.5.0",
"ethers": "4.0.46",
"ethers": "4.0.47",
"openzeppelin-solidity": "^2.4.0",
"ts-node": "^8.5.4",
"typescript": "^3.7.4",
Expand Down
8 changes: 4 additions & 4 deletions js/tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ es6-symbol@^3.1.1, es6-symbol@~3.1.3:
d "^1.0.1"
ext "^1.1.2"

[email protected].46:
version "4.0.46"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.46.tgz#13cd3ed099487f43ece00194b89a8a8781f71507"
integrity sha512-/dPMzzpInhtiip4hKFvsDiJKeRk64IhyA+Po7CtNXneQFSOCYXg8eBFt+jXbxUQyApgWnWOtYxWdfn9+CvvxDA==
[email protected].47:
version "4.0.47"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.47.tgz#91b9cd80473b1136dd547095ff9171bd1fc68c85"
integrity sha512-hssRYhngV4hiDNeZmVU/k5/E8xmLG8UpcNUzg6mb7lqhgpFPH/t7nuv20RjRrEf0gblzvi2XwR5Te+V3ZFc9pQ==
dependencies:
aes-js "3.0.0"
bn.js "^4.4.0"
Expand Down
30 changes: 30 additions & 0 deletions js/zksync.js/abi/IEIP1271.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"interface": [
{
"constant": true,
"inputs": [
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "_signature",
"type": "bytes"
}
],
"name": "isValidSignature",
"outputs": [
{
"internalType": "bytes4",
"name": "",
"type": "bytes4"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
}
1 change: 1 addition & 0 deletions js/zksync.js/abi/update-abi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ cd `dirname $0`

cat $ZKSYNC_HOME/contracts/build/ZkSync.json | jq '{ interface: .interface}' > SyncMain.json
cat $ZKSYNC_HOME/contracts/build/Governance.json | jq '{ interface: .interface}' > SyncGov.json
cat $ZKSYNC_HOME/contracts/build/IEIP1271.json | jq '{ interface: .interface}' > IEIP1271.json
13 changes: 2 additions & 11 deletions js/zksync.js/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"name": "zksync",
"version": "0.5.12",
"version": "0.5.14",
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"axios": "^0.19.0",
"blake2b": "^2.1.3",
"bn.js": "^5.0.0",
"crypto-js": "^3.1.9-1",
"elliptic": "^6.5.0",
"js-sha256": "^0.9.0",
"websocket": "^1.0.30",
"websocket-as-promised": "^0.10.1",
"zksync-crypto": "^0.2.1"
Expand All @@ -19,17 +15,12 @@
"ethers": "^4.0.46"
},
"devDependencies": {
"@types/bn.js": "^4.11.5",
"@types/chai": "^4.1.7",
"@types/crypto-js": "^3.1.43",
"@types/elliptic": "^6.4.9",
"@types/eventsource": "^1.1.2",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.8",
"chai": "^4.2.0",
"ethers": "4.0.46",
"ethers": "4.0.47",
"mocha": "^6.2.0",
"openzeppelin-solidity": "^2.3.0",
"prettier": "1.18.2",
"ts-node": "^8.3.0",
"tslint": "^6.0.0-beta0",
Expand Down
25 changes: 11 additions & 14 deletions js/zksync.js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HTTPTransport,
WSTransport
} from "./transport";
import {utils, ethers, Contract} from "ethers";
import { utils, ethers, Contract } from "ethers";
import {
AccountState,
Address,
Expand Down Expand Up @@ -73,8 +73,7 @@ export class Provider {
contractAddress: ContractAddress;
public tokenSet: TokenSet;

private constructor(public transport: AbstractJSONRPCTransport) {
}
private constructor(public transport: AbstractJSONRPCTransport) {}

static async newWebsocketProvider(address: string): Promise<Provider> {
const transport = await WSTransport.connect(address);
Expand Down Expand Up @@ -135,12 +134,12 @@ export class Provider {
): Promise<PriorityOperationReceipt> {
if (this.transport.subscriptionsSupported()) {
return await new Promise(resolve => {
const sub = this.transport.subscribe(
const subscribe = this.transport.subscribe(
"ethop_subscribe",
[serialId, action],
"ethop_unsubscribe",
resp => {
sub.then(sub => sub.unsubscribe());
subscribe.then(sub => sub.unsubscribe());
resolve(resp);
}
);
Expand All @@ -149,7 +148,7 @@ export class Provider {
while (true) {
const priorOpStatus = await this.getPriorityOpStatus(serialId);
const notifyDone =
action == "COMMIT"
action === "COMMIT"
? priorOpStatus.block && priorOpStatus.block.committed
: priorOpStatus.block && priorOpStatus.block.verified;
if (notifyDone) {
Expand All @@ -167,12 +166,12 @@ export class Provider {
): Promise<TransactionReceipt> {
if (this.transport.subscriptionsSupported()) {
return await new Promise(resolve => {
const sub = this.transport.subscribe(
const subscribe = this.transport.subscribe(
"tx_subscribe",
[hash, action],
"tx_unsubscribe",
resp => {
sub.then(sub => sub.unsubscribe());
subscribe.then(sub => sub.unsubscribe());
resolve(resp);
}
);
Expand All @@ -183,9 +182,9 @@ export class Provider {
const notifyDone =
action == "COMMIT"
? transactionStatus.block &&
transactionStatus.block.committed
transactionStatus.block.committed
: transactionStatus.block &&
transactionStatus.block.verified;
transactionStatus.block.verified;
if (notifyDone) {
return transactionStatus;
} else {
Expand All @@ -211,13 +210,11 @@ export class Provider {
gasPriceWei: utils.bigNumberify(transactionFee.gasPriceWei),
gasFee: utils.bigNumberify(transactionFee.gasFee),
zkpFee: utils.bigNumberify(transactionFee.zkpFee),
totalFee: utils.bigNumberify(transactionFee.totalFee),
totalFee: utils.bigNumberify(transactionFee.totalFee)
};
}

async getTokenPrice(
tokenLike: TokenLike
): Promise<number> {
async getTokenPrice(tokenLike: TokenLike): Promise<number> {
const tokenPrice = await this.transport.request("get_token_price", [
tokenLike
]);
Expand Down
25 changes: 17 additions & 8 deletions js/zksync.js/src/signer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { curve } from "elliptic";
import {
privateKeyFromSeed,
signTransactionBytes,
Expand All @@ -8,13 +7,21 @@ import { ethers, utils } from "ethers";
import {
packAmountChecked,
packFeeChecked,
getEthSignatureType
getEthSignatureType,
signMessagePersonalAPI,
getSignedBytesFromMessage
} from "./utils";
import BN = require("bn.js");
import { Address, CloseAccount, PubKeyHash, Transfer, Withdraw } from "./types";
import {
Address,
EthSignerType,
PubKeyHash,
Transfer,
Withdraw
} from "./types";

const MAX_NUMBER_OF_TOKENS = 4096;
const MAX_NUMBER_OF_ACCOUNTS = 1 << 24;
const MAX_NUMBER_OF_TOKENS = 128;
const MAX_NUMBER_OF_ACCOUNTS = Math.pow(2, 24);

export class Signer {
readonly privateKey: Uint8Array;
Expand Down Expand Up @@ -123,15 +130,17 @@ export class Signer {
ethSigner: ethers.Signer
): Promise<{
signer: Signer;
ethSignatureType: "EthereumSignature" | "EIP1271Signature";
ethSignatureType: EthSignerType;
}> {
const message =
"Access zkSync account.\n" +
"\n" +
"Only sign this message for a trusted client!";
const signature = await ethSigner.signMessage(message);
const signedBytes = getSignedBytesFromMessage(message, false);
const signature = await signMessagePersonalAPI(ethSigner, signedBytes);
const address = await ethSigner.getAddress();
const ethSignatureType = getEthSignatureType(
const ethSignatureType = await getEthSignatureType(
ethSigner.provider,
message,
signature,
address
Expand Down
2 changes: 1 addition & 1 deletion js/zksync.js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class WSTransport extends AbstractJSONRPCTransport {
unsubRep.error
);
}
if (unsubRep.result != true) {
if (unsubRep.result !== true) {
throw new Error(
`Unsubscription failed, returned false: ${subId}`
);
Expand Down
Loading

0 comments on commit 2b05381

Please sign in to comment.