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

Initial changes + ffi workflow #550

Open
wants to merge 75 commits into
base: release-v23
Choose a base branch
from
Open
Changes from 8 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4c0e566
extend utils & update compilation process (#396)
Raid5594 Apr 24, 2024
3601648
NonceHolder Tests (#176)
neotheprogramist May 16, 2024
2840540
chore(scripts): remove unconditionally removed facets (#448)
koloz193 May 16, 2024
622638a
chore(contracts): remove usage of ergs (#454)
koloz193 May 16, 2024
bd9bec5
chore(verifier): update generation to include vk hash (#453)
koloz193 May 16, 2024
994897b
chore(contract): applied new solhint rules across l1, l2, and system …
koloz193 May 16, 2024
8e4c291
Merge branch 'release-v23' into dev
koloz193 Jun 5, 2024
d97d8cd
tests and fix merge conflict
koloz193 Jun 5, 2024
704b41b
fix merge conflicts and bump hashes
koloz193 Jun 5, 2024
ee5667e
fixed lint
koloz193 Jun 5, 2024
5c4525a
update system contracts hashes and verifier hash
koloz193 Jun 5, 2024
131f823
update forge-std
koloz193 Jun 5, 2024
360a918
Merge pull request #508 from matter-labs/zk-merge-release-23-dev
StanislavBreadless Jun 5, 2024
394f651
Merge pull request #399 from matter-labs/release-v23
StanislavBreadless Jun 11, 2024
680b252
sync with dev
StanislavBreadless Jun 11, 2024
8df3025
Merge pull request #523 from matter-labs/sb-merge-main-to-dev
StanislavBreadless Jun 11, 2024
01f033b
Add script for system contracts block explorer verification (#510)
vladbochok Jun 11, 2024
311b82e
chore: zksync-ethers 5.8.0-beta.5 (#387)
benceharomi Jun 11, 2024
ab2f13d
feat: check diamond cut hash locally (#525)
dimazhornyk Jun 12, 2024
29f9ff4
Finalize gas bound caller (#526)
StanislavBreadless Jun 12, 2024
594bac2
Update README.md (#532)
StanislavBreadless Jun 14, 2024
7d7af53
Fix incorrect clause (#535)
StanislavBreadless Jun 18, 2024
100b3bf
Adding doc comments to the chain contracts (#530)
vladbochok Jun 18, 2024
dc7bd13
Add CI coverage (reopenned to dev) (#543)
vladbochok Jun 21, 2024
db93876
Fix erc20 contracts (#545)
Deniallugo Jun 21, 2024
8fec7ec
Mailbox unit testing (#489)
neotheprogramist Jun 27, 2024
116206c
Revert "Mailbox unit testing (#489)" (#558)
saxenism Jun 27, 2024
8172969
feat(deploy): Mint tokens to multiple addresses (#552)
Deniallugo Jun 27, 2024
fb3a5d8
chore(ci): Additional permissions for CI token (#565)
artmakh Jul 2, 2024
1c1b93b
Mailbox unit testing (#559)
tommysr Jul 3, 2024
c9a8a68
chore: zksync-ethers to stable v5.9.0 (#567)
benceharomi Jul 3, 2024
62408fc
Make Deniallugo codeowner for deploy scripts (#597)
Deniallugo Jul 4, 2024
f4ae6a1
Accept admin using methods not files (#568)
Deniallugo Jul 4, 2024
bc98e4b
remove outdated folder (#601)
kelemeno Jul 8, 2024
c808b1f
Merge branch 'main' into zk-sync-main-dev
koloz193 Aug 5, 2024
5b8d6ae
Merge pull request #678 from matter-labs/zk-sync-main-dev
StanislavBreadless Aug 6, 2024
b62ca53
Add chain contract (#598)
vladbochok Aug 6, 2024
3161150
sync main with dev
StanislavBreadless Aug 7, 2024
0b80914
Merge pull request #681 from matter-labs/sb-merge-main-into-dev
StanislavBreadless Aug 7, 2024
7ca5517
feat: add tokenMultiplierSetter role to deployment scripts (#683)
ischasny Aug 9, 2024
1812c31
Merge branch 'main' into deniallugo-merge-main
Deniallugo Aug 13, 2024
d0d735c
Merge pull request #696 from matter-labs/deniallugo-merge-main
StanislavBreadless Aug 13, 2024
118f081
Bridgehub Test Coverage Increase (#494)
neotheprogramist Aug 14, 2024
fd4aebc
fix: zksync-ethers v5 dependency (#702)
benceharomi Aug 15, 2024
7f4f460
feat(foundry): use foundry zksync (dev) (#551)
Deniallugo Aug 16, 2024
80e8234
feat(consensus): add L2 registry contract (BFT-434) (#555)
moshababo Aug 19, 2024
2c8a5fa
Revert: "feat(consensus): add L2 registry contract (BFT-434)" (#717)
pompon0 Aug 20, 2024
5853c3a
feat(consensus): add L2 registry contract (BFT-434) (#555) (#718)
pompon0 Aug 20, 2024
8be87b2
Merge Protocol Defense Tasks into Dev (#518)
koloz193 Aug 20, 2024
7b488e6
chore: foundry config cleanup (#722)
benceharomi Aug 20, 2024
446d391
Add admin role to shared bridge (#727)
StanislavBreadless Aug 21, 2024
2395aed
Update solidity contracts version (#688)
IAvecilla Aug 23, 2024
a36c6c2
chore(config): Fix server build with symlinks (#740)
StanislavBreadless Aug 28, 2024
8d9240f
feat: add a script to prepare chain registration calldata (#671)
dimazhornyk Aug 28, 2024
1e0df10
feat(l2): solidity 0.8.24 and zksolc 1.5.0 (#743)
benceharomi Aug 28, 2024
f2d553b
feat(l1): added missing foundry lib symlinks (#741)
benceharomi Aug 28, 2024
383e1b0
docs: update zkSync casing to ZKsync (#733)
benceharomi Aug 28, 2024
dba0212
chore(contracts): add missing spdx licenses (#732)
koloz193 Aug 28, 2024
874bc6b
fix(scrips): read bytecode from foundry not hardhat (#750)
koloz193 Aug 29, 2024
d368769
feat: Deploy ConsensusRegistry through L1 to L2 transaction (BFT-504)…
aakoshh Sep 2, 2024
7f2c27a
Small PR to Fix "Ethers" and "ETH" encoding (#762)
Raid5594 Sep 3, 2024
3d6e02f
Set foundry optimizer_runs (#770)
perekopskiy Sep 5, 2024
8b5b296
Implement restriction to allow limiting chain admin in power (#699)
StanislavBreadless Sep 5, 2024
6892ccc
Add admin permission to add custom base tokens (#776)
vladbochok Sep 6, 2024
b6c7130
merge main into dev
StanislavBreadless Sep 6, 2024
0fa0fa2
foundry tests pass
StanislavBreadless Sep 6, 2024
00ddc06
fix compile for registry
StanislavBreadless Sep 6, 2024
ef33539
lint
StanislavBreadless Sep 6, 2024
b653ac8
Merge pull request #778 from matter-labs/sb-merge-main-to-dev
StanislavBreadless Sep 6, 2024
cc3b2ac
chore: merge main (#790)
kelemeno Sep 10, 2024
0ce72f9
Initial changes + ffi workflow
Yberjon Jun 24, 2024
47cc8e2
Change CI name
Yberjon Jun 24, 2024
b8b84d6
Deploy Paymaster Test
Yberjon Jul 9, 2024
350c423
Linter fix
Yberjon Jul 9, 2024
8813705
Fix imports and declarations
Yberjon Sep 30, 2024
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: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @vladbochok @StanislavBreadless
l1-contracts/deploy-scripts @Deniallugo
l1-contracts/deploy-script-config-template @Deniallugo
6 changes: 2 additions & 4 deletions gas-bound-caller/README.md
Original file line number Diff line number Diff line change
@@ -20,12 +20,10 @@ If the call to the `_to` address succeeds, the `GasBoundCaller` will ensure that

Summing up the information from the previous chapter, the `GasBoundCaller` should be used in the following way:

TODO(EVM-585): switch `addr` with address.

```solidity
uint256 computeGasBefore = gasleft();
(bool success, bytes memory returnData) = address(this).call{gas: _gasToPass}(abi.encodeWithSelector(GasBoundCaller.gasBoundCall.selector, _to, _maxTotalGas, _data));
(bool success, bytes memory returnData) = address(0xc706EC7dfA5D4Dc87f29f859094165E8290530f5).call{gas: _gasToPass}(abi.encodeWithSelector(GasBoundCaller.gasBoundCall.selector, _to, _maxTotalGas, _data));
uint256 pubdataGasSpent;
if (success) {
@@ -48,4 +46,4 @@ Since `GasBoundCaller` would be the contract that calls the `_to` contract, the

It should be deployed via a built-in CREATE2 factory on each individual chain.

TODO(EVM-585)
The current address on both sepolia testnet and mainnet for zkSync Era is `0xc706EC7dfA5D4Dc87f29f859094165E8290530f5`.
2 changes: 1 addition & 1 deletion gas-bound-caller/canonical-bytecodes/GasBoundCaller

Large diffs are not rendered by default.

33 changes: 16 additions & 17 deletions gas-bound-caller/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import "@matterlabs/hardhat-zksync-chai-matchers";
import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@nomiclabs/hardhat-ethers";
import "hardhat-typechain";

// This version of system contracts requires a pre release of the compiler
const COMPILER_VERSION = "1.5.0";
const PRE_RELEASE_VERSION = "prerelease-a167aa3-code4rena";
function getZksolcUrl(): string {
// @ts-ignore
const platform = { darwin: "macosx", linux: "linux", win32: "windows" }[process.platform];
// @ts-ignore
const toolchain = { linux: "-musl", win32: "-gnu", darwin: "" }[process.platform];
const arch = process.arch === "x64" ? "amd64" : process.arch;
const ext = process.platform === "win32" ? ".exe" : "";

return `https://github.com/matter-labs/era-compiler-solidity/releases/download/${PRE_RELEASE_VERSION}/zksolc-${platform}-${arch}${toolchain}-v${COMPILER_VERSION}${ext}`;
}

console.log(`Using zksolc from ${getZksolcUrl()}`);

export default {
zksolc: {
version: "1.5.0",
compilerSource: "binary",
settings: {
compilerPath: getZksolcUrl(),
isSystem: true,
},
},
@@ -55,6 +40,20 @@ export default {
ethNetwork: "localhost",
zksync: true,
},
zkSyncTestnet: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
// contract verification endpoint
verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification",
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
// contract verification endpoint
verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification",
},
},
paths: {
sources: "./contracts",
3 changes: 3 additions & 0 deletions gas-bound-caller/package.json
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
"devDependencies": {
"@matterlabs/hardhat-zksync-chai-matchers": "^0.2.0",
"@matterlabs/hardhat-zksync-node": "^0.0.1-beta.7",
"@matterlabs/hardhat-zksync-verify": "0.6.1",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@typechain/ethers-v5": "^2.0.0",
@@ -53,6 +54,8 @@
"clean": "yarn clean:bootloader && yarn clean:system-contracts",
"test": "yarn build && hardhat test --network zkSyncTestNode",
"test-node": "hardhat node-zksync --tag v0.0.1-vm1.5.0",
"check-canonical-bytecode": "ts-node ./scripts/check-canonical-bytecode.ts",
"verify": "hardhat run scripts/verify.ts",
"deploy-on-hyperchain": "ts-node ./scripts/deploy-on-hyperchain.ts",
"deploy-on-localhost": "hardhat deploy --network localhost"
}
31 changes: 31 additions & 0 deletions gas-bound-caller/scripts/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// hardhat import should be the first import in the file
import * as hardhat from "hardhat";

const EXPECTED_ADDRESS = "0xc706EC7dfA5D4Dc87f29f859094165E8290530f5";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verifyPromise(address: string, constructorArguments?: Array<any>, libraries?: object): Promise<any> {
return new Promise((resolve, reject) => {
hardhat
.run("verify:verify", { address, constructorArguments, libraries })
.then(() => resolve(`Successfully verified ${address}`))
.catch((e) => reject(`Failed to verify ${address}\nError: ${e.message}`));
});
}

async function main() {
if (process.env.CHAIN_ETH_NETWORK == "localhost") {
console.log("Skip contract verification on localhost");
return;
}

const message = await verifyPromise(EXPECTED_ADDRESS);
console.log(message.status == "fulfilled" ? message.value : message.reason);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err.message || err);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
additional_addresses_for_minting = []

[tokens.DAI]
name = "DAI"
symbol = "DAI"
20 changes: 8 additions & 12 deletions l1-contracts/deploy-scripts/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
@@ -27,28 +26,25 @@ contract AcceptAdmin is Script {
}

// This function should be called by the owner to accept the admin role
function acceptOwner() public {
initConfig();

Ownable2Step adminContract = Ownable2Step(config.admin);
function acceptOwner(address governor, address target) public {
Ownable2Step adminContract = Ownable2Step(target);
Utils.executeUpgrade({
_governor: config.governor,
_governor: governor,
_salt: bytes32(0),
_target: config.admin,
_target: target,
_data: abi.encodeCall(adminContract.acceptOwnership, ()),
_value: 0,
_delay: 0
});
}

// This function should be called by the owner to accept the admin role
function acceptAdmin() public {
initConfig();
IZkSyncHyperchain adminContract = IZkSyncHyperchain(config.admin);
function acceptAdmin(address governor, address target) public {
IZkSyncHyperchain adminContract = IZkSyncHyperchain(target);
Utils.executeUpgrade({
_governor: config.governor,
_governor: governor,
_salt: bytes32(0),
_target: config.admin,
_target: target,
_data: abi.encodeCall(adminContract.acceptAdmin, ()),
_value: 0,
_delay: 0
29 changes: 20 additions & 9 deletions l1-contracts/deploy-scripts/DeployErc20.s.sol
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@
import {Script, console2 as console} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

// It's required to disable lints to force the compiler to compile the contracts
// solhint-disable no-unused-import
import {TestnetERC20Token} from "contracts/dev-contracts/TestnetERC20Token.sol";
// solhint-disable no-unused-import
import {WETH9} from "contracts/dev-contracts/WETH9.sol";

import {Utils} from "./Utils.sol";
import {MintFailed} from "./ZkSyncScriptErrors.sol";

@@ -15,6 +21,7 @@
struct Config {
TokenDescription[] tokens;
address deployerAddress;
address[] additionalAddressesForMinting;
address create2FactoryAddr;
bytes32 create2FactorySalt;
}
@@ -56,6 +63,7 @@
// Grab config from custom config file
path = string.concat(root, "/script-config/config-deploy-erc20.toml");
toml = vm.readFile(path);
config.additionalAddressesForMinting = vm.parseTomlAddressArray(toml, "$.additional_addresses_for_minting");

string[] memory tokens = vm.parseTomlKeys(toml, "$.tokens");

@@ -68,7 +76,6 @@
token.decimals = toml.readUint(string.concat(key, ".decimals"));
token.implementation = toml.readString(string.concat(key, ".implementation"));
token.mint = toml.readUint(string.concat(key, ".mint"));

config.tokens.push(token);
}
}
@@ -83,7 +90,8 @@
symbol: token.symbol,
decimals: token.decimals,
implementation: token.implementation,
mint: token.mint
mint: token.mint,
additionalAddressesForMinting: config.additionalAddressesForMinting
});
console.log("Token deployed at:", tokenAddress);
token.addr = tokenAddress;
@@ -95,7 +103,8 @@
string memory symbol,
uint256 decimals,
string memory implementation,
uint256 mint
uint256 mint,
address[] storage additionalAddressesForMinting
) internal returns (address) {
bytes memory args;
// WETH9 constructor has no arguments
@@ -109,11 +118,13 @@

if (mint > 0) {
vm.broadcast();
(bool success, ) = tokenAddress.call(
abi.encodeWithSignature("mint(address,uint256)", config.deployerAddress, mint)
);
if (!success) {
revert MintFailed();
additionalAddressesForMinting.push(config.deployerAddress);
for (uint256 i = 0; i < additionalAddressesForMinting.length; i++) {

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Found [ .length ] property in Loop condition. Suggestion: assign it to a variable

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: For [ i ] variable, increment/decrement by 1 using: [ ++variable ] to save gas

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Found [ .length ] property in Loop condition. Suggestion: assign it to a variable

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: For [ i ] variable, increment/decrement by 1 using: [ ++variable ] to save gas

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Found [ .length ] property in Loop condition. Suggestion: assign it to a variable

Check failure on line 122 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: For [ i ] variable, increment/decrement by 1 using: [ ++variable ] to save gas
(bool success, ) = tokenAddress.call(
abi.encodeWithSignature("mint(address,uint256)", additionalAddressesForMinting[i], mint)
);
require(success, "Mint failed");

Check failure on line 126 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 126 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 126 in l1-contracts/deploy-scripts/DeployErc20.s.sol

GitHub Actions / lint

GC: Use Custom Errors instead of require statements
console.log("Minting to:", additionalAddressesForMinting[i]);
}
}

@@ -129,7 +140,7 @@
vm.serializeString(token.symbol, "symbol", token.symbol);
vm.serializeUint(token.symbol, "decimals", token.decimals);
vm.serializeString(token.symbol, "implementation", token.implementation);
vm.serializeUint(token.symbol, "mint", token.mint);
vm.serializeUintToHex(token.symbol, "mint", token.mint);
string memory tokenInfo = vm.serializeAddress(token.symbol, "address", token.addr);

tokens = vm.serializeString("tokens", token.symbol, tokenInfo);
16 changes: 13 additions & 3 deletions system-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@matterlabs/hardhat-zksync-chai-matchers";
import "@matterlabs/hardhat-zksync-node";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@nomiclabs/hardhat-ethers";
import "hardhat-typechain";

@@ -50,6 +51,18 @@ export default {
hardhat: {
zksync: true,
},
mainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
verifyURL: "https://mainnet.zksync.io/contract_verification",
},
sepolia: {
url: "https://sepolia.era.zksync.dev",
ethNetwork: "sepolia",
zksync: true,
verifyURL: "https://sepolia.zksync.io/contract_verification",
},
zkSyncTestNode: {
url: "http://127.0.0.1:8011",
ethNetwork: "localhost",
@@ -60,9 +73,6 @@ export default {
ethNetwork: "sepolia",
zksync: true,
},
sepolia: {
url: "", // add your sepolia node url
},
},
paths: {
sources: "./contracts-preprocessed",
4 changes: 3 additions & 1 deletion system-contracts/package.json
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
"dependencies": {
"@matterlabs/hardhat-zksync-deploy": "^0.7.0",
"@matterlabs/hardhat-zksync-solc": "^1.1.4",
"@matterlabs/hardhat-zksync-verify": "^1.4.3",
"commander": "^9.4.1",
"eslint": "^8.51.0",
"eslint-plugin-import": "^2.29.0",
@@ -61,7 +62,8 @@
"compile-zasm": "ts-node scripts/compile-zasm.ts",
"deploy-preimages": "ts-node scripts/deploy-preimages.ts",
"preprocess:bootloader": "rm -rf ./bootloader/build && yarn ts-node scripts/preprocess-bootloader.ts",
"preprocess:system-contracts": "ts-node scripts/preprocess-system-contracts.ts",
"preprocess:system-contracts": "rm -rf ./contracts-preprocessed && ts-node scripts/preprocess-system-contracts.ts",
"verify-on-explorer": "hardhat run scripts/verify-on-explorer.ts",
"test": "yarn build:test-system-contracts && hardhat test --network zkSyncTestNode",
"test-node": "hardhat node-zksync --tag v0.0.1-vm1.5.0",
"test:bootloader": "cd bootloader/test_infra && cargo run"
46 changes: 46 additions & 0 deletions system-contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ import path from "path";
import { spawn as _spawn } from "child_process";
import { createHash } from "crypto";
import { CompilerDownloader } from "hardhat/internal/solidity/compiler/downloader";
import fetch from "node-fetch";

export type HttpMethod = "POST" | "GET";

export interface Dependency {
name: string;
@@ -326,3 +329,46 @@ export async function isFolderEmpty(folderPath: string): Promise<boolean> {
return true; // Return true if an error, as folder doesn't exist.
}
}
/**
* Performs an API call to the Contract verification API.
*
* @param endpoint API endpoint to call.
* @param queryParams Parameters for a query string.
* @param requestBody Request body. If provided, a POST request would be met and body would be encoded to JSON.
* @returns API response parsed as a JSON.
*/
export async function query(
method: HttpMethod,
endpoint: string,
queryParams?: { [key: string]: string },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
requestBody?: any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<any> {
const url = new URL(endpoint);
// Iterate through query params and add them to URL.
if (queryParams) {
Object.entries(queryParams).forEach(([key, value]) => url.searchParams.set(key, value));
}

const init = {
method,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
};
if (requestBody) {
init.body = JSON.stringify(requestBody);
}

const response = await fetch(url, init);
try {
return await response.json();
} catch (e) {
throw {
error: "Could not decode JSON in response",
status: `${response.status} ${response.statusText}`,
};
}
}
86 changes: 86 additions & 0 deletions system-contracts/scripts/verify-on-explorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// hardhat import should be the first import in the file
import * as hre from "hardhat";

import type { YulContractDescription } from "./constants";
import { SYSTEM_CONTRACTS } from "./constants";
import { query } from "./utils";
import { Command } from "commander";
import * as fs from "fs";
import { sleep } from "zksync-ethers/build/src/utils";

const VERIFICATION_URL = hre.network?.config?.verifyURL;

async function waitForVerificationResult(requestId: number) {
let retries = 0;

// eslint-disable-next-line no-constant-condition
while (true) {
if (retries > 50) {
throw new Error("Too many retries");
}

const statusObject = await query("GET", `${VERIFICATION_URL}/${requestId}`);

if (statusObject.status == "successful") {
break;
} else if (statusObject.status == "failed") {
throw new Error(statusObject.error);
} else {
retries += 1;
await sleep(1000);
}
}
}

async function verifyYul(contractInfo: YulContractDescription) {
const sourceCodePath = `${__dirname}/../contracts-preprocessed/${contractInfo.path}/${contractInfo.codeName}.yul`;
const sourceCode = (await fs.promises.readFile(sourceCodePath)).toString();
const requestBody = {
contractAddress: contractInfo.address,
contractName: contractInfo.codeName,
sourceCode: sourceCode,
codeFormat: "yul-single-file",
compilerZksolcVersion: hre.config.zksolc.version,
compilerSolcVersion: hre.config.solidity.compilers[0].version,
optimizationUsed: true,
constructorArguments: "0x",
isSystem: true,
};

const requestId = await query("POST", VERIFICATION_URL, undefined, requestBody);
await waitForVerificationResult(requestId);
}

async function main() {
const program = new Command();

program
.version("0.1.0")
.name("verify on explorer")
.description("Verify system contracts source code on block explorer");

for (const contractName in SYSTEM_CONTRACTS) {
const contractInfo = SYSTEM_CONTRACTS[contractName];
console.log(`Verifying ${contractInfo.codeName} on ${contractInfo.address} address..`);
if (contractInfo.lang == "solidity") {
await hre.run("verify:verify", {
address: contractInfo.address,
contract: `contracts-preprocessed/${contractInfo.codeName}.sol:${contractInfo.codeName}`,
constructorArguments: [],
});
} else if (contractInfo.lang == "yul") {
await verifyYul(contractInfo);
} else {
throw new Error("Unknown source code language!");
}
}

await program.parseAsync(process.argv);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err.message || err);
process.exit(1);
});
90 changes: 85 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -772,10 +772,30 @@
sinon-chai "^3.7.0"
undici "^5.14.0"

"@matterlabs/hardhat-zksync-verify@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-0.4.0.tgz#f812c19950022fc36728f3796f6bdae5633e2fcd"
integrity sha512-GPZmAumFl3ZMPKbECX7Qw8CriwZKWd1DlCRhoG/6YYc6mFy4+MXkF1XsHLMs5r34N+GDOfbVZVMeftIlJC96Kg==
"@matterlabs/hardhat-zksync-verify@0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-0.6.1.tgz#3fd83f4177ac0b138656ed93d4756ec27f1d329d"
integrity sha512-W9gI4k1UnuQ2MaBnK1f7E8Z2C4uHxpeDkzmB/ZCKClai2A3vK2jAbfqiQbX0HvuLq2OOq4dbx83KehAXjXoHlw==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "5.7.0"
"@matterlabs/hardhat-zksync-solc" "^1.1.4"
"@nomicfoundation/hardhat-verify" "^2.0.0"
"@openzeppelin/contracts" "^4.9.2"
axios "^1.6.2"
cbor "^8.1.0"
chai "^4.3.6"
chalk "4.1.2"
debug "^4.1.1"
hardhat "^2.14.0"
sinon "^17.0.1"
sinon-chai "^3.7.0"
zksync-ethers "^5.0.0"

"@matterlabs/hardhat-zksync-verify@^0.2.0":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-0.2.2.tgz#daa34bc4404096ed0f44461ee366c1cb0e5a4f2f"
integrity sha512-WgcItoZGY702oJ708uCP5uLvmwzDLBfhMqq2D0Kh1U/3fCTlPza9zMGUFHxKMQYsITKTeQ5zKOjKoi8MXOeUdQ==
dependencies:
"@matterlabs/hardhat-zksync-solc" "^1.0.5"
"@nomicfoundation/hardhat-verify" "^1.0.2"
@@ -784,6 +804,25 @@
dockerode "^3.3.4"
zksync-ethers "^5.0.0"

"@matterlabs/hardhat-zksync-verify@^1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-1.4.3.tgz#fc36d2ea385eab553ce0b3c3fbc9e216c607873f"
integrity sha512-TONID/+mG8KngZ9iI8yiOgC8VD+cus7M+ejCjF4bGNzsmmzsklGJwzry6bQpk8BXqzsMgbuV+4KjDT4JXiS/QA==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "5.7.0"
"@matterlabs/hardhat-zksync-solc" "^1.1.4"
"@nomicfoundation/hardhat-verify" "^2.0.0"
"@openzeppelin/contracts" "^4.9.2"
axios "^1.6.2"
cbor "^8.1.0"
chai "^4.3.6"
chalk "4.1.2"
debug "^4.1.1"
hardhat "^2.19.4"
sinon "^17.0.1"
sinon-chai "^3.7.0"

"@matterlabs/prettier-config@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@matterlabs/prettier-config/-/prettier-config-1.0.3.tgz#3e2eb559c0112bbe9671895f935700dad2a15d38"
@@ -1013,6 +1052,21 @@
table "^6.8.0"
undici "^5.14.0"

"@nomicfoundation/hardhat-verify@^2.0.0":
version "2.0.8"
resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.8.tgz#6a77dc03de990a1a3aa8e6dc073c393263dbf258"
integrity sha512-x/OYya7A2Kcz+3W/J78dyDHxr0ezU23DKTrRKfy5wDPCnePqnr79vm8EXqX3gYps6IjPBYyGPZ9K6E5BnrWx5Q==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "^5.0.2"
cbor "^8.1.0"
chalk "^2.4.2"
debug "^4.1.1"
lodash.clonedeep "^4.5.0"
semver "^6.3.0"
table "^6.8.0"
undici "^5.14.0"

"@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15"
@@ -1124,6 +1178,11 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.5.tgz#1eed23d4844c861a1835b5d33507c1017fa98de8"
integrity sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==

"@openzeppelin/contracts@^4.9.2":
version "4.9.6"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677"
integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA==

"@pkgr/core@^0.1.0":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31"
@@ -2111,6 +2170,15 @@ axios@^1.4.0, axios@^1.5.1:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.6.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.2.tgz#b625db8a7051fbea61c35a3cbb3a1daa7b9c7621"
integrity sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
@@ -4325,7 +4393,7 @@ hardhat@=2.22.2:
uuid "^8.3.2"
ws "^7.4.6"

hardhat@^2.14.0:
hardhat@^2.18.3, hardhat@^2.19.4:
version "2.22.5"
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.22.5.tgz#7e1a4311fa9e34a1cfe337784eae06706f6469a5"
integrity sha512-9Zq+HonbXCSy6/a13GY1cgHglQRfh4qkzmj1tpPlhxJDwNVnhxlReV6K7hCWFKlOrV13EQwsdcD0rjcaQKWRZw==
@@ -7741,9 +7809,21 @@ yocto-queue@^1.0.0:
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

zksync-ethers@^5.0.0:
<<<<<<< HEAD
version "5.7.2"
resolved "https://registry.yarnpkg.com/zksync-ethers/-/zksync-ethers-5.7.2.tgz#e965a9926e6f8168963ab565dd6ad0d38c4f7f18"
integrity sha512-D+wn4nkGixUOek9ZsVvIZ/MHponQ5xvw74FSbDJDv6SLCI4LZALOAc8lF3b1ml8nOkpeE2pGV0VKmHTSquRNJg==
=======
version "5.8.0"
resolved "https://registry.yarnpkg.com/zksync-ethers/-/zksync-ethers-5.8.0.tgz#ff054345048f851c33cb6efcf2094f40d4da6063"
integrity sha512-/4qI5UElh0lspu0ew2IXBCO+O9kXEzZOM7JqvlfRWWGIUKZ+EDXnjIPgkH0y5/MnMT3FDq9koAAUCyZVWqHUJg==
dependencies:
ethers "~5.7.0"

"zksync-ethers@https://github.com/zksync-sdk/zksync-ethers#ethers-v5-feat/bridgehub":
version "5.1.0"
resolved "https://github.com/zksync-sdk/zksync-ethers#28ccbe7d67b170c202b17475e06a82002e6e3acc"
>>>>>>> main
dependencies:
ethers "~5.7.0"