This repository demonstrates how to compute and deploy contracts using create2
on ZKsync and compares it to traditional EVM-based chains. It provides tests for deploying smart contracts using create2
on both ZKsync and EVM, allowing you to observe the differences between the two implementations.
Ensure that you have foundry-zksync
installed. Follow the installation instructions in the Foundry-zksync repository.
To get started with this repository, follow the steps below:
git clone git@github.com:dutterbutter/min-zksync-create2.git
Navigate into the project directory:
cd min-zksync-create2
Install the necessary dependencies using forge
:
forge install
To build the project for ZKsync, run:
forge build --zksync
You may encounter a compilation error due to a placeholder value in the system contracts library.
To fix the compilation error, navigate to the Constants.sol
file in the era-contracts
library and replace the placeholder value with the actual system contract offset value:
-
File:
lib/era-contracts/system-contracts/contracts/Constants.sol:20:44
-
Change:
uint160 constant SYSTEM_CONTRACTS_OFFSET = {{SYSTEM_CONTRACTS_OFFSET}}; // 2^15
- To:
uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000; // 2^15
After fixing the compilation error, you can run the tests for both zkSync and EVM-based chains to observe the differences.
To run the tests on ZKsync, use the following command:
forge test --match-path test/Create2ZK.t.sol --zksync --enable-eravm-extensions -vvvv
To run the tests on an EVM-based chain, use the following command:
forge test --match-path test/Create2Test.t.sol -vvv