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

Create new rollup script #361

Merged
merged 12 commits into from
Dec 12, 2024
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ create_rollup_parameters.json
docker/deploymentOutput

.DS_Store

tools/createSovereignGenesisWithHardhat/genesis-sovereign_hardhat.json
ignasirv marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions contracts/PolygonZkEVMBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ contract PolygonZkEVMBridge is
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
* @param token Token address, 0 address is reserved for ether
* @param token Token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param forceUpdateGlobalExitRoot Indicates if the new global exit root is updated or not
* @param permitData Raw data of the call `permit` of the token
*/
Expand Down Expand Up @@ -306,7 +306,7 @@ contract PolygonZkEVMBridge is
* @param mainnetExitRoot Mainnet exit root
* @param rollupExitRoot Rollup exit root
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
Expand Down Expand Up @@ -483,7 +483,7 @@ contract PolygonZkEVMBridge is
* Since the metadata has relevance in the address deployed, this function will not return a valid
* wrapped address if the metadata provided is not the original one.
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param name Name of the token
* @param symbol Symbol of the token
* @param decimals Decimals of the token
Expand Down Expand Up @@ -520,7 +520,7 @@ contract PolygonZkEVMBridge is
/**
* @notice Returns the address of a wrapper using the token information if already exist
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
*/
function getTokenWrappedAddress(
uint32 originNetwork,
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/DepositContractMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract DepositContractMock is DepositContract {
* @notice Given the leaf data returns the leaf value
* @param leafType Leaf type
* @param originNetwork Origin Network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param destinationNetwork Destination network
* @param destinationAddress Destination address
* @param amount Amount of tokens
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/PolygonZkEVMBridgeMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract PolygonZkEVMBridgeMock is PolygonZkEVMBridge, OwnableUpgradeable {
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
* @param token Token address, 0 address is reserved for ether
* @param token Token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param permitData Raw data of the call `permit` of the token
*/
function bridgeAsset(
Expand Down
8 changes: 4 additions & 4 deletions contracts/v2/PolygonZkEVMBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ contract PolygonZkEVMBridgeV2 is
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
* @param token Token address, 0 address is reserved for ether
* @param token Token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param forceUpdateGlobalExitRoot Indicates if the new global exit root is updated or not
* @param permitData Raw data of the call `permit` of the token
*/
Expand Down Expand Up @@ -689,7 +689,7 @@ contract PolygonZkEVMBridgeV2 is
* Since the metadata has relevance in the address deployed, this function will not return a valid
* wrapped address if the metadata provided is not the original one.
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param name Name of the token
* @param symbol Symbol of the token
* @param decimals Decimals of the token
Expand Down Expand Up @@ -726,7 +726,7 @@ contract PolygonZkEVMBridgeV2 is
/**
* @notice Returns the address of a wrapper using the token information if already exist
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
*/
function getTokenWrappedAddress(
uint32 originNetwork,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ contract PolygonZkEVMBridgeV2 is
* Since the metadata has relevance in the address deployed, this function will not return a valid
* wrapped address if the metadata provided is not the original one.
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param token Address of the token to calculate the wrapper address
*/
function calculateTokenWrapperAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract PolygonPessimisticConsensus is
* @param _globalExitRootManager Global exit root manager address
* @param _pol POL token address
* @param _bridgeAddress Bridge address
* @param _rollupManager Global exit root manager address
* @param _rollupManager Rollup manager address
*/
constructor(
IPolygonZkEVMGlobalExitRootV2 _globalExitRootManager,
Expand Down
2 changes: 1 addition & 1 deletion contracts/v2/lib/DepositContractV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DepositContractV2 is ReentrancyGuardUpgradeable, DepositContractBase {
* @notice Given the leaf data returns the leaf value
* @param leafType Leaf type --> [0] transfer Ether / ERC20 tokens, [1] message
* @param originNetwork Origin Network
* @param originAddress [0] Origin token address, 0 address is reserved for ether, [1] msg.sender of the message
* @param originAddress [0] Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token, [1] msg.sender of the message
* @param destinationNetwork Destination network
* @param destinationAddress Destination address
* @param amount [0] Amount of tokens/ether, [1] Amount of ether
Expand Down
2 changes: 1 addition & 1 deletion contracts/v2/mocks/BridgeReceiverMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract BridgeReceiverMock {
* @param mainnetExitRoot Mainnet exit root
* @param rollupExitRoot Rollup exit root
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
Expand Down
8 changes: 4 additions & 4 deletions contracts/v2/sovereignChains/BridgeL2SovereignChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ contract BridgeL2SovereignChain is
* @notice The tokenInfoToWrappedToken mapping value is replaced by the new sovereign address but it's not the case for the wrappedTokenToTokenInfo map where the value is added, this way user will always be able to withdraw their tokens
* @notice The number of decimals between sovereign token and origin token is not checked, it doesn't affect the bridge functionality but the UI.
* @param originNetwork Origin network
* @param originTokenAddress Origin token address, 0 address is reserved for ether
* @param originTokenAddress Origin token address, 0 address is reserved for gas token address. If WETH address is zero, means this gas token is ether, else means is a custom erc20 gas token
* @param sovereignTokenAddress Address of the sovereign wrapped token
* @param isNotMintable Flag to indicate if the wrapped token is not mintable
*/
Expand Down Expand Up @@ -463,7 +463,7 @@ contract BridgeL2SovereignChain is

/**
* @notice Function to check if an index is claimed or not
* @dev function override to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
* @dev function overridden to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
* @param leafIndex Index
* @param sourceBridgeNetwork Origin network
*/
Expand All @@ -482,7 +482,7 @@ contract BridgeL2SovereignChain is

/**
* @notice Function to check that an index is not claimed and set it as claimed
* @dev function override to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
* @dev function overridden to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
* @param leafIndex Index
* @param sourceBridgeNetwork Origin network
*/
Expand All @@ -503,7 +503,7 @@ contract BridgeL2SovereignChain is

/**
* @notice Function to call token permit method of extended ERC20
* @dev We override this function from PolygonZkEVMBridgeV2 to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
* @dev function overridden from PolygonZkEVMBridgeV2 to improve a bit the performance and bytecode not checking unnecessary conditions for sovereign chains context
+ @param token ERC20 token address
* @param amount Quantity that is expected to be allowed
* @param permitData Raw data of the call `permit` of the token
Expand Down
12 changes: 6 additions & 6 deletions deployment/helpers/deployment-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function deployPolygonZkEVMDeployer(
}

export async function create2Deployment(
polgonZKEVMDeployerContract: PolygonZkEVMDeployer,
polygonZKEVMDeployerContract: PolygonZkEVMDeployer,
salt: string,
deployTransaction: string,
dataCall: string | null,
Expand All @@ -90,7 +90,7 @@ export async function create2Deployment(

// Precalculate create2 address
const precalculatedAddressDeployed = ethers.getCreate2Address(
polgonZKEVMDeployerContract.target as string,
polygonZKEVMDeployerContract.target as string,
salt,
hashInitCode
);
Expand All @@ -104,7 +104,7 @@ export async function create2Deployment(
// Deploy using create2 and call
if (hardcodedGasLimit) {
const populatedTransaction =
await polgonZKEVMDeployerContract.deployDeterministicAndCall.populateTransaction(
await polygonZKEVMDeployerContract.deployDeterministicAndCall.populateTransaction(
amount,
salt,
deployTransaction,
Expand All @@ -114,21 +114,21 @@ export async function create2Deployment(
await (await deployer.sendTransaction(populatedTransaction)).wait();
} else {
await (
await polgonZKEVMDeployerContract.deployDeterministicAndCall(amount, salt, deployTransaction, dataCall)
await polygonZKEVMDeployerContract.deployDeterministicAndCall(amount, salt, deployTransaction, dataCall)
).wait();
}
} else {
// Deploy using create2
if (hardcodedGasLimit) {
const populatedTransaction = await polgonZKEVMDeployerContract.deployDeterministic.populateTransaction(
const populatedTransaction = await polygonZKEVMDeployerContract.deployDeterministic.populateTransaction(
amount,
salt,
deployTransaction
);
populatedTransaction.gasLimit = hardcodedGasLimit;
await (await deployer.sendTransaction(populatedTransaction)).wait();
} else {
await (await polgonZKEVMDeployerContract.deployDeterministic(amount, salt, deployTransaction)).wait();
await (await polygonZKEVMDeployerContract.deployDeterministic(amount, salt, deployTransaction)).wait();
}
}
return [precalculatedAddressDeployed, true];
Expand Down
9 changes: 7 additions & 2 deletions deployment/v2/4_createRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ async function main() {
) {
// Get token metadata
gasTokenMetadata = await polygonZkEVMBridgeContract.getTokenMetadata(createRollupParameters.gasTokenAddress);
outputJson.gasTokenMetadata = gasTokenMetadata;
// If gas token metadata includes `0x124e4f545f56414c49445f454e434f44494e47 (NOT_VALID_ENCODING)` means there is no erc20 token deployed at the selected gas token network
if (gasTokenMetadata.includes("124e4f545f56414c49445f454e434f44494e47")) {
throw new Error(
Expand All @@ -293,7 +294,7 @@ async function main() {
gasTokenNetwork = 0;
gasTokenMetadata = "0x";
}

outputJson.gasTokenAddress = gasTokenAddress;
const nonce = await currentProvider.getTransactionCount(rollupManagerContract.target);
const newZKEVMAddress = ethers.getCreateAddress({
from: rollupManagerContract.target as string,
Expand Down Expand Up @@ -376,7 +377,9 @@ async function main() {
}

let batchData = "";
// If is vanilla client, replace genesis by sovereign contracts, else, inject initialization batch
/**
If the system is running a "vanilla client" (i.e., a basic, unmodified Ethereum client or rollup setup), the genesis block should include the deployment of the sovereign contracts, and these contracts should already be initialized with their required initial state and configurations. This means that the genesis block will contain the initial state for these contracts, allowing the system to start running without needing any additional initialization steps. However, for other rollups, additional configuration is needed. In this case, instead of having everything pre-initialized in the genesis block, we must inject an "initialization batch" into the genesis file. This batch will contain specific instructions for initializing the contracts at the time of rollup deployment. The injected initialization batch allows the system to be configured dynamically during deployment.
*/
if (isVanillaClient) {
const initializeParams = {
rollupID: rollupID,
Expand Down Expand Up @@ -479,6 +482,8 @@ async function main() {
outputJson.rollupAddress = newZKEVMAddress;
outputJson.verifierAddress = verifierContract.target;
outputJson.consensusContract = consensusContract;
outputJson.consensusContractAddress = PolygonconsensusContract.target;
outputJson.rollupTypeId = newRollupTypeID;

// Rewrite updated genesis in case of vanilla client
if (isVanillaClient) {
Expand Down
5 changes: 4 additions & 1 deletion deployment/v2/utils/updateVanillaGenesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ async function updateVanillaGenesis(genesis, chainID, initializeParams) {
await batch2.executeTxs();
await zkEVMDB2.consolidate(batch2);

// Update bridgeProxy storage
// Update bridgeProxy storage and nonce
bridgeProxy.contractName = bridgeContractName + " proxy";
bridgeProxy.storage = await zkEVMDB2.dumpStorage(bridgeProxy.address);
// Update nonce, in case weth is deployed at initialize, it is increased
const bridgeProxyState = await zkEVMDB2.getCurrentAccountState(bridgeProxy.address)
bridgeProxy.nonce = String(Number(bridgeProxyState.nonce));
// If bridge initialized with a zero sovereign weth address and a non zero gas token, we should add created erc20 weth contract to the genesis
let wethAddress;
if (
Expand Down
Loading