Skip to content

Commit

Permalink
Improve upgrade presimistic script
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Nov 4, 2024
1 parent d5b0cc1 commit 3ff477a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 43 deletions.
85 changes: 45 additions & 40 deletions deployment/v2/utils/updateVanillaGenesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
const oldBridge = genesis.genesis.find(function (obj) {
return obj.contractName == "PolygonZkEVMBridgeV2";
});
const deployGERData = await gerFactory.getDeployTransaction(oldBridge.address);
// Get bridge proxy address
const bridgeProxy = genesis.genesis.find(function (obj) {
return obj.contractName == "PolygonZkEVMBridgeV2 proxy";
});
const deployGERData = await gerFactory.getDeployTransaction(bridgeProxy.address);
injectedTx.data = deployGERData.data;
txObject = ethers.Transaction.from(injectedTx);
const txDeployGER = processorUtils.rawTxToCustomRawTx(txObject.serialized);
Expand Down Expand Up @@ -142,10 +146,6 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
sovereignWETHAddressIsNotMintable,
]
);
// Get bridge proxy address
const bridgeProxy = genesis.genesis.find(function (obj) {
return obj.contractName == "PolygonZkEVMBridgeV2 proxy";
});
injectedTx.to = bridgeProxy.address;
injectedTx.data = initializeData;
txObject = ethers.Transaction.from(injectedTx);
Expand Down Expand Up @@ -264,10 +264,15 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
// To get the key we encode the key of the mapping with the position in the mapping
if (sovereignWETHAddressIsNotMintable) {
const mappingSlot = 162; // Slot of the mapping in the bridge contract
const key = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [sovereignWETHAddress, mappingSlot]));
expect(
bridgeProxy.storage[key]
).to.equal("0x0000000000000000000000000000000000000000000000000000000000000001");
const key = ethers.keccak256(
ethers.AbiCoder.defaultAbiCoder().encode(
["address", "uint256"],
[sovereignWETHAddress, mappingSlot]
)
);
expect(bridgeProxy.storage[key]).to.equal(
"0x0000000000000000000000000000000000000000000000000000000000000001"
);
}
} else {
// Storage value for WETH address (ony if network with native gas token), deployed at bridge initialization
Expand All @@ -290,39 +295,39 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
"0x5745544800000000000000000000000000000000000000000000000000000008"
);
}
}

// Storage values for gasTokenMetadata, its a bytes variable
let offset = 2 + 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142a"]).to.include(
gasTokenMetadata.slice(2, offset)
);
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142b"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142c"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142d"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142e"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142f"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db71430"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
// Storage values for gasTokenMetadata, its a bytes variable
let offset = 2 + 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142a"]).to.include(
gasTokenMetadata.slice(2, offset)
);
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142b"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142c"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142d"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142e"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db7142f"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
offset += 64;
expect(bridgeProxy.storage["0x9930d9ff0dee0ef5ca2f7710ea66b8f84dd0f5f5351ecffe72b952cd9db71430"]).to.include(
gasTokenMetadata.slice(offset, offset + 64)
);
}

// Check bridgeAddress is included in ger bytecode
expect(oldGer.bytecode).to.include(oldBridge.address.toLowerCase().slice(2));
// Check bridge proxy Address is included in ger bytecode
expect(oldGer.bytecode).to.include(bridgeProxy.address.toLowerCase().slice(2));

// Update bridgeProxy storage
gerProxy.contractName = gerContractName + " proxy";
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/v2/create_rollup_parameters_docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"adminZkEVM": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"forkID": 11,
"consensusContract": "PolygonPessimisticConsensus",
"gasTokenAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"gasTokenAddress": "deployed",
"deployerPvtKey": "",
"maxFeePerGas": "",
"maxPriorityFeePerGas": "",
Expand Down
45 changes: 43 additions & 2 deletions upgrade/upgradePessimistic/upgradePessimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {expect} from "chai";
import path = require("path");
import fs = require("fs");
import {utils} from "ffjavascript";

import * as dotenv from "dotenv";
dotenv.config({path: path.resolve(__dirname, "../../.env")});
Expand Down Expand Up @@ -125,7 +126,11 @@ async function main() {
const operationRollupManager = genOperation(
proxyAdmin.target,
0, // value
proxyAdmin.interface.encodeFunctionData("upgrade", [rollupManagerAddress, implRollupManager]), // data
proxyAdmin.interface.encodeFunctionData("upgradeAndCall", [
rollupManagerAddress,
implRollupManager,
PolygonRollupManagerFactory.interface.encodeFunctionData("initialize", []),
]), // data
ethers.ZeroHash, // predecessor
salt // salt
);
Expand Down Expand Up @@ -157,7 +162,43 @@ async function main() {
executeData,
timelockContractAddress: timelockAddress,
};
fs.writeFileSync(pathOutputJson, JSON.stringify(outputJson, null, 1));

// Decode the scheduleData for better readability
const timelockTx = timelockContractFactory.interface.parseTransaction({data: scheduleData});
const paramsArray = timelockTx?.fragment.inputs;
const objectDecoded = {};

for (let i = 0; i < paramsArray?.length; i++) {
const currentParam = paramsArray[i];
objectDecoded[currentParam.name] = timelockTx?.args[i];

if (currentParam.name == "payloads") {
// for each payload
const payloads = timelockTx?.args[i];
for (let j = 0; j < payloads.length; j++) {
const data = payloads[j];
const decodedProxyAdmin = proxyAdmin.interface.parseTransaction({
data,
});

const resultDecodeProxyAdmin = {};
resultDecodeProxyAdmin.signature = decodedProxyAdmin?.signature;
resultDecodeProxyAdmin.selector = decodedProxyAdmin?.selector;

const paramsArrayData = decodedProxyAdmin?.fragment.inputs;

for (let n = 0; n < paramsArrayData?.length; n++) {
const currentParam = paramsArrayData[n];
resultDecodeProxyAdmin[currentParam.name] = decodedProxyAdmin?.args[n];
}
objectDecoded[`decodePayload_${j}`] = resultDecodeProxyAdmin;
}
}
}

outputJson.decodedScheduleData = objectDecoded;

fs.writeFileSync(pathOutputJson, JSON.stringify(utils.stringifyBigInts(outputJson), null, 1));
}

main().catch((e) => {
Expand Down

0 comments on commit 3ff477a

Please sign in to comment.