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

feat(upgrade): update tool to generate calldata for setting new chain creation params #3117

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
58 changes: 56 additions & 2 deletions infrastructure/protocol-upgrade/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ import * as path from 'path';
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

export enum Action {
Add = 0,
Replace = 1,
Remove = 2
}

export interface DiamondCutData {
facetCuts: FacetCut[];
initAddress: string;
initCalldata: string;
}

export interface ChainCreationParams {
genesisUpgrade: string;
genesisBatchHash: string;
genesisIndexRepeatedStorageChanges: number;
genesisBatchCommitment: string;
diamondCut: DiamondCutData;
}

export interface ForceDeployment {
// The bytecode hash to put on an address
bytecodeHash: BytesLike;
Expand Down Expand Up @@ -186,6 +200,10 @@ export function prepareUpgradeCalldata(
upgradeAddress: string,
facetCuts: FacetCut[],
zksyncAddress: string,
genesisUpgradeAddress: string,
genesisBatchHash: string,
genesisIndexRepeatedStorageChanges: number,
genesisBatchCommitment: string,
prepareDirectOperation?: boolean,
chainId?: string
) {
Expand All @@ -194,6 +212,21 @@ export function prepareUpgradeCalldata(
initAddress: upgradeAddress,
initCalldata
};

let chainCreationDiamondCut: DiamondCutData = {
facetCuts: facetCuts.filter((cut) => cut.action == Action.Add),
initAddress: genesisUpgradeAddress,
initCalldata: '0x'
};

let chainCreationParams: ChainCreationParams = {
genesisUpgrade: genesisUpgradeAddress,
genesisBatchHash,
genesisIndexRepeatedStorageChanges,
genesisBatchCommitment,
diamondCut: chainCreationDiamondCut
};

// Prepare calldata for STM
let stm = new StateTransitionManagerFactory();
const stmUpgradeCalldata = stm.interface.encodeFunctionData('setNewVersionUpgrade', [
Expand All @@ -203,6 +236,10 @@ export function prepareUpgradeCalldata(
newProtocolVersion
]);

const stmSetChainCreationCalldata = stm.interface.encodeFunctionData('setChainCreationParams', [
chainCreationParams
]);

// Prepare calldata for upgrading diamond proxy
let adminFacet = new AdminFacetFactory();
const diamondProxyUpgradeCalldata = adminFacet.interface.encodeFunctionData('upgradeChainFromVersion', [
Expand All @@ -215,7 +252,8 @@ export function prepareUpgradeCalldata(
let result: any = {
stmUpgradeCalldata,
chainAdminUpgradeCalldata,
diamondCut
diamondCut,
stmSetChainCreationCalldata
};

if (prepareDirectOperation) {
Expand All @@ -242,6 +280,10 @@ export function buildDefaultUpgradeTx(
upgradeTimestamp,
zksyncAddress,
postUpgradeCalldataFlag,
genesisUpgradeAddress,
genesisBatchHash,
genesisIndexRepeatedStorageChanges,
genesisBatchCommitment,
prepareDirectOperation?,
chainId?
) {
Expand Down Expand Up @@ -329,6 +371,10 @@ export function buildDefaultUpgradeTx(
upgradeAddress,
facetCuts,
zksyncAddress,
genesisUpgradeAddress,
genesisBatchHash,
genesisIndexRepeatedStorageChanges,
genesisBatchCommitment,
prepareDirectOperation,
chainId
);
Expand Down Expand Up @@ -376,7 +422,11 @@ command
.option('--zksync-address <zksyncAddress>')
.option('--chain-id <chainId>')
.option('--prepare-direct-operation <prepareDirectOperation>')
.option('--post-upgrade-calldata')
.option('--post-upgrade-calldata <postUpgradeCalldata>')
.option('--genesis-upgrade-address <genesisUpgradeAddress>')
.option('--genesis-batch-hash <genesisBatchHash>')
.option('--genesis-index-repeated-storage-changes <genesisIndexRepeatedStorageChanges>')
.option('--genesis-batch-commitment <genesisBatchCommitment>')
.action(async (options) => {
buildDefaultUpgradeTx(
options.environment,
Expand All @@ -386,6 +436,10 @@ command
options.upgradeTimestamp,
options.zksyncAddress,
options.postUpgradeCalldata,
options.genesisUpgradeAddress,
options.genesisBatchHash,
options.genesisIndexRepeatedStorageChanges,
options.genesisBatchCommitment,
options.prepareDirectOperation,
options.chainId
);
Expand Down
Loading