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(zk_stack): Use deployer private key and remove create2 address #1098

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
10 changes: 10 additions & 0 deletions infrastructure/zk/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export function modify(variable: string, assignedVariable: string) {
reload();
}

export function removeFromInit(variable: string) {
const initEnv = 'etc/env/.init.env';
if (!fs.existsSync(initEnv)) {
return;
}

utils.replaceInFile(initEnv, `${variable}=.*`, '');
reload();
}

// merges .init.env with current env file so all configs are in the same place
export function mergeInitToEnv() {
const env = dotenv.parse(fs.readFileSync(process.env.ENV_FILE!));
Expand Down
14 changes: 12 additions & 2 deletions infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async function initHyperchain() {
testTokens: {
deploy: deployTestTokens,
args: ['--private-key', deployerPrivateKey, '--envFile', process.env.CHAIN_ETH_NETWORK!]
}
},
deployerPrivateKeyArgs: ['--private-key', deployerPrivateKey]
};

await init(initArgs);
Expand Down Expand Up @@ -110,6 +111,7 @@ async function setHyperchainMetadata() {
BaseNetwork.GOERLI,
BaseNetwork.MAINNET
];

const GENERATE_KEYS = 'Generate keys';
const INSERT_KEYS = 'Insert keys';
const questions: BasePromptOptions[] = [
Expand Down Expand Up @@ -139,6 +141,12 @@ async function setHyperchainMetadata() {
let deployer, governor, ethOperator, feeReceiver: ethers.Wallet | undefined;
let feeReceiverAddress, l1Rpc, l1Id, databaseUrl;

if (results.l1Chain !== BaseNetwork.LOCALHOST || results.l1Chain !== BaseNetwork.LOCALHOST_CUSTOM) {
// If it's not a localhost chain, we need to remove the CONTRACTS_CREATE2_FACTORY_ADDR from the .env file and use default value.
// Otherwise it's a chance that we will reuse create2 factory from the localhost chain.
env.removeFromInit('CONTRACTS_CREATE2_FACTORY_ADDR');
}

if (results.l1Chain !== BaseNetwork.LOCALHOST) {
const connectionsQuestions: BasePromptOptions[] = [
{
Expand Down Expand Up @@ -195,6 +203,7 @@ async function setHyperchainMetadata() {
feeReceiver = ethers.Wallet.createRandom();
feeReceiverAddress = feeReceiver.address;
} else {
console.log(warning('The private keys for these wallets must be different from each other!\n'));
const keyQuestions: BasePromptOptions[] = [
{
message: 'Private key of the L1 Deployer (the one that deploys the contracts)',
Expand Down Expand Up @@ -788,7 +797,8 @@ async function configDemoHyperchain(cmd: Command) {
testTokens: {
deploy: deployTestTokens,
args: ['--private-key', deployerPrivateKey, '--envFile', process.env.CHAIN_ETH_NETWORK!]
}
},
deployerPrivateKeyArgs: ['--private-key', deployerPrivateKey]
};

if (!cmd.skipEnvSetup) {
Expand Down
19 changes: 14 additions & 5 deletions infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ const success = chalk.green;
const timestamp = chalk.grey;

export async function init(initArgs: InitArgs = DEFAULT_ARGS) {
const { skipSubmodulesCheckout, skipEnvSetup, testTokens, governorPrivateKeyArgs, deployerL2ContractInput } =
initArgs;
const {
skipSubmodulesCheckout,
skipEnvSetup,
testTokens,
governorPrivateKeyArgs,
deployerPrivateKeyArgs,
deployerL2ContractInput
} = initArgs;

if (!process.env.CI && !skipEnvSetup) {
await announced('Pulling images', docker.pull());
Expand All @@ -41,10 +47,10 @@ export async function init(initArgs: InitArgs = DEFAULT_ARGS) {
if (testTokens.deploy) {
await announced('Deploying localhost ERC20 tokens', run.deployERC20('dev', '', '', '', testTokens.args));
}
await announced('Deploying L1 verifier', contract.deployVerifier([]));
await announced('Deploying L1 verifier', contract.deployVerifier(deployerPrivateKeyArgs));
await announced('Reloading env', env.reload());
await announced('Running server genesis setup', server.genesisFromSources());
await announced('Deploying L1 contracts', contract.redeployL1(governorPrivateKeyArgs));
await announced('Deploying L1 contracts', contract.redeployL1(deployerPrivateKeyArgs));
await announced('Initializing validator', contract.initializeValidator(governorPrivateKeyArgs));
await announced(
'Deploying L2 contracts',
Expand Down Expand Up @@ -135,6 +141,7 @@ export interface InitArgs {
skipSubmodulesCheckout: boolean;
skipEnvSetup: boolean;
governorPrivateKeyArgs: any[];
deployerPrivateKeyArgs: any[];
deployerL2ContractInput: {
args: any[];
includePaymaster: boolean;
Expand All @@ -150,6 +157,7 @@ const DEFAULT_ARGS: InitArgs = {
skipSubmodulesCheckout: false,
skipEnvSetup: false,
governorPrivateKeyArgs: [],
deployerPrivateKeyArgs: [],
deployerL2ContractInput: { args: [], includePaymaster: true, includeL2WETH: true },
testTokens: { deploy: true, args: [] }
};
Expand All @@ -164,7 +172,8 @@ export const initCommand = new Command('init')
skipEnvSetup: cmd.skipEnvSetup,
governorPrivateKeyArgs: [],
deployerL2ContractInput: { args: [], includePaymaster: true, includeL2WETH: true },
testTokens: { deploy: true, args: [] }
testTokens: { deploy: true, args: [] },
deployerPrivateKeyArgs: []
};
await init(initArgs);
});
Expand Down
Loading