• Stars
    star
    355
  • Rank 119,764 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Introduction to layer two and zkSync

Intro to Layer 2s: buidl on the zkEVM (pre ETH Denver edition)

This repository contains all the code examples used in the "Introduction to L2s" workshop previous to ETH Denver.

🎬 Watch the recording here

Slides are available here: https://docs.google.com/presentation/d/1_zWQRjUFX5ahiBMOjnoDiMAdjJ2-ozCs593HRCwflHU/edit?usp=sharing

This repo is no longer open to contributions & PRs.

Project structure

Projects created with the zkSync-CLI have the following structure.

  • /contracts: smart contracts.
  • /deploy: deployment and contract interaction scripts.
  • /test: test files
  • hardhat.config.ts: configuration file.

Commands

  • yarn hardhat compile will compile the contracts.
  • yarn hardhat deploy-zksync --script scriptFILE.ts will execute the script from the /deploy folder (e.g yarn hardhat deploy-zksync --script deploy-greeter.ts). Requires environment variable setup.

Environment variables

In order to prevent users to leak private keys, this project includes the dotenv package which is used to load environment variables. It's used to load the wallet private key, required to run the deploy script.

To use it, rename .env.example to .env and enter your private key.

WALLET_PRIVATE_KEY=123cde574ccff....

Workshop tasks

Workshop important links

1. zkSync portal and faucets

The zkSync Portal is the easiest way to deposit and withdraw funds from zkSync. If you have GoerliETH, you can use the bridge section to deposit or withdraw funds to and from the zkSync testnet.

However, if you don't have any GoerliETH, you can receive a small amount by using our faucet, which requires you to post a tweet as a way to verify your identity.

On the other hand, here are a few other faucets that you can use to get GoerLiETH, which then you can bridge to zkSync:

2. Create a project with zksync-cli

The zkSync CLI tool is the easiest way to start developing applications and smart contracts on zkSync. You can find the documentation here.

To install it, just run sudo npm i -g zksync-cli@latest (enter your system password).

To create a new project, just run zksync-cli create NAME_OF_YOUR_PROJECT. This will create a new folder with the project name and download a sample project inside it.

Note Once created, run cd NAME_OF_YOUR_PROJECT to enter the project directory. You'll have to run the commands to compile contracts and run scripts from this folder.

The project created is very similar to any other Hardhat project, but the hardhat.config.ts file includes some zkSync-specific properties.

First, it imports a few dependencies used to compile and deploy our contracts:

import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-deploy";

Secondly, it includes the zksolc object which contains specific properties of the compiler. It comes with the minimal configuration but you can learn more about the zksolc configuration here.

zksolc: {
  version: "1.2.2",
  compilerSource: "binary",
  settings: {},
},

An last, the networks are defined with the following parameters:

  url: "https://zksync2-testnet.zksync.dev",
  ethNetwork: "goerli",
  zksync: true,

The url and ethNetwork are the RPC endpoints of the L2 and L1 and the zksync flag is used to indicate Hardhat if it should use the zksync compiler and deployment plugins.

Note With "goerli", the project will use the default providers from ethers, but you can change that for an RPC endpoint from

3. Deploy and verify the Greeter contract

The zkSync-CLI sample project includes a Greeter contract and a deploy script. The Greeter contract stores a message on chain which can be retrieved by calling the read method greet() and can be updated by calling the method setGreeting(_message).

To compile the contract, run yarn hardhat compile. You'll notice that the folders artifacts-zk and cache-zk will be created with the compiled artifact.

To deploy the contract, just set your wallet's private key in the .env file (you'll have to rename it first), and run the command yarn hardhat deploy-zksync --script deploy-greeter.ts.

To verify the contract you can use the zkSync Explorer. You'll have to select the solidity and zksolc compiler versions to match the ones from the hardhat.config.ts file and also enter the constructor params, which are printed in the terminal by the deploy-greeter.ts script.

Note Make sure you've configured your private key in the .env file as described above.

4. Create and deploy an ERC20 contract

To showcase the compatibility with the standard token contract, we'll use the OpenZeppeling contract wizard to create an ERC20 contract.

We'll choose an ERC20, Burnable, Pausable and Snapshot. We can copy the contract code and the contract and put it in the contracts folder as is (check out file zkToken.sol).

As this contract uses some dependencies from OpenZeppelin, we'll have to install them with yarn add -D @openzeppelin/contracts.

To compile the contract, just run yarn hardhat compile again.

  • The included deploy-erc20.ts script will deploy this contract.
  • The included use-erc20.ts script will do a transfer of tokens between two accounts and return its balances.

Note To verify contracts that include imports of other contracts and libraries (like Openzeppelin contracts πŸ˜‰), you'd need to flatten it first! Learn more about flattening contracts in our docs

5. Create and deploy an ERC721 contract

To showcase the compatibility with the standard NFT token, we'll use the OpenZeppeling contract wizard to create an ERC721 contract.

