Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a section which is setting missing libraries for build and test #107

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 2 additions & 48 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ yarn build
# Install foundry-zksync, please follow this URL
https://foundry-book.zksync.io/getting-started/installation

# Install era-test-node
https://github.com/matter-labs/era-test-node
```

Next, you should uncomment the following lines in `foundry.toml`.
Expand All @@ -246,50 +244,6 @@ Partial comment-out files can be found the following. Please uncomment them.
- src/utils/ZKSyncCreate2Factory.sol
- test/helpers/DeploymentHelper.sol

Run the era-test-node forking zksync sepolia

```
era_test_node fork https://sepolia.era.zksync.dev
```

At the first forge build, you need to detect the missing libraries.

```
forge build --zksync --zk-detect-missing-libraries
```

As you saw before, you need to deploy missing libraries.
You can deploy them by the following command for example.

```
$ forge build --zksync --zk-detect-missing-libraries
Missing libraries detected: src/libraries/CommandUtils.sol:CommandUtils, src/libraries/DecimalUtils.sol:DecimalUtils, src/libraries/StringUtils.sol:StringUtils
```

Run the following command in order to deploy each missing libraries:

```
export PRIVATE_KEY={YOUR_PRIVATE_KEY}
export RPC_URL=http://127.0.0.1:8011
export CHAIN_ID=260

forge create src/libraries/DecimalUtils.sol:DecimalUtils --private-key $PRIVATE_KEY --rpc-url $RPC_URL --chain $CHAIN_ID --zksync
forge create src/libraries/CommandUtils.sol:CommandUtils --private-key $PRIVATE_KEY --rpc-url $RPC_URL --chain $CHAIN_ID --zksync --libraries src/libraries/DecimalUtils.sol:DecimalUtils:{DECIMAL_UTILS_ADDRESS_YOU_DEPLOYED}
forge create src/libraries/StringUtils.sol:StringUtils --private-key $PRIVATE_KEY --rpc-url $RPC_URL --chain $CHAIN_ID --zksync
```

After that, you can see the following lines in the foundry.toml. Please replace `{PROJECT_DIR}` and `{DEPLOYED_ADDRESS}`.
Also, this lines are needed only for foundry-zksync, if you use normal foundry commands, please comment out.


```
libraries = [
"{PROJECT_DIR}/packages/contracts/src/libraries/DecimalUtils.sol:DecimalUtils:{DEPLOYED_ADDRESS}",
"{PROJECT_DIR}/packages/contracts/src/libraries/CommandUtils.sol:CommandUtils:{DEPLOYED_ADDRESS}"
"{PROJECT_DIR}/packages/contracts/src/libraries/StringUtils.sol:StringUtils:{DEPLOYED_ADDRESS}"
]
```

About Create2, `L2ContractHelper.computeCreate2Address` should be used.
`type(ERC1967Proxy).creationCode` doesn't work correctly in ZKsync.
We need to use the bytecode hash intead of `type(ERC1967Proxy).creationCode`.
Expand All @@ -298,7 +252,7 @@ Perhaps that is a different value in each compiler version and library addresses
Run the following commands, you'll get the bytecode hash.

```
forge test --match-test "testComputeCreate2Address" --no-match-contract ".*Script.*" --system-mode=true --zksync --gas-limit 1000000000 --chain 300 -vvv --fork-url http://127.0.0.1:8011
forge test --match-test "testComputeCreate2Address" --no-match-contract ".*Script.*" --system-mode=true --zksync --gas-limit 1000000000 --chain 300 -vvv
```

And then, you should replace `{YOUR_BYTECODE_HASH}` in the .env
Expand Down Expand Up @@ -352,7 +306,7 @@ libraries = [
Run this command again, you'll get the bytecode hash.

```
forge test --match-test "testComputeCreate2Address" --no-match-contract ".*Script.*" --system-mode=true --zksync --gas-limit 1000000000 --chain 300 -vvv --fork-url http://127.0.0.1:8011
forge test --match-test "testComputeCreate2Address" --no-match-contract ".*Script.*" --system-mode=true --zksync --gas-limit 1000000000 --chain 300 -vvv
```

And then, you should replace `{YOUR_BYTECODE_HASH}` in the .env
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ast = true
build_info = true
extra_output = ["storageLayout"]

# For missing libraries, please comment out following line and replace some placeholders if you use foundry-zksync
# For missing libraries, please comment out following line and replace some placeholders if you deploy to zksync with foundry-zksync
#libraries = [
# "{PROJECT_DIR}/packages/contracts/src/libraries/DecimalUtils.sol:DecimalUtils:{DEPLOYED_ADDRESS}",
# "{PROJECT_DIR}/packages/contracts/src/libraries/CommandUtils.sol:CommandUtils:{DEPLOYED_ADDRESS}",
Expand Down
Loading