Skip to content

Commit

Permalink
Ivan/fix l1 l2 address conversion (matter-labs#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ischasny authored and matzayonc committed Mar 27, 2024
1 parent bb0ec3d commit 27dd364
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion l1-contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export function getNumberFromEnv(envName: string): string {
const ADDRESS_MODULO = ethers.BigNumber.from(2).pow(160);

export function applyL1ToL2Alias(address: string): string {
return ethers.utils.hexlify(ethers.BigNumber.from(address).add(L1_TO_L2_ALIAS_OFFSET).mod(ADDRESS_MODULO));
return ethers.utils.hexZeroPad(
ethers.utils.hexlify(ethers.BigNumber.from(address).add(L1_TO_L2_ALIAS_OFFSET).mod(ADDRESS_MODULO)),
20
);
}

export function readBatchBootloaderBytecode() {
Expand Down
12 changes: 9 additions & 3 deletions l2-contracts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ export const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/
export const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: "utf-8" }));

export function applyL1ToL2Alias(address: string): string {
return ethers.utils.hexlify(ethers.BigNumber.from(address).add(L1_TO_L2_ALIAS_OFFSET).mod(ADDRESS_MODULO));
return ethers.utils.hexZeroPad(
ethers.utils.hexlify(ethers.BigNumber.from(address).add(L1_TO_L2_ALIAS_OFFSET).mod(ADDRESS_MODULO)),
20
);
}

export function unapplyL1ToL2Alias(address: string): string {
// We still add ADDRESS_MODULO to avoid negative numbers
return ethers.utils.hexlify(
ethers.BigNumber.from(address).sub(L1_TO_L2_ALIAS_OFFSET).add(ADDRESS_MODULO).mod(ADDRESS_MODULO)
return ethers.utils.hexZeroPad(
ethers.utils.hexlify(
ethers.BigNumber.from(address).sub(L1_TO_L2_ALIAS_OFFSET).add(ADDRESS_MODULO).mod(ADDRESS_MODULO)
),
20
);
}

Expand Down

0 comments on commit 27dd364

Please sign in to comment.