• Stars
    star
    295
  • Rank 140,902 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 2 years ago
  • Updated 26 days ago

Reviews

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

Repository Details

Fork of Foundry tailored for zkSync environment

Foundry with zkSync Era v0.1

This repository provides Foundry functionality in Solidity for compiling, deploying, testing, and interacting with smart contracts on zkSync Era.

What is foundry?

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Need help getting started with Foundry? Read the 📖 Foundry Book (WIP)!

Foundry-zkSync adds:

  • zkForge: zkSync testing framework (like Truffle, Hardhat and DappTools).
  • zkCast: Swiss army knife for interacting with zkEVM smart contracts, sending transactions and getting chain data.

Need help getting started with Foundry-zkSync? Read the 📖 Usage Guides (WIP)!

⚠️ Caution

Please note that foundry-zksync is still in its alpha stage. Some features might not be fully supported yet and may not work as intended. However, it is open-sourced, and contributions are welcome!

📊 Features & Limitations

✅ Features 🚫 Limitations
Compile smart contracts with the zksolc compiler. Can't find test/ directory
Deploy smart contracts to zkSync Era mainnet, testnet, or local test node. script command lacks zksolc support.
Bridge assets L1 <-> L2. Cheat codes are not supported.
Call deployed contracts on zkSync Era testnet or local test node. Lacks advanced testing methods (e.g., variant testing).
Send transactions to deployed contracts on zkSync Era testnet or local test node.
Simple 'PASS / FAIL' testing.

📝 Prerequisites

💾 Installation

Each tool within our suite can be installed individually, or you can install the entire suite at once.

Installing zkforge 🛠️

Run the following command:

cargo install --path ./crates/zkforge --profile local --force --locked

This installs zkforge to ~/.cargo/bin, making it available as an executable.

Installing zkcast 📡

Run the following command:

cargo install --path ./crates/zkcast --profile local --force --locked

This installs zkcast to ~/.cargo/bin, allowing it to be used as an executable.

Installing the Entire Suite 📦

To install all the tools in the suite:

cargo build --release

Quickstart

Run:

zkforge init --template https://github.com/dutterbutter/hello-foundry-zksync

Let's check out what zkforge generated for us:

$ cd hello-foundry-zksync
$ tree . -d -L 1
.
├── abis
├── broadcast
├── interfaces
├── lib
├── script
├── src
├── test

Compiling contracts

We can build the project with zkforge zkbuild:

$ zkforge zkbuild
Compiling smart contracts...
Child -> Bytecode Hash: 010000410c1f3728a3887d9bc854d978ce441ccef394319cb26c58e0ba90df46
Counter -> Bytecode Hash: 0100003bc44686be52940f3f2bd8a0feef17700663cba9edb978886c08123811
Greeter -> Bytecode Hash: 0100008f03cbc9c98bb0a883736bf9c1d8801b74928ed78148ddbd5445defddf
StepChild -> Bytecode Hash: 010000239f712c49b5804a34b1f995e034d853e2c6d2edcb60646f1bf9f057f2
Compiler run completed with warnings
TwoUserMultisig -> Bytecode Hash: 01000757a0867b6d7aba75853f126e7780bd893ae384a4718a2a03a6b53a5ee1
AAFactory -> Bytecode Hash: 0100007b76ee1ed575d19043b0b995632ac07ae996aefbbc8238f490f492c793
SimpleFactory -> Bytecode Hash: 0100021b7653e052f7f8218197d79e28de792ff243a30711fb63251644d47524
Compiled Successfully

Running Tests

You can run the tests using zkforge test.

❗Known issue of not being able to find tests in the /tests/ directory.

The command and its expected output are shown below:

$ zkforge test

Running 2 tests for Counter.sol:ContractBTest
[PASS] test_CannotSubtract43() (gas: 9223372034707517612)
[PASS] test_NumberIs42() (gas: 9223372034707517612)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 43.08ms

