Skip to content

Comments

fix: function is_foundry_zksync#43

Open
Imod7 wants to merge 1 commit intoCyfrin:mainfrom
Imod7:domi-fix-is-foundry-zksync
Open

fix: function is_foundry_zksync#43
Imod7 wants to merge 1 commit intoCyfrin:mainfrom
Imod7:domi-fix-is-foundry-zksync

Conversation

@Imod7
Copy link

@Imod7 Imod7 commented Sep 3, 2025

Issue

The function is_foundry_zksync does not recognise if the system has Foundry Base Installation or Foundry zkSync installed. It will always return

This is Vanilla Foundry

Steps to reproduce the issue

From Course : Foundry Fundamentals > Lesson 25 - Zksync Devops
Project: foundry-fund-me-cu
Test File: test/unit/ZkSyncDevOps.t.sol
Note: Have ffi = true in the foundry.toml
Run first

foundryup-zksync

and then

forge test --mt testZkSyncFoundryFails -vvvv

Root Cause

The command

forge --version

that it's being run in these lines of code

function is_foundry_zksync() public returns (bool) {
	string[] memory forgeVersionCommand = new string[](2);
	forgeVersionCommand[0] = "forge";
	forgeVersionCommand[1] = "--version";
	bytes memory retData = vm.ffi(forgeVersionCommand);

in the Foundry Base installation it returns

forge Version: 1.3.2-stable

and in Foundry zkSync installation it returns

forge Version: 1.3.0-foundry-zksync-v0.0.26

With the following checks in that function, only the first part of the returned string is checked which is the version (forge Version: 1.) and it is the same in both cases (Foundry Base Installation and Foundry zkSync Installation).

So when the code arrives at this check, it only checks for the version of the installation hence this if statement will be fulfilled and the code will go in the corresponding statements which is the following

	console2.log("This is Vanilla Foundry");
	return false;

Suggested Solution

After running the command

forge --version

check if the returned string contains the substring zksync. If yes, return the corresponding msg and boolean value.

Notes

Note 1

I am not sure if the checks of specific versions are necessary. If we just add 2 more checks after the suggested solution, e.g.

// If it contains standard foundry indicators, it's vanilla
if (_containsSubstring(lowerVersion, bytes("forge"))) {
	console2.log("This is Vanilla Foundry");
	return false;
}

console2.log("Unknown forge version");
revert FoundryZkSyncChecker__UnknownFoundryVersion();

we could remove all the rest of the checks.

Note 2

I do not understand why skipZkSync modifier uses another function isZkSyncChain and then another function isOnZkSyncChainId to again determine if we are on zkSync or not. We could use the same function.

Additional changes

Change 1

Replaced

console2.log("Got forge version:", forgePrefixedStr);

which results in

Got forge version:", "forge Version: 1.

with

console2.log("Got forge version:", forgeVersionStr);

which results in

Got forge version:", "forge Version: 1.3.0-foundry-zksync-v0.0.26

which looks more like what I would expect to see in the forge version.

Change 2

Replaced the natspec of the function is_foundry_zksync since it does not return the current version of foundry. It returns if the Foundry installation is the base one or the zksync one.

Testing

  • git clone foundry-devops
  • checkout in my branch
  • git clone also foundry-fund-me-cu in a separate folder
    • edit the unti/test/ZkSyncDevOps.t.sol file and change the import of FoundryZkSyncChecker to point to the cloned repo (previous step) of foundry-devops (use the absolute path)
    • enable ffi = true in your foundry.toml

In your foundry-fund-me-cu folder:

Foundry-zkSync

  • Run foundryup-zksync
  • When you run forge --version, it should return something similar to forge Version: 1.3.0-foundry-zksync-v0.0.26
  • Uncomment the test testZkSyncFoundryFails and run forge test --mt testZkSyncFoundryFails -vvvv
  • it should pass (because zkSync now supports keyExistsJson) and returns This is Foundry ZkSync

Foundry

  • Run foundryup
  • When you run forge --version, it should return something similar to forge Version: 1.3.2-stable
  • Run again the test forge test --mt testZkSyncFoundryFails -vvvv
  • It should returns This is Vanilla Foundry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant