Skip to content

feat(l2): embed contracts in deployer and system_contracts_updater #3604

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

Merged
merged 36 commits into from
Jul 24, 2025

Conversation

avilagaston9
Copy link
Contributor

@avilagaston9 avilagaston9 commented Jul 11, 2025

Motivation

This PR embeds the bytecode of the contracts used in the deployer and system_contracts_updater as constants within the resulting binaries.

Description

  • Adds a build.rs script under crates/l2/contracts/bin/build.rs that downloads all necessary dependencies and compiles all required contracts.
  • Modifies deployer and system_contracts_updater to import the resulting bytecodes as constants using include_bytes!, instead of compiling them at runtime.
  • Removes the download_contract_deps function from the SDK, as it was only cloning the same two repositories and was used even when only one was needed.
  • Updates the compile_contract function in the SDK to accept a list of remappings.
  • Adds deploy_contract_from_bytecode and deploy_with_proxy_from_bytecode functions to the SDK.
  • Updates tests to work with the new SDK API.

Note

The new build.rs script checks if COMPILE_CONTRACTS is set to decide whether to compile the contracts.
This prevents cargo check --workspace from requiring solc as a dependency.

Closes #3380

@avilagaston9 avilagaston9 changed the base branch from main to l2/embed-contracts July 11, 2025 15:12
@avilagaston9 avilagaston9 changed the title Feat/l2/embed remaining contracts feat(l2): embed contracts in the deployer Jul 11, 2025
@github-actions github-actions bot added the L2 Rollup client label Jul 11, 2025
@avilagaston9 avilagaston9 self-assigned this Jul 11, 2025
@avilagaston9 avilagaston9 moved this to In Progress in ethrex_l2 Jul 11, 2025
Copy link

github-actions bot commented Jul 11, 2025

Lines of code report

Total lines added: 192
Total lines removed: 104
Total lines changed: 296

Detailed view
+------------------------------------------------------------------+-------+------+
| File                                                             | Lines | Diff |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/deployer/cli.rs                   | 367   | -9   |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/deployer/main.rs                  | 568   | -58  |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/system_contracts_updater/cli.rs   | 13    | -8   |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/system_contracts_updater/error.rs | 16    | -1   |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/system_contracts_updater/main.rs  | 97    | +10  |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/build.rs                              | 146   | +146 |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/build.rs                                    | 41    | +10  |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/contract_utils/src/compile.rs               | 76    | -2   |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/contract_utils/src/deps.rs                  | 144   | -26  |
+------------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                                  | 510   | +26  |
+------------------------------------------------------------------+-------+------+

@avilagaston9 avilagaston9 marked this pull request as ready for review July 14, 2025 16:04
@avilagaston9 avilagaston9 requested a review from a team as a code owner July 14, 2025 16:04
@avilagaston9 avilagaston9 changed the title feat(l2): embed contracts in the deployer feat(l2): embed contracts in deployer and system_contracts_updater Jul 14, 2025
Base automatically changed from l2/embed-contracts to main July 15, 2025 18:50
Copy link
Contributor

@xqft xqft left a comment

Choose a reason for hiding this comment

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

nice!!

@avilagaston9 avilagaston9 force-pushed the feat/l2/embed_remaining_contracts branch from c513224 to e724c86 Compare July 15, 2025 19:47
@avilagaston9 avilagaston9 marked this pull request as draft July 16, 2025 21:40
@avilagaston9 avilagaston9 marked this pull request as ready for review July 17, 2025 17:57
@avilagaston9 avilagaston9 moved this from In Progress to In Review in ethrex_l2 Jul 17, 2025
Comment on lines 103 to 111
for entry in fs::read_dir(dir).expect("Failed to read directory") {
let entry = entry.expect("Failed to get entry");
let path = entry.path();
if path.is_dir() {
watch_solidity_files(&path);
} else if path.extension().is_some_and(|ext| ext == "sol") {
println!("cargo::rerun-if-changed={}", path.display());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can just do cargo::rerun-if-changed=crates/l2/contracts/src here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha my bad. I hadn't read the "Note from the future" comment. Done in f1d793f!

@avilagaston9 avilagaston9 added this pull request to the merge queue Jul 24, 2025
Merged via the queue into main with commit 67cd8be Jul 24, 2025
40 checks passed
@avilagaston9 avilagaston9 deleted the feat/l2/embed_remaining_contracts branch July 24, 2025 13:03
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l2 Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L2 Rollup client
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Embed contracts inside compiled binary
3 participants