Skip to content

Conversation

@laisolizq
Copy link
Collaborator

  • Add script upgrade etrog -> sovereign

@laisolizq laisolizq marked this pull request as draft September 18, 2025 15:28
address _emergencyBridgePauser,
address _emergencyBridgeUnpauser,
address _proxiedTokensManager
) public virtual reinitializer(3) {
Copy link
Collaborator

@ignasirv ignasirv Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to add the getInitializedVersion as it is done in the AgglayerBridge initialize; check initializer version is 1 (or not zero) and also check that current values to update are zero.

@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 6277218 to 1207da1 Compare September 22, 2025 09:28
@laisolizq laisolizq requested a review from ignasirv September 22, 2025 09:28
@krlosMata
Copy link
Member

Add localBalanceTree initialization

* @dev The key is generated as keccak256(abi.encodePacked(originNetwork, originTokenAddress))
* @param amount The amount to set for the local balance tree leaf
*/
function _setLocalBalanceTreeInitialize(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replicating the function setLocalBalanceTree I would move setLocalBalanceTree code to an internal function _setLocalBalanceTree and call it from initialize, this way you will be saving a lot of bytecode

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the idea was not to change the AgglayerBridgeL2 contract, so I implemented this function here.
Is it okay to change it? Should I modify it, or leave it as it is?
@krlosMata

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, since it’s an internal change that doesn’t affect functionality, I’ll go ahead and make the change. If anyone thinks otherwise, please let me know ^^

@laisolizq laisolizq changed the base branch from feature/reorg-v2 to feature/v12 October 3, 2025 15:16
@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 7d700a2 to 3c1c8e2 Compare October 3, 2025 16:04
@laisolizq laisolizq marked this pull request as ready for review October 8, 2025 15:54
* @param _emergencyBridgeUnpauser emergency bridge unpauser address, allowed to be zero if the chain wants to disable the feature to unpause the bridge
* @param _proxiedTokensManager address of the proxied tokens manager
*/
function initializeBridgeZkEVM(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funciton name seems uncoherent with contract name
maybe InitializeFromEtrog?

@invocamanman
Copy link
Collaborator

JUst to double check, are we sure that the PolygonZkEVMBridgeV2Pessimistic is the contract deployed on those networks?¿

@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 7326371 to 2862a36 Compare October 10, 2025 08:23
@laisolizq
Copy link
Collaborator Author

laisolizq commented Oct 10, 2025

JUst to double check, are we sure that the PolygonZkEVMBridgeV2Pessimistic is the contract deployed on those networks?¿

I compared the two bytecodes with a script (comparing only strings), and it says everything is the same except for the last few bytes (which, according to what I’ve found, is a metadata hash that shouldn’t matter). Is that right? @invocamanman

@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 2862a36 to 15dafbb Compare October 10, 2025 08:50
@krlosMata
Copy link
Member

@codex review

@krlosMata krlosMata requested a review from Copilot October 10, 2025 09:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a script for upgrading L2 bridge and global exit root contracts from Etrog to Sovereign versions, facilitating the migration from PolygonZkEVMBridgeV2 to AgglayerBridgeL2 and PolygonZkEVMGlobalExitRootL2 to AgglayerGERL2.

Key changes:

  • Upgrade script with timelock operation generation for both bridge and GER contracts
  • Test suite for validation via shallow fork testing
  • Contract implementation supporting upgrade from Etrog with initialization of new parameters

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
upgrade/upgradeEtrogSovereign/upgradeEtrogToSovereign.ts Main upgrade script deploying implementations and generating timelock operations
upgrade/upgradeEtrogSovereign/test/shallowForkUpgrade.test.ts Shallow fork test validating contract upgrades and parameter initialization
upgrade/upgradeEtrogSovereign/getLBT.ts Utility script for retrieving Local Balance Tree data from NewWrappedToken events
upgrade/upgradeEtrogSovereign/README.md Documentation for upgrade process and configuration
upgrade/upgradeEtrogSovereign/upgrade_parameters.json.example Example configuration file with required parameters
contracts/sovereignChains/AgglayerBridgeL2FromEtrog.sol Bridge contract implementation supporting upgrade from Etrog version
contracts/sovereignChains/AgglayerBridgeL2.sol Internal method extraction for Local Balance Tree initialization
test/contractsv2/AgglayerBridgeL2FromEtrogUpgrade.test.ts Unit test for upgrade functionality
hardhat.config.ts Compilation configuration for new contract
upgrade/upgradeEtrogSovereign/.gitignore Ignore file for generated LBT data

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


dotenv.config({ path: path.resolve(__dirname, '../../.env') });

dotenv.config({ path: path.resolve(__dirname, '../../.env') });
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate dotenv.config() call - this line is identical to line 22 and should be removed.

Suggested change
dotenv.config({ path: path.resolve(__dirname, '../../.env') });

Copilot uses AI. Check for mistakes.
dotenv.config({ path: path.resolve(__dirname, '../../.env') });

async function main() {
// Asser upgrade version
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Asser' to 'Assert'.

Suggested change
// Asser upgrade version
// Assert upgrade version

Copilot uses AI. Check for mistakes.
// load timelock
const timelockContractFactory = await ethers.getContractFactory('PolygonZkEVMTimelock', deployer);
const timelockContract = (await timelockContractFactory.attach(timelockAddress)) as TimelockController;
// take params delay, or minimum timelock dela
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'dela' to 'delay'.

Suggested change
// take params delay, or minimum timelock dela
// take params delay, or minimum timelock delay

Copilot uses AI. Check for mistakes.
import upgradeParams from './upgrade_parameters.json';
import { logger } from '../../src/logger';

export async function getLBT(contractAddress) {
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type annotation for contractAddress parameter. Should be 'contractAddress: string'.

Suggested change
export async function getLBT(contractAddress) {
export async function getLBT(contractAddress: string) {

Copilot uses AI. Check for mistakes.
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

@@ -0,0 +1,14 @@
{
"bridgeL2": "0x..",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we create a separate object with: initiaizationParameters ?
Just to be more explicit

import { addInfoOutput } from '../../tools/utils';

// You can replace this import with the actual values obtained from getLBT
import { originNetwork, originTokenAddress, totalSupply } from './initializeLBT.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no example of this file.
Reminder that this file could be generated from getLBT.ts tool or from the agglayer-node or any other tool

logger.info('Create schedule and execute operation');
logger.info('Operation Bridge');
// Get LBT initialization parameters (if not imported, import getLBT and use it)
// const { originNetwork, originTokenAddress, totalSupply } = await getLBT(bridgeL2, creationBridgeL2Block);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several comments in the files. It should be cleaned

@@ -0,0 +1,79 @@
import { ethers } from 'hardhat';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another tool. The upgrade can take the LBT from any source.
I'd create a separate tool to synch the LBT.


dotenv.config({ path: path.resolve(__dirname, '../../.env') });

const pathOutputJson = path.join(__dirname, './upgrade_output.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add timestamp here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d rather not add a timestamp, since from the test I retrieve this upgrade_output in order to use that data within the test.
I think I’ve seen all the upgrade tests done this way.

@@ -0,0 +1 @@
initializeLBT.json No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing upgrade_output_*.json

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is added to the .gitignore in the root of the project. Even so, if I add a timestamp to it, I’ll also add it to the .gitignore of this tool.

@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from a0a3ab9 to e49d164 Compare October 10, 2025 13:04
@laisolizq laisolizq requested a review from krlosMata October 10, 2025 13:04
Comment on lines 44 to 46
uint32[] memory originNetwork,
address[] memory originTokenAddress,
uint256[] memory amount
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this and also the internal function, to array i think might be better
e.g originNetworkArray

Comment on lines 37 to 38
* @param _proxiedTokensManager address of the proxied tokens manager
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

natspec

Comment on lines +1 to +23
/* eslint-disable no-await-in-loop, no-use-before-define, no-lonely-if */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved */
import { expect } from 'chai';
import path = require('path');

import * as dotenv from 'dotenv';
import { ethers, upgrades } from 'hardhat';
import { time, reset, setBalance, mine } from '@nomicfoundation/hardhat-network-helpers';
import {
PolygonZkEVMTimelock,
AgglayerGERL2,
AgglayerBridgeL2,
PolygonZkEVMBridgeV2Pessimistic,
LegacyAgglayerGERL2,
} from '../../../typechain-types';
import upgradeParams from '../upgrade_parameters.json';
import upgradeOutput from '../upgrade_output.json';
import { logger } from '../../../src/logger';
import { checkParams } from '../../../src/utils';
import { ProxyAdmin } from '../../../typechain-types/@openzeppelin/contracts4/proxy/transparent';

dotenv.config({ path: path.resolve(__dirname, '../../.env') });

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shadow fork ahhaha

@laisolizq laisolizq marked this pull request as draft October 15, 2025 08:48
@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 919cc16 to 26d5f01 Compare October 16, 2025 09:54
@laisolizq laisolizq marked this pull request as ready for review October 16, 2025 16:22
@laisolizq laisolizq force-pushed the feature/upgrade-etrog-sovereign branch from 2d285ae to ff874a1 Compare October 16, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants