Skip to content

Commit

Permalink
chore(kl-factory): Respond to comments by mm-zk (#1756)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
StanislavBreadless authored Apr 22, 2024
1 parent 651407e commit 9ef148e
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 171 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci-core-lint-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ jobs:
ci_run zk lint ts --check
ci_run zk lint md --check
ci_run zk db check-sqlx-data
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Cargo.lock
!/etc/env/configs/ext-node.toml
!/etc/env/configs/ext-node-docker.toml
/etc/env/l1-inits
!/etc/env/l1-inits/.init.env
/etc/env/l2-inits
!/etc/env/base
!/etc/env/file_based
Expand Down
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "contracts"]
path = contracts
url = https://github.com/matter-labs/era-contracts.git
branch = kl-factory
3 changes: 1 addition & 2 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib/
# Ignore contract submodules
contracts
contracts
4 changes: 2 additions & 2 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ pub const SHARED_BRIDGE_ETHER_TOKEN_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
]);
// Default `ERA_CHAIN_ID`. All hyperchains start with this chain id and later on
// it is changed to the proper one
// Default `ERA_CHAIN_ID`. All hyperchains start with this chain id and later on during their registration
// an "initial upgrade" transaction overrides it with the correct value.
pub const DEFAULT_ERA_CHAIN_ID: u32 = 270;
3 changes: 1 addition & 2 deletions core/lib/zksync_core/src/consistency_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ impl ConsistencyChecker {
}
}

// TODO: Add support for post shared bridge commits
let commit_function = if local.is_pre_boojum() {
&*PRE_BOOJUM_COMMIT_FUNCTION
} else if local.is_pre_shared_bridge() {
Expand All @@ -430,7 +429,7 @@ impl ConsistencyChecker {
} else {
self.contract
.function("commitBatchesSharedBridge")
.context("L1 contract does not have `commitBatches` function")
.context("L1 contract does not have `commitBatchesSharedBridge` function")
.map_err(CheckError::Internal)?
};

Expand Down
39 changes: 28 additions & 11 deletions core/node/block_reverter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,36 @@ impl BlockReverter {
.expect("Private key is required to send revert transaction"),
);
let chain_id = web3.eth().chain_id().await.unwrap().as_u64();
let zksync_chain_id = std::env::var("CHAIN_ETH_ZKSYNC_NETWORK_ID")
let hyperchain_id = std::env::var("CHAIN_ETH_ZKSYNC_NETWORK_ID")
.ok()
.and_then(|val| val.parse::<u128>().ok())
.expect("Hyperchain chain id has to be set in config");
let revert_function = contract.function("revertBatchesSharedBridge").expect(
"Either `revertBlocks` or `revertBatches` function must be present in contract",
);
let data = revert_function
.encode_input(&[
Token::Uint(zksync_chain_id.into()),
Token::Uint(last_l1_batch_to_keep.0.into()),
])
.unwrap();
.expect("`CHAIN_ETH_ZKSYNC_NETWORK_ID` has to be set in config");
let era_chain_id = std::env::var("CONTRACTS_ERA_CHAIN_ID")
.ok()
.and_then(|val| val.parse::<u128>().ok())
.expect("`CONTRACTS_ERA_CHAIN_ID` has to be set in config");

// It is expected that for all new chains `revertBatchesSharedBridge` can be used.
// For Era we are using `revertBatches` function for backwards compatibility in case the migration
// to the shared bridge is not yet complete.
let data = if hyperchain_id == era_chain_id {
let revert_function = contract
.function("revertBatches")
.expect("`revertBatches` function must be present in contract");
revert_function
.encode_input(&[Token::Uint(last_l1_batch_to_keep.0.into())])
.unwrap()
} else {
let revert_function = contract
.function("revertBatchesSharedBridge")
.expect("`revertBatchesSharedBridge` function must be present in contract");
revert_function
.encode_input(&[
Token::Uint(hyperchain_id.into()),
Token::Uint(last_l1_batch_to_keep.0.into()),
])
.unwrap()
};

let base_fee = web3
.eth()
Expand Down
4 changes: 2 additions & 2 deletions core/tests/ts-integration/tests/base-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ describe('base ERC20 contract checks', () => {
const finalAliceBalance = await alice.getBalance();
const finalBobBalance = await bob.getBalance();

await expect(finalAliceBalance).bnToBeEq(initialAliceBalance);
await expect(finalBobBalance).bnToBeEq(initialBobBalance);
expect(finalAliceBalance).bnToBeEq(initialAliceBalance);
expect(finalBobBalance).bnToBeEq(initialBobBalance);
});

test('Can perform a withdrawal', async () => {
Expand Down
2 changes: 1 addition & 1 deletion etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ max_acceptable_priority_fee_in_gwei = 100000000000

proof_loading_mode = "OldProofFromDb"

pubdata_sending_mode = "Calldata"
pubdata_sending_mode = "Blobs"

[eth_sender.gas_adjuster]
# Priority fee to be used by GasAdjuster (in wei).
Expand Down
2 changes: 1 addition & 1 deletion etc/env/configs/dev.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__imports__ = [ "base", "l1-inits/.init.env", "l2-inits/dev.init.env" ]

ETH_SENDER_SENDER_PUBDATA_SENDING_MODE = "Calldata"
ETH_SENDER_SENDER_PUBDATA_SENDING_MODE = "Blobs"
2 changes: 1 addition & 1 deletion etc/env/file_based/genesis.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
genesis_root: 0xb749a312a6f3ece4d43c5a02730587e133fd4ff4f90edf27d866f49946302abe
genesis_rollup_leaf_index: '46'
genesis_batch_commitment: 0x7c15b7e70795ba6d07ffa67482343d6b07fad0941d4fd7fe8a748b4da764c006
genesis_protocol_version: 24
genesis_protocol_version: 23
default_aa_hash: 0x0100055be0b42ec7b676a62a67507bad5db7b30ccbce9640ba9db9e37cc8d499
bootloader_hash: 0x010008095dfd6a873af3909665f4d7929d3bf86baf725277618f85135e4054d2
l1_chain_id: '9'
Expand Down
23 changes: 0 additions & 23 deletions etc/env/l1-inits/.init.env

This file was deleted.

28 changes: 1 addition & 27 deletions etc/tokens/test.json
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
[
{
"name": "ChainLink Token (goerli)",
"symbol": "LINK",
"decimals": 18,
"address": "0x63bfb2118771bd0da7A6936667A7BB705A06c1bA"
},
{
"name": "wBTC",
"symbol": "wBTC",
"decimals": 8,
"address": "0xCA063A2AB07491eE991dCecb456D1265f842b568"
},
{
"name": "USD Coin (goerli)",
"symbol": "USDC",
"decimals": 6,
"address": "0xd35CCeEAD182dcee0F148EbaC9447DA2c4D449c4"
},
{
"name": "DAI",
"symbol": "DAI",
"decimals": 18,
"address": "0x5C221E77624690fff6dd741493D735a17716c26B"
}
]

[]
24 changes: 0 additions & 24 deletions infrastructure/zk/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,6 @@ export async function initializeGovernance(): Promise<void> {
await utils.spawn(`yarn l1-contracts initialize-governance ${args.join(' ')} | tee initializeGovernance.log`);
}

export async function deployWeth(
command: 'dev' | 'new',
name?: string,
symbol?: string,
decimals?: string,
args: any = []
): Promise<void> {
// let destinationFile = 'localhost';
// if (args.includes('--envFile')) {
// destinationFile = args[args.indexOf('--envFile') + 1];
// args.splice(args.indexOf('--envFile'), 2);
// }
await utils.spawn(`yarn --silent --cwd contracts/l1-contracts deploy-weth '
${args.join(' ')} | tee deployL1.log`);

const deployLog = fs.readFileSync('deployL1.log').toString();
const l1DeploymentEnvVars = ['CONTRACTS_L1_WETH_TOKEN_ADDR'];
updateContractsEnv(
`etc/env/l1-inits/${process.env.L1_ENV_NAME ? process.env.L1_ENV_NAME : '.init'}.env`,
deployLog,
l1DeploymentEnvVars
);
}

export async function deployL2(args: any[] = [], includePaymaster?: boolean): Promise<void> {
await utils.confirmAction();

Expand Down
1 change: 1 addition & 0 deletions infrastructure/zk/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function load() {
export function modify(variable: string, value: string, initEnv: string, withReload = true) {
const assignedVariable = value.startsWith(`${variable}=`) ? value : `${variable}=${value}`;
fs.mkdirSync('etc/env/l2-inits', { recursive: true });
fs.mkdirSync('etc/env/l1-inits', { recursive: true });
if (!fs.existsSync(initEnv)) {
fs.writeFileSync(initEnv, assignedVariable);
return;
Expand Down
33 changes: 2 additions & 31 deletions infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import fetch from 'node-fetch';
import { up } from './up';
import * as Handlebars from 'handlebars';
import { ProverType, setupProver } from './prover_setup';
// import { DeploymentMode } from './contract';
import { announced } from './utils';

const title = chalk.blueBright;
Expand Down Expand Up @@ -141,7 +140,7 @@ async function setHyperchainMetadata(runObservability: boolean) {
];

const results: any = await enquirer.prompt(questions);
// kl to do add random chainId generation here if user does not want to pick chainId.
// TODO(EVM-574): add random chainId generation here if user does not want to pick chainId.

let deployer, governor, ethOperator, feeReceiver: ethers.Wallet | undefined;
let feeReceiverAddress, l1Rpc, l1Id, databaseUrl, databaseProverUrl;
Expand Down Expand Up @@ -305,9 +304,6 @@ async function setHyperchainMetadata(runObservability: boolean) {
await announced('Ensuring databases are up', db.wait({ core: true, prover: false }));
}

// testTokens and weth will be done for the shared bridge.
// await initializeTestERC20s();

console.log('\n');

printAddressInfo('Deployer', deployer.address);
Expand Down Expand Up @@ -427,31 +423,6 @@ function printAddressInfo(name: string, address: string) {
console.log('');
}

// async function initializeTestERC20s() {
// // TODO: For now selecting NO breaks server-core deployment, should be always YES or create empty-mock file for v2-core
// // PLA-595
// const questions: BasePromptOptions[] = [
// {
// message:
// 'Do you want to deploy some test ERC20s to your hyperchain? NB: Temporary broken, always select YES',
// name: 'deployERC20s',
// type: 'confirm'
// }
// ];

// const results: any = await enquirer.prompt(questions);

// if (results.deployERC20s) {
// env.modify('DEPLOY_TEST_TOKENS', 'true', 'etc/env/l1-inits/.init.env');
// console.log(
// warning(
// `The addresses for the generated test ECR20 tokens will be available at the /etc/tokens/${getEnv(
// process.env.CHAIN_ETH_NETWORK!
// )}.json file.`
// )
// );
// }
// }
async function startServer() {
const YES_DEFAULT = 'Yes (default components)';
const YES_CUSTOM = 'Yes (custom components)';
Expand Down Expand Up @@ -767,7 +738,7 @@ async function configDemoHyperchain(cmd: Command) {
skipEnvSetup: cmd.skipEnvSetup,
skipSubmodulesCheckout: false,
testTokenOptions: { envFile: process.env.CHAIN_ETH_NETWORK! },
// TODO set the proper values
// TODO(EVM-573): support Validium mode
runObservability: false,
validiumMode: false
});
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const lightweightInitCmdAction = async (): Promise<void> => {
await announced('Reloading env', env.reload());
await announced('Running server genesis setup', server.genesisFromBinary());
await announced('Deploying localhost ERC20 and Weth tokens', run.deployERC20AndWeth({ command: 'dev' }));
// TODO set proper values
// TODO(EVM-573): support Validium mode
await announced('Deploying L1 contracts', contract.redeployL1(false, DeploymentMode.Rollup));
await announced('Deploying L2 contracts', contract.deployL2ThroughL1({ includePaymaster: true }));
await announced('Initializing governance', contract.initializeGovernance());
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/zk/src/reinit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Command } from 'commander';
import { up } from './up';
import { announced } from './utils';
import { initDevCmdAction, initHyperCmdAction } from './init';
// import { DeploymentMode } from './contract';

const reinitDevCmdAction = async (): Promise<void> => {
await announced('Setting up containers', up(false));
Expand All @@ -13,7 +12,7 @@ const reinitDevCmdAction = async (): Promise<void> => {
skipEnvSetup: true,
skipSubmodulesCheckout: true,
skipTestTokenDeployment: true,
// TODO set proper values
// TODO(EVM-573): support Validium mode
runObservability: true,
validiumMode: false
});
Expand Down
37 changes: 0 additions & 37 deletions infrastructure/zk/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,6 @@ export async function deployERC20AndWeth({
}
}

export async function deployWeth({ envFile }: { envFile?: string }) {
const destinationFile = envFile || process.env.CHAIN_ETH_NETWORK!;
const privateKey = process.env.DEPLOYER_PRIVATE_KEY;
const args = [privateKey ? `--private-key ${privateKey}` : ''];
await utils.spawn(`yarn --silent --cwd contracts/l1-contracts deploy-erc20 add-multi '
[
{ "name": "Wrapped Ether", "symbol": "WETH", "decimals": 18, "implementation": "WETH9"}
]' ${args.join(' ')} > deployedTokens.log`);
let newlyDeployedTokens: Token[];
try {
newlyDeployedTokens = JSON.parse(
fs.readFileSync('deployedTokens.log', {
encoding: 'utf-8'
})
);
} catch (e) {
console.log('No new tokens deployed');
return;
}
const alreadyDeployedToken: Token[] = JSON.parse(
fs.readFileSync(`./etc/tokens/${destinationFile}.json`, {
encoding: 'utf-8'
})
);
const finalTokens: Token[] = alreadyDeployedToken
.filter((token) => newlyDeployedTokens.find((newToken) => newToken.symbol === token.symbol) === undefined)
.concat(newlyDeployedTokens);
fs.writeFileSync(`./etc/tokens/${destinationFile}.json`, JSON.stringify(finalTokens, null, 2));
const WETH = getTokens(destinationFile).find((token) => token.symbol === 'WETH')!;
env.modify(
'CONTRACTS_L1_WETH_TOKEN_ADDR',
`CONTRACTS_L1_WETH_TOKEN_ADDR=${WETH.address}`,
`etc/env/l1-inits/${process.env.L1_ENV_NAME ? process.env.L1_ENV_NAME : '.init'}.env`
);
return;
}

export type Token = {
address: string | null;
name: string;
Expand Down

0 comments on commit 9ef148e

Please sign in to comment.