• Stars
    star
    322
  • Rank 126,085 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 1 year ago
  • Updated 5 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).
4,894
star
2

zksync

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

zksync-era

zkSync era
Rust
2,841
star
4

zksync-web-era-docs

zkSync Era Documentation
JavaScript
908
star
5

zksync-lite-docs

zkSync documentation
Shell
739
star
6

zksync-wallet-vue

zkSync web wallet
Vue
498
star
7

era-contracts

Smart Contract Submodule For zkSync Era
Solidity
421
star
8

era-test-node

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

zinc

The Zinc language public repository
Rust
307
star
10

hardhat-zksync

TypeScript
269
star
11

era-boojum

Boojum, the scariest SNARK implementation.
Rust
264
star
12

era-sync_vm

Circuit Implementation of zkVM for zkSync Era
Rust
252
star
13

foundry-zksync

Fork of Foundry tailored for zkSync environment
Rust
217
star
14

era-system-contracts

Implementation of the system contracts
Solidity
201
star
15

zksync-cli

CLI tool that simplifies zkSync development
TypeScript
130
star
16

era-tutorial-examples

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

zksync-dapp-checkout

zkCheckout β€” trustable permissionless DeFi payment gateway. Brand new zkSync dApp w/t all L2 perks: fast&cheap transfers / simple&quick withdrawal
Vue
115
star
18

block-explorer

zkSync Era Block Explorer
TypeScript
106
star
19

paymaster-examples

Ready to use paymaster contracts for zkSync Era
TypeScript
93
star
20

hodor

Open source implementation of zkSTARKs in pure Rust
Rust
74
star
21

eip1962

EIP1962 implementation effort
Rust
65
star
22

era-bellman-cuda

A library implementing GPU-accelerated cryptographic functionality for the zkSync prover
Cuda
64
star
23

franklin-crypto

Rust
63
star
24

v2-testnet-contracts

Solidity
60
star
25

zksync-hardhat-template

[DEPRECATED] Template project for zksync-hardhat
TypeScript
60
star
26

era-zk_evm

Out-of-circuit zkEVM implementation
Rust
58
star
27

era-compiler-solidity

EraVM Solidity compiler.
Rust
47
star
28

local-setup

zkSync 2.0 setup for local development
Shell
46
star
29

zksolc-bin

This repository contains current and historical builds of the zkEVM Solidity Compiler.
45
star
30

era-consensus

Consensus layer implementation for zkSync Era
Rust
44
star
31

era-zkevm_test_harness

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

zksync-link

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

zk_os

OS for next iteration of the world computer
Rust
40
star
34

era-zkevm_circuits

Rust
39
star
35

curve-zinc

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

solidity_plonk_verifier

Solidity verifier for Plonk
Solidity
38
star
37

rescue-poseidon

Rescue and Poseidon hash function implementations
Rust
38
star
38

recursive_aggregation_circuit

Kate commitment based PLONK recursive aggregation circuit
Solidity
38
star
39

zksync-withdrawal-finalizer

zkSync 2.0 Withdrawal Finalizer
Rust
38
star
40

tutorials

TypeScript
34
star
41

era-zkevm_opcode_defs

Definitions of zkEVM opcodes (primary dependency for all other repos)
Rust
31
star
42

era-compiler-vyper

EraVM Vyper compiler.
Rust
28
star
43

zkSync-account-abstraction-template

27
star
44

schnorr-musig

Simple Schnorr Multi-Signatures
Rust
26
star
45

custom-aa-tutorial

A full example for the tutorial on custom AA
Solidity
25
star
46

cross-chain-tutorial

TypeScript
24
star
47

era-boojum-cuda

A library implementing GPU-accelerated cryptographic functionality for the zkSync prover.
Rust
24
star
48

era-shivini

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

compiler-solidity

The zkEVM Solidity compiler.
Rust
22
star
50

zkvyper-bin

This repository contains current and historical builds of the zkEVM Vyper Compiler.
22
star
51

era-heavy-ops-service

Specialized GPU Prover for zkSync Era
Rust
22
star
52

hackathon-winner-projects

A list of all the projects submitted in all zksync hackathons.
20
star
53

zksync-web-landing

zkSync.io landing page
CSS
20
star
54

era-boojum-validator-cli

Rust
19
star
55

risc_v_simulator

Rust
18
star
56

custom-paymaster-tutorial

Full example for the custom paymaster tutorial in the documentation
TypeScript
18
star
57

z-prize-msm-gpu

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

era-zkevm_tester

Assembly runner for zkEVM testing
Rust
16
star
59

era-compiler-llvm

The zkEVM fork of the LLVM framework
16
star
60

era-compiler-llvm-context

Shared front end code of the EraVM compilers.
Rust
14
star
61

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
14
star
62

compiler-llvm

The zkEVM fork of the LLVM framework
13
star
63

era-compiler-tests

The collection of tests for the compilers for zkEVM
Solidity
11
star
64

era-revm

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

era-zkEVM-assembly

The zkEVM assembly tools
Rust
10
star
66

zksync-contract-templates

Contract Templates for zkSync: solidity, hardhat, vyper
TypeScript
10
star
67

vault-auth-tee

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

ETHLisbon-2022-hackathon

Information about MatterLabs bounty program for ETH Lisbon 2022 hackathon
TypeScript
9
star
69

era-hardhat-with-plugins

A zkSync Hardhat project configured with multiple plugins to improve the developer experience
TypeScript
9
star
70

era-compiler-tester

The ZKsync compiler integration testing framework.
Rust
9
star
71

zksync-packages-info

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

.github

zkSync Frontend Team workflow configuration
9
star
73

eravm-spec

Coq
9
star
74

proof_system_info_v1.0

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

zksync-v2-issues

Report issues encountered when using the zkSync 2.0 testnet.
8
star
76

zksync-hardhat-vyper-template

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

aa-signature-checker

TypeScript
7
star
78

era-compiler-llvm-builder

EraVM LLVM Framework Builder.
Rust
7
star
79

compiler-infra

Docker images with build tools for compiler repos
Dockerfile
7
star
80

vise

Tools to define and export metrics in Rust libraries and apps
Rust
7
star
81

l2-intro-ethdenver

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

demo-circuit

Rust
7
star
83

eip1962_specs

Specification documents for EIP1962
6
star
84

compiler-tests

The compiler tests collection
Solidity
6
star
85

era-fee-withdrawer

TypeScript
6
star
86

zkcli-block-explorer

zkSync Block Explorer module for zkcli
TypeScript
6
star
87

zksync-hardhat-ft-template

Template for a fungible token project on zkSync Era
TypeScript
5
star
88

teepot

Key Value store in a TEE with Remote Attestation for Authentication
Rust
5
star
89

era-zk_evm_abstractions

Rust
5
star
90

multisig

JavaScript
5
star
91

era-compiler-common

Shared constants of the compilers for EraVM.
Rust
5
star
92

zksync-dapp-forced-exit

CSS
5
star
93

simple-oracle-benchmarking

Deploy a simplified oracle, track gas usage.
TypeScript
5
star
94

era-solidity

Solidity compiler and language tuned for EraVM
C++
5
star
95

gated-nft-tutorial

TypeScript
4
star
96

l2-intro-demo

Introduction to layer 2 protocols and smart contract examples on zkSync
TypeScript
4
star
97

greeter-tutorial-starter

Vue
4
star
98

gated-nft-tutorial-starter

TypeScript
4
star
99

zksync-tool-locker

Vue
3
star
100

zinc.github.io

The Zinc circuit book, which corresponds to the version 0.1 of the Zinc language.
HTML
3
star