Skip to content

Commit

Permalink
Merge branch 'main' into ya-prover-autoscaler-old-release
Browse files Browse the repository at this point in the history
  • Loading branch information
yorik authored Oct 17, 2024
2 parents e0435aa + 899ffc0 commit 102d389
Showing 1 changed file with 56 additions and 2 deletions.
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

0 comments on commit 102d389

Please sign in to comment.