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

fix(zk): properly mark unlinked contract #40

Merged
merged 4 commits into from
Nov 8, 2024
Merged

Conversation

Karrq
Copy link

@Karrq Karrq commented Nov 7, 2024

With this PR we can now properly detect when a contract is unlinked, mark it as such and track the missing libraries associated with the unlinked bytecode.

Changes:

  • switch from evm to eravm object in json output
  • remove methodIdentifiers
  • deserialize missingLibraries and store it next to the unlinked bytecode

Copy link

@elfedy elfedy left a comment

Choose a reason for hiding this comment

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

Unless I am missing something on why it is done this way, I think we should consider separating compiler outputs from the artifacts we use and not join them into one, hiding the conversion inside the deserialization. The abstractions for this are there already:

  1. We deserialize Contract that has a Bytecode and we respect the output fields (no ad hoc deserialization logic).
  2. We have ZkContractArtifact with ZkArtifactBytecode that contains the missing_libraries (if we need them there for some reason) and that is constucted on the zksync_contract_to_artifact_function

crates/artifacts/zksolc/src/bytecode.rs Outdated Show resolved Hide resolved
}

// NOTE: distinction between bytecode and deployed bytecode make no sense of zkEvm, but
// we implement these conversions in order to be able to use the Artifacts trait.
impl From<Bytecode> for CompactBytecode {
fn from(bcode: Bytecode) -> Self {
Self { object: bcode.object, source_map: None, link_references: BTreeMap::default() }
let link_references = bcode.link_references();
Self { object: bcode.object, source_map: None, link_references }
Copy link

Choose a reason for hiding this comment

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

We need to be careful now because bytecode and deployed bytecode will NOT be the same thing as bytecode might be an unlinked and link_references has meaningful info . Maybe update the NOTE above.
Also is having this conversion the reason why you need missing_libraries in the Bytecode struct

Copy link
Author

Choose a reason for hiding this comment

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

in EraVM they still are the same thing, not sure why the unlinked means it's different

Copy link

Choose a reason for hiding this comment

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

CompactBytecode will have the link references for the bytecode CompactDeployedBytecode will not. Previously we only cared about the bytecode field and could use both interchangebly. It may not be the case now if we used the linked_references somewhere we need CompactBytecode

crates/artifacts/zksolc/src/contract.rs Outdated Show resolved Hide resolved
crates/artifacts/zksolc/src/lib.rs Show resolved Hide resolved
crates/artifacts/zksolc/src/serde_helpers.rs Outdated Show resolved Hide resolved
crates/artifacts/zksolc/src/serde_helpers.rs Outdated Show resolved Hide resolved
fix: remove serde logic in favor of keeping artifact and compiler format separate
@Karrq Karrq requested a review from elfedy November 7, 2024 14:42
crates/artifacts/zksolc/src/contract.rs Outdated Show resolved Hide resolved
Copy link

@elfedy elfedy left a comment

Choose a reason for hiding this comment

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

LGTM, ci is not passing though, I think it is due to outdated compiler tests.

crates/compilers/src/compilers/zksolc/mod.rs Outdated Show resolved Hide resolved
crates/compilers/src/compilers/zksolc/mod.rs Outdated Show resolved Hide resolved
crates/compilers/src/zksync/artifact_output/zk.rs Outdated Show resolved Hide resolved
crates/compilers/src/zksync/artifact_output/zk/bytecode.rs Outdated Show resolved Hide resolved
@Karrq Karrq merged commit 9f99284 into zksync-v0.11.6 Nov 8, 2024
4 checks passed
@Karrq Karrq deleted the zksolc-link branch November 8, 2024 12:40
Karrq added a commit that referenced this pull request Nov 26, 2024
feat(zk): mark bytecode as unlinked
refactor(zk): get output from `eravm` object
feat: retain pre-1.5.7 zksolc compatibility
test(artifact:zk): unprefixed bytecode test
Karrq added a commit that referenced this pull request Nov 26, 2024
* feat: add zksolc support

* fix: codeowner change (#32,#34)

* feat: zksolc v1.5.7 support (#35)

* feat: zksolc 1.5.7 support

* chore: update version constants

* feat: Support error / warning suppression in zksolc (#33)

feat: add FromStr to ZkSolcWarnings and ZkSolcErrors (#37)

* fix: add back skip filter over avoid-contracts

* feat(zk): properly mark unlinked contract (#40,#41,#43,#44)

feat(zk): mark bytecode as unlinked
refactor(zk): get output from `eravm` object
feat: retain pre-1.5.7 zksolc compatibility
test(artifact:zk): unprefixed bytecode test

* chore: bump version

* chore: merge conflicts 11.6->12.3

feat(zk): per-source profile & settings
feat(zk): stub our zksolc settings restrictions

* fix(ci): update rust toolchain version

* fix(ci): proper rust toolchain name

* chore: clippy

---------

Co-authored-by: Federico Rodríguez <[email protected]>
Co-authored-by: Tomi Moreno <[email protected]>
Co-authored-by: Alex Ostrovski <[email protected]>
Co-authored-by: Dustin Brickwood <[email protected]>
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