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 SYSTEM_CONTRACTS_OFFSET preprocessing #1152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system-contracts/contracts/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {IPubdataChunkPublisher} from "./interfaces/IPubdataChunkPublisher.sol";

/// @dev All the system contracts introduced by zkSync have their addresses
/// started from 2^15 in order to avoid collision with Ethereum precompiles.
uint160 constant SYSTEM_CONTRACTS_OFFSET = {{SYSTEM_CONTRACTS_OFFSET}}; // 2^15
uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000; // 2^15

/// @dev Unlike the value above, it is not overridden for the purpose of testing and
/// is identical to the constant value actually used as the system contracts offset on
Expand Down
10 changes: 7 additions & 3 deletions system-contracts/scripts/preprocess-system-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from "fs";
import { existsSync, mkdirSync, writeFileSync } from "fs";
import path from "path";
import { renderFile } from "template-file";
Expand All @@ -16,15 +17,18 @@ async function preprocess(testMode: boolean) {
console.log("\x1b[31mWarning: test mode for the preprocessing being used!\x1b[0m");
params.SYSTEM_CONTRACTS_OFFSET = "0x9000";
}
const substring = "uint160 constant SYSTEM_CONTRACTS_OFFSET = 0x8000;"
const replacingSubstring = `uint160 constant SYSTEM_CONTRACTS_OFFSET = ${params.SYSTEM_CONTRACTS_OFFSET};`

const contracts = await glob(
[`${CONTRACTS_DIR}/**/*.sol`, `${CONTRACTS_DIR}/**/*.yul`, `${CONTRACTS_DIR}/**/*.zasm`],
{ onlyFiles: true }
);

for (const contract of contracts) {
const preprocessed = await renderFile(contract, params);
const fileName = `${OUTPUT_DIR}/${contract.slice(CONTRACTS_DIR.length)}`;
for (const contractPath of contracts) {
let contract = fs.readFileSync(contractPath,'utf8');
const preprocessed = await contract.replace(substring, replacingSubstring);
const fileName = `${OUTPUT_DIR}/${contractPath.slice(CONTRACTS_DIR.length)}`;
const directory = path.dirname(fileName);
if (!existsSync(directory)) {
mkdirSync(directory, { recursive: true });
Expand Down
Loading