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

feat(zk): zksolc linking #800

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

feat(zk): zksolc linking #800

wants to merge 25 commits into from

Conversation

Karrq
Copy link
Contributor

@Karrq Karrq commented Dec 20, 2024

What 💻

  • Add functions to use zksolc --link
  • Process deploy-time linking (CREATE only)
  • Update default zksolc to 1.5.8

Why ✋

  • Allow tests & scripts to rely on contracts with libraries that have not been deployed yet

Notes 📝

There's a simple merge conflicts due to the lack of access to DualCompiledContracts during the MultiContractRunner instantiation.

This is a working yet incomplete implementation, as such there are a few quirks, in particular: unlinked factory deps are not supported (zksolc 1.5.9 should have some extra info that we can use), linking via CREATE2 is not supported either yet.

Currently there's an issue with trying to actually run the library, I believe due to a missing storage migration:

2024-12-20T21:22:57.842992Z ERROR suite{name=CounterTest}:test{kind=test name=testIncrement}:call:inspect: foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x0e93455c2327dc24ac46d3a2edade6dbb6260629 calldata="771602f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

@Karrq Karrq self-assigned this Dec 20, 2024
@Karrq Karrq requested a review from a team as a code owner December 20, 2024 21:37
crates/evm/evm/src/executors/strategy.rs Show resolved Hide resolved
crates/forge/src/multi_runner.rs Outdated Show resolved Hide resolved
crates/linking/src/lib.rs Outdated Show resolved Hide resolved
crates/linking/src/lib.rs Outdated Show resolved Hide resolved
crates/strategy/zksync/src/executor.rs Outdated Show resolved Hide resolved
crates/zksync/compilers/src/link.rs Show resolved Hide resolved
crates/zksync/compilers/src/link.rs Outdated Show resolved Hide resolved
crates/zksync/compilers/src/link.rs Outdated Show resolved Hide resolved
crates/zksync/compilers/src/link.rs Outdated Show resolved Hide resolved
crates/zksync/core/src/lib.rs Show resolved Hide resolved
crates/config/src/zksync.rs Outdated Show resolved Hide resolved
.find(|(id, _)| id.source == needle.source && id.name == needle.name)
.map(|(_, evm)| (needle, zk, evm))
})
.filter(|(_, zk, evm)| zk.bytecode.is_some() && evm.bytecode.is_some())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be more of an assertion than a filter? Is it ok to keep on executing if we are missing some of the bytecodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would simply not be added to the dual_compiled_contracts like it was before if it was unlinked (read as invalid bytecode)

Copy link
Contributor

@elfedy elfedy Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I am just worried we would filter something we should be aware it's missing (for example what happened when using zksolc previous to 1.5.7 and trying to just deserialize the eravm field to get the bytecode) and then this fails later when trying to get the bytecode and takes a bit to debug and track it is being filetred here. If this cannot happen then we are good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also some contracts which aren't meant to have bytecode like interfaces etc... Not sure the implications here tbh

crates/linking/src/lib.rs Outdated Show resolved Hide resolved
crates/linking/src/lib.rs Outdated Show resolved Hide resolved
crates/linking/src/lib.rs Outdated Show resolved Hide resolved
Karrq added 6 commits January 13, 2025 19:02
fix(strategy): remove get_mut for `DualCompiledContracts`
fix(zk:link): use version from config
refactor(zk:config): extract config -> zksolc compiler logic into
function
chore: lints
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.

3 participants