Skip to content

Commit

Permalink
Fix SYSTEM_CONTRACTS_OFFSET preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno authored and CodeSandwich committed Dec 17, 2024
1 parent aafee03 commit b5fcfde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit b5fcfde

Please sign in to comment.