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(registration): Add Chain registrar contract #1064

Open
wants to merge 55 commits into
base: dev
Choose a base branch
from

Conversation

Deniallugo
Copy link
Contributor

@Deniallugo Deniallugo commented Nov 14, 2024

What ❔

Add Chain registrar contracts, that allow partners to register their chains and then configure their chain from L1

Why ❔

For making our registration process a bit more transparent and later on make it even easier

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

Deniallugo and others added 30 commits September 10, 2024 15:10
Signed-off-by: Danil <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
Signed-off-by: Danil <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
Signed-off-by: Danil <[email protected]>
Co-authored-by: Bence Haromi <[email protected]>
Co-authored-by: Grzegorz Prusak <[email protected]>
Co-authored-by: Moshe Shababo <[email protected]>
Co-authored-by: Akosh Farkash <[email protected]>
Co-authored-by: Bruno França <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
Co-authored-by: Roman Brodetski <[email protected]>
Co-authored-by: vladbochok <[email protected]>
Co-authored-by: Stanislav Bezkorovainyi <[email protected]>
Co-authored-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Co-authored-by: otani <[email protected]>
Co-authored-by: Zach Kolodny <[email protected]>
…sserter-command

fix: add deploy timestamp asserter command
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Signed-off-by: Danil <[email protected]>
Copy link
Member

@vladbochok vladbochok left a comment

Choose a reason for hiding this comment

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

Please update comments to follow napspec specificaion. Comment all function parameters by /// @param.

Signed-off-by: Danil <[email protected]>
@Deniallugo Deniallugo force-pushed the deniallugo-chain-registrator branch 4 times, most recently from d831ef1 to 1fabb69 Compare November 25, 2024 09:05
Signed-off-by: Danil <[email protected]>
@Deniallugo Deniallugo changed the base branch from release-v25-protocol-defense to dev November 25, 2024 09:33
@Deniallugo Deniallugo changed the title [WIP] Chain registrar feat(registration): Add Chain registrar contract Nov 25, 2024
Signed-off-by: Danil <[email protected]>
Copy link

Coverage after merging deniallugo-chain-registrator into dev will be

86.64%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
contracts/bridge
   L1ERC20Bridge.sol81.82%80%75%83.87%62, 70, 70–71, 73–74
   L1SharedBridge.sol78.11%63.89%84.21%81.58%101–102, 109–110, 117–118, 125, 125–126, 133–134, 179–180, 194–195, 203–204, 216–217, 219–220, 231, 231, 231–235, 235–236, 238, 243–245, 245–246, 248–250, 250–251, 253, 265, 274, 274–275, 283–284, 286–287, 298–299, 454–455, 457–458, 589–590, 606–607, 617–618, 633–634, 730–731, 972, 977
contracts/bridgehub
   Bridgehub.sol89.29%74.07%100%91.49%100–101, 112–113, 132–133, 155–156, 158–159, 332–333, 49, 63–64
contracts/chain-registrar
   ChainRegistrar.sol61.76%40%50%68%103–105, 145–146, 166–167, 175–176, 183–184
contracts/common
   ReentrancyGuard.sol90%66.67%100%92.86%78–79
contracts/common/libraries
   L2ContractHelper.sol42.86%0%50%52.63%25–26, 31–32, 35–36, 50, 52, 52–53, 57, 57–58, 66
   SemVer.sol100%100%100%100%
   UncheckedMath.sol100%100%100%100%
   UnsafeBytes.sol100%100%100%100%
contracts/governance
   ChainAdmin.sol64.29%50%60%68.42%27–28, 39–40, 78, 78–79, 81
   Governance.sol91.67%94.74%95%89.86%45, 45–46, 49, 51–52, 54–55
contracts/state-transition
   StateTransitionManager.sol59.48%35.71%50%65.42%101, 106–110, 116, 149–150, 152–153, 155–156, 158–159, 201, 203–204, 209, 211, 211–212, 215–217, 219–220, 255, 275, 289, 294, 299, 304, 309, 314, 319, 386, 386–387, 390, 455–456, 79, 92, 92–93
   TestnetVerifier.sol44.44%33.33%50%50%16, 16, 16, 32
   ValidatorTimelock.sol95.89%83.33%100%95.83%241, 82–83
   Verifier.sol89.88%35.71%96.30%90.93%1673–1674, 287–302, 305–308, 311–318, 321–328, 331–332, 335–336, 339, 384–385, 395–396, 406–407, 417–418, 428–429, 444–445, 454, 454–455, 904–905
contracts/state-transition/chain-deps
   DiamondInit.sol77.55%45.45%100%86.11%34–35, 37–38, 40–41, 43–44, 46–47, 71
   DiamondProxy.sol92.31%75%100%100%16, 27
contracts/state-transition/chain-deps/facets
   Admin.sol86.21%72.73%92.31%87.30%109, 109–110, 112–113, 178, 180, 83–84, 94–95
   Executor.sol82.04%63.41%84.38%87.90%137–138, 192, 197, 202, 207, 212, 217, 222, 227, 230–231, 235–236, 240–242, 244–245, 260–261, 280, 294–295, 361–362, 425, 447–449, 469, 48, 48–49, 519–520, 528–529, 549, 556–557, 57, 59, 59–60, 619, 62, 620, 63, 646–647, 696–697, 70, 700–701, 71, 74–75, 775
   Getters.sol92.23%100%90.48%93.22%211, 57, 77, 82
   Mailbox.sol100%100%100%100%
   ZkSyncHyperchainBase.sol92.86%85.71%100%92.86%55–56