We'll select the following options: Mintable (with auto increments), Burnable, Enumerable and enter a Base URI. We can copy this contract into the /contracts folder (check out file zkNFT.sol).

To compile the contract, just run yarn hardhat compile again.

  • The included deploy-erc721.ts script will deploy this contract.
  • The included use-erc721.ts script will mint a new NFT and return the total supply and balance.

Official Links

More Repositories

1

awesome-zero-knowledge-proofs

A curated list of awesome things related to learning Zero-Knowledge Proofs (ZKP).
5,253
star
2

zksync

zkSync: trustless scaling and privacy engine for Ethereum
Rust
4,883
star
3

zksync-era

zkSync era
Rust
3,084
star
4

zksync-web-era-docs

zkSync Era Documentation
JavaScript
982
star
5

zksync-lite-docs

zkSync Lite documentation
Shell
773
star
6

zksync-wallet-vue

zkSync Lite web wallet
Vue
517
star
7

era-contracts

Smart Contract Submodule For zkSync Era
Solidity
481
star
8

era-test-node

In-memory node that can be used for integration testing and debugging.
Rust
308
star
9

zinc

The Zinc language public repository
Rust
308
star
10

era-boojum

Boojum, the scariest SNARK implementation.
Rust
302
star
11

foundry-zksync

Fork of Foundry tailored for zkSync environment
Rust
295
star
12

hardhat-zksync

TypeScript
281
star
13

era-sync_vm

Circuit Implementation of zkVM for zkSync Era
Rust
278
star
14

era-system-contracts

Implementation of the system contracts
Solidity
201
star
15

zksync-cli

CLI tool that simplifies ZKsync development
TypeScript
163
star
16

era-tutorial-examples

[DEPRECATED ]Full examples for tutorials in the zkSync Era documentation. Visit: https://github.com/matter-labs/tutorials
TypeScript
129
star
17

zksync-dapp-checkout

zkCheckout β€” trustable permissionless DeFi payment gateway. Fast & cheap transfers / simple & quick withdrawal
Vue
124
star
18

block-explorer

zkSync Era Block Explorer
TypeScript
123
star
19

franklin-crypto

Rust
115
star
20

paymaster-examples

Ready to use paymaster contracts for zkSync Era
TypeScript
110
star
21

era-zk_evm

Out-of-circuit zkEVM implementation
Rust
81
star
22

hodor

Open source implementation of zkSTARKs in pure Rust
Rust
79
star
23

era-bellman-cuda

A library implementing GPU-accelerated cryptographic functionality for the zkSync prover
Cuda
71
star
24

eip1962

EIP1962 implementation effort
Rust
65
star
25

local-setup

zkSync 2.0 setup for local development
Shell
64
star
26

v2-testnet-contracts

Solidity
63
star
27

era-compiler-solidity

Solidity compiler for ZKsync
Rust
62
star
28

zksync-hardhat-template

[DEPRECATED] Template project for zksync-hardhat
TypeScript
62
star
29

era-consensus

Consensus layer implementation for zkSync Era
Rust
62
star
30

era-zkevm_circuits

Rust
59
star
31

era-zkevm_test_harness

Compare in-circuit and out-of-circuit VMs
Rust
59
star
32

zksolc-bin

Releases of the Solidity compiler for ZKsync
55
star
33

zksync-withdrawal-finalizer

zkSync 2.0 Withdrawal Finalizer
Rust
54
star
34

zk_os

OS for next iteration of the world computer
Rust
45
star
35

tutorials

TypeScript
43
star
36

rescue-poseidon

Rescue and Poseidon hash function implementations
Rust
42
star
37

zksync-link

PayNow - Create payment links, get paid in tokens
Svelte
41
star
38

curve-zinc

The Curve Stableswap smart contract implementation in Zinc v0.2.2.
Rust
40
star
39

solidity_plonk_verifier

Solidity verifier for Plonk
Solidity
38
star
40

era-zkevm_opcode_defs

Definitions of zkEVM opcodes (primary dependency for all other repos)
Rust
38
star
41

recursive_aggregation_circuit

Kate commitment based PLONK recursive aggregation circuit
Solidity
38
star
42

era-compiler-vyper

Vyper compiler for ZKsync
Rust
37
star
43

zksync-contract-templates

Contract Templates for zkSync: solidity, hardhat, vyper
TypeScript
32
star
44

era-compiler-llvm

ZKsync fork of the LLVM framework.
C++
31
star
45

schnorr-musig

Simple Schnorr Multi-Signatures
Rust
28
star
46

custom-aa-tutorial

A full example for the tutorial on custom AA
Solidity
28
star
47

zkSync-account-abstraction-template

28
star
48

era-shivini

A library implementing GPU-accelerated zkSync prover.
Rust
27
star
49

zkvyper-bin

Releases of the Vyper compiler for ZKsync
27
star
50

