Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:matter-labs/zksync-dev into fk/night…
Browse files Browse the repository at this point in the history
…ly-run-loadtest
  • Loading branch information
furkhat committed Apr 30, 2020
2 parents d6845f5 + c8191c2 commit 62e4a69
Show file tree
Hide file tree
Showing 124 changed files with 4,645 additions and 4,466 deletions.
950 changes: 428 additions & 522 deletions .drone.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ npm-debug.log

Cargo.lock
!/Cargo.lock
!/js/zksync-crypto/Cargo.lock

/etc/env/*
!/etc/env/dev.env.example
Expand Down
4,188 changes: 2,097 additions & 2,091 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export PROVER_DOCKER_IMAGE ?=matterlabs/prover:$(IMAGE_TAG)
export NGINX_DOCKER_IMAGE ?= matterlabs/nginx:$(IMAGE_TAG)
export GETH_DOCKER_IMAGE ?= matterlabs/geth:latest
export CI_DOCKER_IMAGE ?= matterlabs/ci
export GANACHE_DOCKER_IMAGE ?= matterlabs/ganache

# Getting started

Expand Down Expand Up @@ -103,12 +102,6 @@ image-ci:
push-image-ci: image-ci
docker push "${CI_DOCKER_IMAGE}"

image-ganache:
@cd docker/ganache && envsubst < Dockerfile | docker build -t "${GANACHE_DOCKER_IMAGE}" . -f -

push-image-ganache: image-ganache
docker push "${GANACHE_DOCKER_IMAGE}"

# Using RUST+Linux docker image (ekidd/rust-musl-builder) to build for Linux. More at https://github.com/emk/rust-musl-builder
docker-options = --rm -v $(shell pwd):/home/rust/src -v cargo-git:/home/rust/.cargo/git -v cargo-registry:/home/rust/.cargo/registry --env-file $(ZKSYNC_HOME)/etc/env/$(ZKSYNC_ENV).env
rust-musl-builder = @docker run $(docker-options) ekidd/rust-musl-builder
Expand Down Expand Up @@ -175,7 +168,7 @@ ci-check:
@ci-check.sh

integration-testkit: build-contracts
@bin/integration-testkit
@bin/integration-testkit.sh

migration-test: build-contracts
cargo run --bin migration_test --release
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ZK Sync: scaling and privacy engine for Ethereum
# zkSync: scaling and privacy engine for Ethereum

Check out [ZK Sync live demo](https://demo.matter-labs.io/).
Check out [zkSync live demo](https://demo.matter-labs.io/).

ZK Sync is a scaling and privacy engine for Ethereum. Its current functionality scope includes low gas transfers of ETH and ERC20 tokens in the Ethereum network. This document is a description of the JS library that can be used to interact with ZK Sync.
zkSync is a scaling and privacy engine for Ethereum. Its current functionality scope includes low gas transfers of ETH and ERC20 tokens in the Ethereum network. This document is a description of the JS library that can be used to interact with zkSync.

ZK Sync is built on ZK Rollup architecture. ZK Rollup is an L2 scaling solution in which all funds are held by a smart contract on the mainchain, while computation and storage are performed off-chain. For every Rollup block, a state transition zero-knowledge proof (SNARK) is generated and verified by the mainchain contract. This SNARK includes the proof of the validity of every single transaction in the Rollup block. Additionally, the public data update for every block is published over the mainchain network in the cheap calldata.
zkSync is built on ZK Rollup architecture. ZK Rollup is an L2 scaling solution in which all funds are held by a smart contract on the mainchain, while computation and storage are performed off-chain. For every Rollup block, a state transition zero-knowledge proof (SNARK) is generated and verified by the mainchain contract. This SNARK includes the proof of the validity of every single transaction in the Rollup block. Additionally, the public data update for every block is published over the mainchain network in the cheap calldata.

This architecture provides the following guarantees:

Expand All @@ -14,7 +14,7 @@ This architecture provides the following guarantees:

In other words, ZK Rollup strictly inherits the security guarantees of the underlying L1.

To learn how to use ZK Sync, please refer to the [ZK Sync SDK documentation](https://zksync.io).
To learn how to use zkSync, please refer to the [zkSync SDK documentation](https://zksync.io).

## Prerequisites

Expand Down Expand Up @@ -258,7 +258,7 @@ zksync publish-source

# License

ZK Sync is distributed under the terms of both the MIT license
zkSync is distributed under the terms of both the MIT license
and the Apache License (Version 2.0).

See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT) for details.
2 changes: 2 additions & 0 deletions bin/db-setup
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cd core/storage
echo DATABASE_URL=$DATABASE_URL
diesel database setup
diesel migration run

mv -f src/schema.rs.generated src/schema.rs
11 changes: 4 additions & 7 deletions bin/integration-testkit → bin/integration-testkit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ function clean_up() {
exit $exitcode
}

# run with usual geth
cargo run --bin exodus_test --release

# set up ganache
# set up fast geth
if [[ $ZKSYNC_ENV == ci ]]; then
export WEB3_URL=http://ganache:7545
export WEB3_URL=http://geth-fast:8545
elif [[ $ZKSYNC_ENV == dev ]]; then
CONTAINER_ID=$(docker run --rm -d -p 7545:7545 matterlabs/ganache)
CONTAINER_ID=$(docker run --rm -d -p 7545:8545 matterlabs/geth:latest fast)
export WEB3_URL=http://localhost:7545
fi

# run with ganache
cargo run --bin exodus_test --release
cargo run --bin testkit --release
cargo run --bin migration_test --release
117 changes: 75 additions & 42 deletions contracts/contracts/Bytes.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.16;
pragma solidity ^0.5.0;


library Bytes {
Expand Down Expand Up @@ -38,47 +38,60 @@ library Bytes {
bts = toBytesFromUIntTruncated(uint(self), 20);
}

function bytesToAddress(bytes memory self) internal pure returns (address addr) {
require(self.length == 20, "bbs11");
function bytesToAddress(bytes memory self, uint256 _start) internal pure returns (address addr) {
require(self.length >= (_start + 20), "bta11");
assembly {
// Load 32 bytes, address is only 20 bytes, discard 12 bytes (96 bits)
addr := shr(96, mload(add(self, 0x20)))
addr := mload(add(add(self, 20), _start))
}
}

function bytesToUInt16(bytes memory self) internal pure returns (uint16 r) {
require(self.length >= 2, "bb611");
function bytesToBytes20(bytes memory self, uint256 _start) internal pure returns (bytes20 r) {
require(self.length >= (_start + 20), "btb20");
assembly {
r := mload(add(add(self, 0x2), 0))
// Note that bytes1..32 is stored in the beginning of the word unlike other primitive types
r := mload(add(add(self, 0x20), _start))
}
}

function bytesToUInt24(bytes memory self) internal pure returns (uint24 r) {
require(self.length >= 3, "bb411");
function bytesToUInt16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 r) {
require(_bytes.length >= (_start + 2), "btu02");
assembly {
r := mload(add(add(self, 0x3), 0))
r := mload(add(add(_bytes, 0x2), _start))
}
}

function bytesToUInt32(bytes memory self) internal pure returns (uint32 r) {
require(self.length >= 4, "bb411");
function bytesToUInt24(bytes memory _bytes, uint256 _start) internal pure returns (uint24 r) {
require(_bytes.length >= (_start + 3), "btu03");
assembly {
r := mload(add(add(self, 0x4), 0))
r := mload(add(add(_bytes, 0x3), _start))
}
}

function bytesToUInt128(bytes memory self) internal pure returns (uint128 r)
{
require(self.length >= 16, "bb811");
function bytesToUInt32(bytes memory _bytes, uint256 _start) internal pure returns (uint32 r) {
require(_bytes.length >= (_start + 4), "btu04");
assembly {
r := mload(add(add(_bytes, 0x4), _start))
}
}

function bytesToUInt128(bytes memory _bytes, uint256 _start) internal pure returns (uint128 r) {
require(_bytes.length >= (_start + 16), "btu16");
assembly {
r := mload(add(add(self, 0x10), 0))
r := mload(add(add(_bytes, 0x10), _start))
}
}

function bytesToBytes32(bytes memory _input) internal pure returns (bytes32 _output) {
require (_input.length == 0x20);
function bytesToUInt160(bytes memory _bytes, uint256 _start) internal pure returns (uint160 r) {
require(_bytes.length >= (_start + 20), "btu20");
assembly {
_output := mload(add(_input, 0x20))
r := mload(add(add(_bytes, 0x14), _start))
}
}

function bytesToBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32 r) {
require(_bytes.length >= 0x20, "btb32");
assembly {
r := mload(add(add(_bytes, 0x20), _start))
}
}

Expand Down Expand Up @@ -139,43 +152,51 @@ library Bytes {
}

function readUInt16(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint16 r) {
bytes memory buf;
(new_offset, buf) = read(_data, _offset, 2);
r = bytesToUInt16(buf);
new_offset = _offset + 2;
r = bytesToUInt16(_data, _offset);
}

function readUInt24(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint24 r) {
bytes memory buf;
(new_offset, buf) = read(_data, _offset, 3);
r = bytesToUInt24(buf);
new_offset = _offset + 3;
r = bytesToUInt24(_data, _offset);
}

function readUInt32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint32 r) {
bytes memory buf;
(new_offset, buf) = read(_data, _offset, 4);
r = bytesToUInt32(buf);
new_offset = _offset + 4;
r = bytesToUInt32(_data, _offset);
}

function readUInt128(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint128 r) {
bytes memory buf;
(new_offset, buf) = read(_data, _offset, 16);
r = bytesToUInt128(buf);
new_offset = _offset + 16;
r = bytesToUInt128(_data, _offset);
}

function readUInt160(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint160 r) {
new_offset = _offset + 20;
r = bytesToUInt160(_data, _offset);
}

function readAddress(bytes memory _data, uint _offset) internal pure returns (uint new_offset, address r) {
bytes memory buf;
(new_offset, buf) = read(_data, _offset, 20);
r = bytesToAddress(buf);
new_offset = _offset + 20;
r = bytesToAddress(_data, _offset);
}

function readBytes20(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes20 r) {
new_offset = _offset + 20;
r = bytesToBytes20(_data, _offset);
}

function readBytes32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes32 r) {
new_offset = _offset + 32;
r = bytesToBytes32(_data, _offset);
}

// Helper function for hex conversion.
function halfByteToHex(byte _byte) internal pure returns (byte _hexByte) {
uint8 numByte = uint8(_byte);
if (numByte >= 0 && numByte <= 9) {
return byte(0x30 + numByte); // ASCII 0-9
} else if (numByte <= 15) {
return byte(0x57 + numByte); // ASCII a-f
}
require(uint8(_byte) | 0xf == 0xf, "hbh11"); // half byte's value is out of 0..15 range.

// "FEDCBA9876543210" ASCII-encoded, shifted and automatically truncated.
return byte (uint8 (0x66656463626139383736353433323130 >> (uint8 (_byte) * 8)));
}

// Convert bytes to ASCII hex representation
Expand All @@ -188,4 +209,16 @@ library Bytes {
return outStringBytes;
}

/// Trim bytes into single word
function trim(bytes memory _data, uint _new_length) internal pure returns (uint r) {
require(_new_length <= 0x20, "trm10"); // new_length is longer than word
require(_data.length >= _new_length, "trm11"); // data is to short

uint a;
assembly {
a := mload(add(_data, 0x20)) // load bytes into uint256
}

return a >> ((0x20 - _new_length) * 8);
}
}
7 changes: 5 additions & 2 deletions contracts/contracts/Config.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
pragma solidity 0.5.16;
pragma solidity ^0.5.0;


/// @title zkSync configuration constants
/// @author Matter Labs
contract Config {

/// @notice Notice period before activation preparation status of upgrade mode (in seconds)
uint constant UPGRADE_NOTICE_PERIOD = 2 weeks;
uint constant UPGRADE_NOTICE_PERIOD = 1 weeks;

/// @notice Period after the start of preparation upgrade when contract wouldn't register new priority operations (in seconds)
uint constant UPGRADE_PREPARATION_LOCK_PERIOD = 1 days;

/// @notice ERC20 token withdrawal gas limit
uint256 constant ERC20_WITHDRAWAL_GAS_LIMIT = 250000;

/// @notice zkSync address length
uint8 constant ADDRESS_BYTES = 20;

Expand Down
27 changes: 22 additions & 5 deletions contracts/contracts/Events.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
pragma solidity 0.5.16;
pragma solidity ^0.5.0;

import "./Upgradeable.sol";
import "./Operations.sol";


/// @title zkSync events
/// @author Matter Labs
contract Events {

/// @notice Event emitted when a block is committed
event BlockCommitted(uint32 indexed blockNumber);
event BlockCommit(uint32 indexed blockNumber);

/// @notice Event emitted when a block is verified
event BlockVerified(uint32 indexed blockNumber);
event BlockVerification(uint32 indexed blockNumber);

/// @notice Event emitted when user send a transaction to withdraw her funds from onchain balance
event OnchainWithdrawal(
Expand All @@ -36,7 +37,7 @@ contract Events {
);

/// @notice Event emitted when blocks are reverted
event BlocksReverted(
event BlocksRevert(
uint32 totalBlocksVerified,
uint32 totalBlocksCommitted
);
Expand All @@ -48,10 +49,26 @@ contract Events {
event NewPriorityRequest(
address sender,
uint64 serialId,
uint8 opType,
Operations.OpType opType,
bytes pubData,
uint256 expirationBlock
);

event DepositCommit(
uint32 franklinBlockId,
uint24 accountId,
address owner,
uint16 tokenId,
uint128 amount
);

event FullExitCommit(
uint32 franklinBlockId,
uint24 accountId,
address owner,
uint16 tokenId,
uint128 amount
);
}

/// @title Upgrade events
Expand Down
Loading

0 comments on commit 62e4a69

Please sign in to comment.