Skip to content

Commit

Permalink
Remove unnnecessary functions
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Nov 22, 2024
1 parent 5828b73 commit b13245c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 47 deletions.
47 changes: 10 additions & 37 deletions l1-contracts/contracts/chain-registrar/ChainRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,29 @@ import {ETH_TOKEN_ADDRESS} from "../common/Config.sol";
import {IERC20} from "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/access/Ownable2StepUpgradeable.sol";
import {IGetters} from "../state-transition/chain-interfaces/IGetters.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {SafeERC20} from "@openzeppelin/contracts-v4/token/ERC20/utils/SafeERC20.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @dev ChainRegistrar serves as the main point for chain registration.
contract ChainRegistrar is Ownable2StepUpgradeable, ReentrancyGuard {
contract ChainRegistrar is Ownable2StepUpgradeable {
using SafeERC20 for IERC20;
/// @notice Address that will be used for deploying l2 contracts
address public l2Deployer;
/// ZKsync Bridgehub
IBridgehub public bridgehub;

/// Chains that has been successfully deployed
mapping(address => mapping(uint256 => bool)) public deployedChains;
/// Proposal for chain registration
mapping(address => mapping(uint256 => ChainConfig)) public proposedChains;

error ProposalNotFound();
error BaseTokenTransferFailed();
error ChainIsAlreadyDeployed();
error ChainIsNotYetDeployed();
error BridgeIsNotRegistered();

/// @notice new chain is deployed
event NewChainDeployed(uint256 indexed chainId, address author, address diamondProxy, address chainAdmin);

/// @notice new chain is proposed to register
event NewChainRegistrationProposal(uint256 indexed chainId, address author);

/// @notice Shared bridge is registered on l2
event SharedBridgeRegistered(uint256 indexed chainId, address l2Address);

/// @notice L2 Deployer has changed
event L2DeployerChanged(address newDeployer);

Expand Down Expand Up @@ -75,17 +65,19 @@ contract ChainRegistrar is Ownable2StepUpgradeable, ReentrancyGuard {
}

// @dev Initialize the contract
function initialize(address _bridgehub, address _l2Deployer, address _owner) public reentrancyGuardInitializer {
function initialize(address _bridgehub, address _l2Deployer, address _owner) public {
bridgehub = IBridgehub(_bridgehub);
l2Deployer = _l2Deployer;
_transferOwnership(_owner);
}

// @dev Propose a new chain to be registered in zksync ecosystem.
// ZKsync administration will use this data for registering the chain on bridgehub.
// The call will fail if the chain already registered.
// Note: For non eth based chains it requires to either approve equivalent of 1 eth of base token or transfer
// this token to l2 deployer directly
/// @dev Propose a new chain to be registered in zksync ecosystem.
/// ZKsync administration will use this data for registering the chain on bridgehub.
/// The call will fail if the chain already registered.
/// Note: For non eth based chains it requires to either approve equivalent of 1 eth of base token or transfer
/// this token to l2 deployer directly
/// @param _chainId

function proposeChainRegistration(
uint256 _chainId,
PubdataPricingMode _pubdataPricingMode,
Expand All @@ -96,7 +88,7 @@ contract ChainRegistrar is Ownable2StepUpgradeable, ReentrancyGuard {
address _tokenMultiplierSetter,
uint128 _gasPriceMultiplierNominator,
uint128 _gasPriceMultiplierDenominator
) public {
) external {
ChainConfig memory config = ChainConfig({
chainId: _chainId,
pubdataPricingMode: _pubdataPricingMode,
Expand Down Expand Up @@ -133,10 +125,6 @@ contract ChainRegistrar is Ownable2StepUpgradeable, ReentrancyGuard {
emit L2DeployerChanged(l2Deployer);
}

function getChainConfig(address _author, uint256 _chainId) public view returns (ChainConfig memory) {
return proposedChains[_author][_chainId];
}

// @dev Get data about the chain that has been fully deployed
function getRegisteredChainConfig(uint256 _chainId) public view returns (RegisteredChainConfig memory) {
address stm = bridgehub.stateTransitionManager(_chainId);
Expand All @@ -160,19 +148,4 @@ contract ChainRegistrar is Ownable2StepUpgradeable, ReentrancyGuard {
});
return config;
}

// @dev Mark chain as registered. Emit necessary events for spinning up the chain server
function setChainAsRegistered(address _author, uint256 _chainId) public onlyOwner nonReentrant {
ChainConfig memory config = proposedChains[_author][_chainId];
if (config.chainId == 0) {
revert ProposalNotFound();
}

RegisteredChainConfig memory deployedConfig = getRegisteredChainConfig(_chainId);

// Matter Labs team set the pending admin to the chain admin and now governor of the chain must accept ownership
emit NewChainDeployed(_chainId, _author, deployedConfig.diamondProxy, deployedConfig.pendingChainAdmin);
emit SharedBridgeRegistered(_chainId, deployedConfig.l2BridgeAddress);
deployedChains[_author][_chainId] = true;
}
}
7 changes: 0 additions & 7 deletions l1-contracts/deploy-scripts/DeployL2Contracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ contract DeployL2Script is Script {
deploySharedBridge();
deploySharedBridgeProxy(legacyBridge);
initializeChain();
finalizeRegistration();
deployForceDeployer();
deployConsensusRegistry();
deployConsensusRegistryProxy();
Expand Down Expand Up @@ -373,10 +372,4 @@ contract DeployL2Script is Script {
_value: 0
});
}

function finalizeRegistration() internal {
ChainRegistrar chainRegistrar = ChainRegistrar(config.chainRegistrar);
vm.broadcast();
chainRegistrar.setChainAsRegistered(config.proposalAuthor, config.chainId);
}
}
2 changes: 1 addition & 1 deletion l1-contracts/deploy-scripts/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract RegisterHyperchainScript is Script {
}

function loadChain() internal {
chainConfig = chainRegistrar.getChainConfig(config.proposalAuthor, config.chainChainId);
chainConfig = chainRegistrar.proposedChains[config.proposalAuthor][config.chainChainId];
}

function checkTokenAddress() internal view {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ contract ChainRegistrarTest is Test {
sharedBridge.initializeChainGovernance(1, makeAddr("l2bridge"));
vm.recordLogs();
vm.prank(admin);
chainRegistrar.setChainAsRegistered(author, 1);
Vm.Log[] memory registeredLogs = vm.getRecordedLogs();
ChainRegistrar.RegisteredChainConfig memory registeredConfig = chainRegistrar.getRegisteredChainConfig(1);
require(registeredConfig.diamondProxy != address(0));
require(registeredConfig.chainAdmin != address(0));
Expand Down

0 comments on commit b13245c

Please sign in to comment.