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

Compilation Error When Using era-contracts in Foundry Projects #802

Open
dutterbutter opened this issue Sep 12, 2024 · 2 comments
Open

Compilation Error When Using era-contracts in Foundry Projects #802

dutterbutter opened this issue Sep 12, 2024 · 2 comments

Comments

@dutterbutter
Copy link

dutterbutter commented Sep 12, 2024

Description:

When users attempt to use era-contracts into their Foundry projects by running the following command:

forge install matter-labs/era-contracts

They encounter a compilation error due to an unresolved placeholder in the Constants.sol file:

Compiler run failed:
Error (6933): Expected primary expression.
  --> lib/era-contracts/system-contracts/contracts/Constants.sol:20:44:
   |
20 | uint160 constant SYSTEM_CONTRACTS_OFFSET = {{SYSTEM_CONTRACTS_OFFSET}}; // 2^15
   |                                            ^
Error:
Compilation failed

This issue occurs because SYSTEM_CONTRACTS_OFFSET is currently a placeholder ({{SYSTEM_CONTRACTS_OFFSET}}) rather than a resolved constant value.

Problematic Line:

The problematic line can be found here in the era-contracts repository:
lib/era-contracts/system-contracts/contracts/Constants.sol:20

uint160 constant SYSTEM_CONTRACTS_OFFSET = {{SYSTEM_CONTRACTS_OFFSET}}; // 2^15

Impact:

This issue leads to friction in the developer experience, as users are unable to compile their projects upon immediate installation. Rather they need to go into era-contracts and build first or replace with a constant value. This additional step although may seem negligible is a point of friction.

Suggested Solution:

I am unaware of the implications, if any, to replace the placeholder {{SYSTEM_CONTRACTS_OFFSET}} with an actual constant value directly in the Constants.sol file (e.g. 0x8000) but it would be nice not to have to do any additional steps to make use of era-contracts.

@dutterbutter
Copy link
Author

Improved understanding of the issue:

When we test system contracts we use our test-node (to have an environment that runs zkEVM code). However, unlike usual tests, here we have to replace system contracts themselves, i.e. if there is some issue in some code during the tests, the entire environment would get corrupted. That's why we have two modes in our contracts: "test mode" where all system contracts have addresses 0x9000 + X, and "prod mode" where all system contracts have addresses 0x8000 + X.
So that when we replace a contract under address 0x9000 + X with a mock the entire testing infra does not collapse due to changes in the system contracts

@kelemeno
Copy link
Contributor

kelemeno commented Nov 1, 2024

I was able to fix it on a different branch, will talk about merging this change to main with the others:

uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000; // 2^15

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

No branches or pull requests

2 participants