Running 1 test for Counter.sol:OwnerUpOnlyTest
[PASS] test_IncrementAsOwner() (gas: 9223372034707517612)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 43.46ms

Running 2 tests for Counter.sol:CounterTest
[PASS] test_Increment() (gas: 9223372034707517612)
[PASS] test_Increment_twice() (gas: 9223372034707517612)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 47.81ms

Ran 3 test suites: 5 tests passed, 0 failed, 0 skipped (5 total tests)

Configuration

Using foundry.toml

Foundry is designed to be very configurable. You can configure Foundry using a file called foundry.toml in the root of your project, or any other parent directory. See config package for all available options.

Configuration can be arbitrarily namespaced by profiles. The default profile is named default (see "Default Profile").

You can select another profile using the FOUNDRY_PROFILE environment variable. You can also override parts of your configuration using FOUNDRY_ or DAPP_ prefixed environment variables, like FOUNDRY_SRC.

zkforge init creates a basic, extendable foundry.toml file.

To see your current configuration, run zkforge config. To see only basic options (as set with zkforge init), run zkforge config --basic. This can be used to create a new foundry.toml file with zkforge config --basic > foundry.toml.

By default zkforge config shows the currently selected foundry profile and its values. It also accepts the same arguments as zkforge build.

DappTools Compatibility

You can re-use your .dapprc environment variables by running source .dapprc before using a Foundry tool.

Additional Configuration

You can find additional setup and configurations guides in the Foundry Book:

Contributing

See our contributing guidelines.

Troubleshooting

Verify arguments

Make sure that:

  • You are using zksync specific methods (zkcreate not create, zksend not send).
  • You set the correct --rpc-url.
  • You have the proper contract address - the bytecodes in zkSync Era are different to in EVM - so the resulting contracts will be deployed at different addresses.

'Method not found' when calling 'send'

If you get errors like (code: -32601, message: Method not found, data: None) - you are probably using a send method instead of zksend.

'Could not get solc: Unknown version provided', 'checksum not found'

These errors might show up on the Mac with ARM chip (M1, M2) due to the fact that most recent solc compilers are not auto-downloaded there.

There are 2 workarounds:

  • Use an older compiler by adding --use 0.8.19 flag to the zk-build command.
  • Download the compiler manually and then use the --offline mode. (Download the compiler into ~/.svm/VERSION/solc-VERSION -- for example ~/.svm/0.8.20/solc-0.8.20).

You can get the latest compiler version for MacOs AARCH here: https://github.com/ethers-rs/solc-builds/tree/master/macosx/aarch64

You might have to remove the zkout directory (that holds the compilation artifacts) and in some rare scenarios also cleanup the installed solc versions (by removing ~/.svm/ directory)

solc versions >0.8.19 are not supported, found 0.8.20

This means that our zksync compiler doesn't support that version of solidity yet.

In such case, please remove the artifacts (by removing zkout directory) and re-run with the older version of solidity (--use 0.8.19) for example.

You might also have to remove the ~/.svm/0.8.20/solc-0.8.20 file.

Acknowledgements

  • Foundry is a clean-room rewrite of the testing framework DappTools. None of this would have been possible without the DappHub team's work over the years.
  • Matthias Seitz: Created ethers-solc which is the backbone of our compilation pipeline, as well as countless contributions to ethers, in particular the abigen macros.
  • Rohit Narurkar: Created the Rust Solidity version manager svm-rs which we use to auto-detect and manage multiple Solidity versions.
  • Brock Elmore: For extending the VM's cheatcodes and implementing structured call tracing, a critical feature for debugging smart contract calls.
  • All the other contributors to the ethers-rs & foundry repositories and chatrooms.

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

l2-intro-pre-ethdenver

Introduction to layer two and zkSync
TypeScript
355
star
9

era-test-node

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

zinc

The Zinc language public repository
Rust
308
star
11

era-boojum

Boojum, the scariest SNARK implementation.
Rust
302
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