cross-chain-tutorial

TypeScript
27
star
51

hackathon-winner-projects

A list of all the projects submitted in all zksync hackathons.
25
star
52

era-boojum-cuda

A library implementing GPU-accelerated cryptographic functionality for the zkSync prover.
Rust
25
star
53

era-heavy-ops-service

Specialized GPU Prover for zkSync Era
Rust
24
star
54

vm2

High performance EraVM for zkSync.
Rust
22
star
55

compiler-solidity

The zkEVM Solidity compiler.
Rust
22
star
56

era-boojum-validator-cli

Rust
21
star
57

risc_v_simulator

Rust
20
star
58

custom-paymaster-tutorial

Full example for the custom paymaster tutorial in the documentation
TypeScript
20
star
59

zksync-web-landing

zkSync.io landing page
CSS
20
star
60

era-zkevm_tester

Adapter between zk_evm and era-compiler-tester
Rust
19
star
61

era-compiler-llvm-context

Shared front-end code of the ZKsync compilers
Rust
19
star
62

z-prize-msm-gpu

Submission for https://www.zprize.io/prizes/accelerating-msm-operations-on-gpu-fpga
Cuda
19
star
63

era-compiler-tests

Collection of tests for ZKsync compilers
Solidity
17
star
64

era-compiler-tester

Integration testing framework for ZKsync compilers
Rust
17
star
65

z-prize-msm-gpu-combined

Combined solution from Matter Labs and Yrrid based on their respective submissions for the Z-Prize category Accelerating MSM Operations on GPU/FPGA
Cuda
15
star
66

eravm-spec

Coq
15
star
67

zksync-crypto

Cryptography libraries for ZKsync
Rust
14
star
68

teepot

Key Value store in a TEE with Remote Attestation for Authentication
Rust
13
star
69

era-compiler-llvm-builder

ZKsync LLVM framework builder
Rust
12
star
70

compiler-llvm

The zkEVM fork of the LLVM framework
12
star
71

zksync-packages-info

Information about the different packages and SDKs by MatterLabs to interact with zkSync Era
Vue
12
star
72

.github

zkSync Frontend Team workflow configuration
12
star
73

era-solidity

ZKsync fork of the original Solidity compiler
C++
12
star
74

era-hardhat-with-plugins

A zkSync Hardhat project configured with multiple plugins to improve the developer experience
TypeScript
11
star
75

era-revm

revm (Rust Ethereum VM) translation for Era / zkEVM
Rust
11
star
76

zksync-frontend-templates

Frontend Templates for ZKsync: vue, react, next, wagmi
TypeScript
10
star
77

ETHLisbon-2022-hackathon

Information about MatterLabs bounty program for ETH Lisbon 2022 hackathon
TypeScript
10
star
78

era-zkEVM-assembly

The zkEVM assembly tools
Rust
10
star
79

aa-signature-checker

TypeScript
9
star
80

era-zk_evm_abstractions

Rust
9
star
81

zksync-v2-issues

Report issues encountered when using the zkSync 2.0 testnet.
9
star
82

vault-auth-tee

Hashicorp Vault plugin for authenticating Trusted Execution Environments (TEE) like SGX enclaves
Go
9
star
83

proof_system_info_v1.0

Information about proof system used in zkSync v1.0
8
star
84

zksync-hardhat-ft-template

Template for a fungible token project on zkSync Era
TypeScript
8
star
85

vise

Tools to define and export metrics in Rust libraries and apps
Rust
8
star
86

l2-intro-ethdenver

Introduction to layer 2 protocols and smart contract examples on zkSync for ETH Denver
Vue
8
star
87

nixsgx

Reproducible Nix packages for TEEs
Nix
8
star
88

eip1962_specs

Specification documents for EIP1962
7
star
89

compiler-infra

Docker images with build tools for compiler repos.
Dockerfile
7
star
90

era-compiler-common

Shared constants of the ZKSync compilers
Rust
7
star
91

demo-circuit

Rust
7
star
92

zkcli-block-explorer

zkSync Block Explorer module for zkcli
TypeScript
7
star
93

zksync-hardhat-vyper-template

[DEPRECATED] Template project for zksync-cli. Includes a Vyper smart contract, tests and script to deploy to zkSync Era
TypeScript
7
star
94

compiler-tests

The compiler tests collection
Solidity
6
star
95

ansible-en-role

Ansible role for zkSync Era External Node
Jinja
6
star
96

zksync-dapp-forced-exit

CSS
6
star
97

simple-oracle-benchmarking

Deploy a simplified oracle, track gas usage.
TypeScript
6
star
98

zksync-crypto-gpu

GPU-acceselerated cryptography libraries for ZKsync
Rust
6
star
99

zksync-docs

Developer documentation site for zkSync community.
Vue
5
star
100

hyperchain-da

Common clients and contracts for DA solutions for zkSync hyperchains.
Rust
5
star