Giter Site home page Giter Site logo

cunancunin / foundry-zksync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matter-labs/foundry-zksync

0.0 0.0 0.0 20.13 MB

Fork of Foundry tailored for zkSync environmentg

License: Apache License 2.0

Shell 0.30% Rust 97.17% Dockerfile 0.03% Solidity 2.50%

foundry-zksync's Introduction

Foundry with zkSync Era v0.1-alpha

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 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

Foundry-zksync offers a set of features designed to work with zkSync Era, providing a comprehensive toolkit for smart contract deployment and interaction:

  • Smart Contract Deployment: Easily deploy smart contracts to zkSync Era mainnet, testnet, or a local test node.
  • Asset Bridging: Bridge assets between L1 and L2, facilitating seamless transactions across layers.
  • Contract Interaction: Call and send transactions to deployed contracts on zkSync Era testnet or local test node.
  • Solidity Testing: Write tests in Solidity, similar to DappTools, for a familiar testing environment.
  • Fuzz Testing: Benefit from fuzz testing, complete with shrinking of inputs and printing of counter-examples.
  • Remote RPC Forking: Utilize remote RPC forking mode, leveraging Rust's asynchronous infrastructure like tokio.
  • Flexible Debug Logging: Choose your debugging style:
    • DappTools-style: Utilize DsTest's emitted logs for debugging.
    • Hardhat-style: Leverage the popular console.sol contract.
  • Configurable Compiler Options: Tailor compiler settings to your needs, including LLVM optimization modes.

Limitations

While foundry-zksync is alpha stage, there are some limitations to be aware of:

  • Cheat Codes Support: Not all cheat codes are fully supported. View the list of supported cheat codes.

  • Compile Time: Some users may experience slower compile times.

  • Compiling Libraries: Compiling non-inlinable libraries requires deployment and adding to configuration. For more information please refer to official docs.

    libraries = [
        "src/MyLibrary.sol:MyLibrary:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4"
    ]
    
  • Create2 Address Derivation: There are differences in Create2 Address derivation compared to Ethereum. Read the details.

  • Specific Foundry Features: Currently features such as --gas-report may not work as intended. We are actively working on providing support for these feature types.

For the most effective use of our library, we recommend familiarizing yourself with these features and limitations.

๐Ÿ“ Prerequisites

  • Install Rust with the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

The current implementation makes use of nightly-2023-09-30. Please be sure to have the proper toolchain installed:

# rustup install nightly-2023-09-30-<YOUR-TARGET>
rustup install nightly-2023-09-30-aarch64-apple-darwin

๐Ÿ’พ 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 hello_foundry

Let's check out what zkforge generated for us:

$ cd hello_foundry
$ 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...
Compiled Successfully

Running Tests

You can run the tests using zkforge test.

The command and its expected output are shown below:

$ zkforge test

Running 2 tests for Counter.t.sol:CounterTest
[PASS] testFuzz_SetNumber(uint256) (runs: 256, ฮผ: 9223372034707527035, ~: 9223372034707527076)
[PASS] test_Increment() (gas: 9223372034707527339)
Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 5.15s

Ran 1 test suites: 2 tests passed, 0 failed, 0 skipped (2 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. An example foundry.toml for zkSync with zksolc configurations may look like:

[profile.default]
src = 'src'
out = 'out'
libs = ['lib']

[profile.zksync]
src = 'src'
libs = ['lib']
fallback_oz = true
mode = "3"

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.

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.

Acknowledgments - foundry-zksync

foundry-zksync's People

Contributors

aon avatar bernard-wagner avatar brockelmore avatar calldata avatar ckoopmann avatar danipopes avatar devanoneth avatar dutterbutter avatar evalir avatar gakonst avatar github-actions[bot] avatar ifrostizz avatar joshiedo avatar jpopesculian avatar mattsse avatar mds1 avatar meetmangukiya avatar nbaztec avatar ncitron avatar ngotchac avatar odyslam avatar onbjerg avatar paulrberg avatar psushi avatar rkrasiuk avatar shawnharmsen avatar shekhirin avatar tarrencev avatar transmissions11 avatar tynes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.