contracts/state-transition/libraries
   Diamond.sol93.33%80.77%100%95.96%109–110, 113, 115, 117, 120, 198–199, 316
   LibMap.sol100%100%100%100%
   Merkle.sol100%100%100%100%
   PriorityQueue.sol100%100%100%100%
   TransactionValidator.sol94.44%88.24%100%96%66–67, 69–70
contracts/upgrades
   BaseZkSyncUpgrade.sol58.20%27.27%100%60.23%104, 104–105, 108, 111, 114–115, 126, 126–127, 130, 133, 136–137, 151–153, 171–173, 212–213, 215, 215–216, 232–233, 249–250, 252–253, 258–259, 259–260, 271–272, 278–279, 285–286, 293–294, 298–299, 308–309, 311–312, 75–76
   BaseZkSyncUpgradeGenesis.sol56.67%14.29%100%68.18%25, 25–26, 33–34, 40–41, 52–53, 62–63, 65–66
   DefaultUpgrade.sol100%100%100%100%
   GenesisUpgrade.sol100%100%100%100%
contracts/vendor
   AddressAliasHelper.sol85.71%75%100%85.71%60, 62

/// @title ChainRegistrar Contract
/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice This contract is used for proposing and registering new chains in the zkSync ecosystem.
Copy link
Member

Choose a reason for hiding this comment

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

  • zkSync -> ZKsync
  • It doesn't register chains, users just propose them
Suggested change
/// @notice This contract is used for proposing and registering new chains in the zkSync ecosystem.
/// @notice This contract is used as a public registry where anyone can propose new chain registration in ZKsync ecosystem.

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice This contract is used for proposing and registering new chains in the zkSync ecosystem.
/// @notice It helps chain administrators retrieve all necessary L1 information about their chain.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @notice It helps chain administrators retrieve all necessary L1 information about their chain.
/// @notice It also helps chain administrators retrieve all necessary L1 information about their chain.

/// @custom:security-contact [email protected]
/// @notice This contract is used for proposing and registering new chains in the zkSync ecosystem.
/// @notice It helps chain administrators retrieve all necessary L1 information about their chain.
/// @notice Additionally, it assists zkSync administrators in verifying the correctness of registration transactions.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think "ZKsync administrators" is a good term, also it is a bit confusing as we rather use ZKsync ecosystem admin in other places.

/// @dev During the chain proposal, some base tokens must be transferred to this address.
address public l2Deployer;

/// @notice Address of the ZKsync Bridgehub.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @notice Address of the ZKsync Bridgehub.
/// @notice Address of ZKsync Bridgehub.

Comment on lines +55 to +65
/// @dev Struct for holding the base token configuration of a chain.
struct BaseToken {
/// @notice Gas price multiplier numerator, used to compare the base token price to ether for L1->L2 transactions.
uint128 gasPriceMultiplierNominator;
/// @notice Gas price multiplier denominator, used to compare the base token price to ether for L1->L2 transactions.
uint128 gasPriceMultiplierDenominator;
/// @notice Address of the base token used for gas fees.
address tokenAddress;
/// @notice Address responsible for setting the token multiplier.
address tokenMultiplierSetter;
}
Copy link
Member

Choose a reason for hiding this comment

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

Natspec

Suggested change
/// @dev Struct for holding the base token configuration of a chain.
struct BaseToken {
/// @notice Gas price multiplier numerator, used to compare the base token price to ether for L1->L2 transactions.
uint128 gasPriceMultiplierNominator;
/// @notice Gas price multiplier denominator, used to compare the base token price to ether for L1->L2 transactions.
uint128 gasPriceMultiplierDenominator;
/// @notice Address of the base token used for gas fees.
address tokenAddress;
/// @notice Address responsible for setting the token multiplier.
address tokenMultiplierSetter;
}
/// @dev Struct for holding the base token configuration of a chain.
/// @param gasPriceMultiplierNominator Gas price multiplier numerator, used to compare the base token price to ether for L1->L2 transactions.
/// @param gasPriceMultiplierDenominator Gas price multiplier denominator, used to compare the base token price to ether for L1->L2 transactions.
/// @param tokenAddress Address of the base token used for gas fees.
/// @param tokenMultiplierSetter Address responsible for setting the token multiplier.
struct BaseToken {
uint128 gasPriceMultiplierNominator;
uint128 gasPriceMultiplierDenominator;
address tokenAddress;
address tokenMultiplierSetter;
}

Copy link
Member

Choose a reason for hiding this comment

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

Please change it in other places too

/// @param _bridgehub Address of the ZKsync Bridgehub.
/// @param _l2Deployer Address of the L2 deployer.
/// @param _owner Address of the contract owner.
function initialize(address _bridgehub, address _l2Deployer, address _owner) public {
Copy link
Member

Choose a reason for hiding this comment

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

Important: anyone can reinitialize the contract. To avoid it you can use Initializable.sol from OZ lib. Also don't forget to set _disableInitializers in constructor.

Suggested change
function initialize(address _bridgehub, address _l2Deployer, address _owner) public {
function initialize(address _bridgehub, address _l2Deployer, address _owner) external Initializer {

_transferOwnership(_owner);
}

/// @notice Proposes a new chain to be registered in the zkSync ecosystem.
Copy link
Member

Choose a reason for hiding this comment

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

ZKsync everywhere please

Suggested change
/// @notice Proposes a new chain to be registered in the zkSync ecosystem.
/// @notice Proposes a new chain to be registered in the ZKsync ecosystem.

revert ChainIsAlreadyDeployed();
}

proposedChains[msg.sender][_chainId] = config;
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it makes sense to allow user to re-propose config? I would rather restrict it to make avoid any confusion on the final config (as soon as config is onchain it immutable).

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.

6 participants