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

chore: Kl/merge-dev #791

Merged
merged 14 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ l1-contracts/script-out/*
l1-contracts/test/foundry/l1/integration/deploy-scripts/script-out/*.toml
!l1-contracts/script-out/.gitkeep
*.timestamp
l1-contracts/test/foundry/l1/integration/deploy-scripts/script-out/*
l1-contracts/zkout/*
3 changes: 2 additions & 1 deletion gas-bound-caller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"ethers": "^5.7.0",
"fast-glob": "^3.3.2",
"hardhat": "=2.22.2",
"preprocess": "^3.2.0"
"preprocess": "^3.2.0",
"zksync-ethers": "^5.9.0"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-chai-matchers": "^0.2.0",
Expand Down
1 change: 0 additions & 1 deletion l1-contracts/contracts/bridge/BridgeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pragma solidity 0.8.24;
import {IERC20Metadata} from "@openzeppelin/contracts-v4/token/ERC20/extensions/IERC20Metadata.sol";
import {ETH_TOKEN_ADDRESS} from "../common/Config.sol";
import {DataEncoding} from "../common/libraries/DataEncoding.sol";
import {NEW_ENCODING_VERSION} from "./asset-router/IAssetRouterBase.sol";

/**
* @author Matter Labs
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus

/// @notice asset id can represent any token contract with the appropriate interface/functionality
/// @param _baseTokenAssetId asset id of base token to be registered
function addTokenAssetId(bytes32 _baseTokenAssetId) external onlyOwner {
function addTokenAssetId(bytes32 _baseTokenAssetId) external onlyOwnerOrAdmin {
if (assetIdIsRegistered[_baseTokenAssetId]) {
revert AssetIdAlreadyRegistered();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
governance = "0x6a08d69675af7755569a1a25ef37e795493473a1"
erc20_bridge = "0x84fbda16bd5f2d66d7fbaec5e8d816e7b7014595"
consensus_registry_owner = "0xD64e136566a9E04eb05B30184fF577F52682D182"
129 changes: 119 additions & 10 deletions l1-contracts/deploy-scripts/DeployL2Contracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ contract DeployL2Script is Script {
address l1SharedBridgeProxy;
address governance;
address erc20BridgeProxy;
// The owner of the contract sets the validator/attester weights.
// Can be the developer multisig wallet on mainnet.
address consensusRegistryOwner;
uint256 chainId;
uint256 eraChainId;
address l2SharedBridgeImplementation;
address l2SharedBridgeProxy;
address consensusRegistryImplementation;
address consensusRegistryProxy;
address forceDeployUpgraderAddress;
}

Expand All @@ -35,44 +40,74 @@ contract DeployL2Script is Script {
bytes l2StandardErc20Bytecode;
bytes l2SharedBridgeBytecode;
bytes l2SharedBridgeProxyBytecode;
bytes consensusRegistryBytecode;
bytes consensusRegistryProxyBytecode;
bytes forceDeployUpgrader;
}

function run() public {
deploy(false);
}

function runWithLegacyBridge() public {
deploy(true);
}

function deploy(bool legacyBridge) public {
initializeConfig();
loadContracts();
loadContracts(legacyBridge);

deployFactoryDeps();
deploySharedBridge();
deploySharedBridgeProxy();
deploySharedBridgeProxy(legacyBridge);
initializeChain();
deployForceDeployer();
deployConsensusRegistry();
deployConsensusRegistryProxy();

saveOutput();
}

function runDeployLegacySharedBridge() public {
deploySharedBridge(true);
}

function runDeploySharedBridge() public {
deploySharedBridge(false);
}

function deploySharedBridge(bool legacyBridge) internal {
initializeConfig();
loadContracts();
loadContracts(legacyBridge);

deployFactoryDeps();
deploySharedBridge();
deploySharedBridgeProxy();
deploySharedBridgeProxy(legacyBridge);
initializeChain();

saveOutput();
}

function runDefaultUpgrader() public {
initializeConfig();
loadContracts();
loadContracts(false);

deployForceDeployer();

saveOutput();
}

function loadContracts() internal {
function runDeployConsensusRegistry() public {
initializeConfig();
loadContracts(false);

deployConsensusRegistry();
deployConsensusRegistryProxy();

saveOutput();
}

function loadContracts(bool legacyBridge) internal {
//HACK: Meanwhile we are not integrated foundry zksync we use contracts that has been built using hardhat
contracts.l2StandardErc20FactoryBytecode = Utils.readHardhatBytecode(
"/artifacts-zk/@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json"
Expand All @@ -84,12 +119,28 @@ contract DeployL2Script is Script {
"/artifacts-zk/contracts/bridge/BridgedStandardERC20.sol/BridgedStandardERC20.json"
);

contracts.l2SharedBridgeBytecode = Utils.readFoundryBytecode("/zkout/L2SharedBridge.sol/L2SharedBridge.json");
if (legacyBridge) {
contracts.l2SharedBridgeBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/dev-contracts/DevL2SharedBridge.sol/DevL2SharedBridge.json"
);
} else {
contracts.l2SharedBridgeBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/zkout/L2SharedBridge.sol/L2SharedBridge.json"
);
}

contracts.l2SharedBridgeProxyBytecode = Utils.readHardhatBytecode(
"/artifacts-zk/@openzeppelin/contracts-v4/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json"
);
contracts.forceDeployUpgrader = Utils.readFoundryBytecode(

contracts.consensusRegistryBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/zkout/ConsensusRegistry.sol/ConsensusRegistry.json"
);
contracts.consensusRegistryProxyBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/zkout/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json"
);

contracts.forceDeployUpgrader = Utils.readHardhatBytecode(
"/../l2-contracts/zkout/ForceDeployUpgrader.sol/ForceDeployUpgrader.json"
);
}
Expand All @@ -102,13 +153,16 @@ contract DeployL2Script is Script {
config.governance = toml.readAddress("$.governance");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.erc20BridgeProxy = toml.readAddress("$.erc20_bridge");
config.consensusRegistryOwner = toml.readAddress("$.consensus_registry_owner");
config.chainId = toml.readUint("$.chain_id");
config.eraChainId = toml.readUint("$.era_chain_id");
}

function saveOutput() internal {
vm.serializeAddress("root", "l2_shared_bridge_implementation", config.l2SharedBridgeImplementation);
vm.serializeAddress("root", "l2_shared_bridge_proxy", config.l2SharedBridgeProxy);
vm.serializeAddress("root", "consensus_registry_implementation", config.consensusRegistryImplementation);
vm.serializeAddress("root", "consensus_registry_proxy", config.consensusRegistryProxy);
string memory toml = vm.serializeAddress("root", "l2_default_upgrader", config.forceDeployUpgraderAddress);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-l2-contracts.toml");
Expand Down Expand Up @@ -155,13 +209,20 @@ contract DeployL2Script is Script {
});
}

function deploySharedBridgeProxy() internal {
function deploySharedBridgeProxy(bool legacyBridge) internal {
address l2GovernorAddress = AddressAliasHelper.applyL1ToL2Alias(config.governance);
bytes32 l2StandardErc20BytecodeHash = L2ContractHelper.hashL2Bytecode(contracts.beaconProxy);

string memory functionSignature;

if (legacyBridge) {
functionSignature = "initializeDevBridge(address,address,bytes32,address)";
} else {
functionSignature = "initialize(address,address,bytes32,address)";
}
// solhint-disable-next-line func-named-parameters
bytes memory proxyInitializationParams = abi.encodeWithSignature(
"initialize(address,address,bytes32,address)",
functionSignature,
config.l1SharedBridgeProxy,
config.erc20BridgeProxy,
l2StandardErc20BytecodeHash,
Expand All @@ -186,6 +247,54 @@ contract DeployL2Script is Script {
});
}

// Deploy the ConsensusRegistry implementation and save its address into the config.
function deployConsensusRegistry() internal {
// ConsensusRegistry.sol doesn't have a constructor, just an initializer.
bytes memory constructorData = "";

config.consensusRegistryImplementation = Utils.deployThroughL1({
bytecode: contracts.consensusRegistryBytecode,
constructorargs: constructorData,
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: new bytes[](0),
chainId: config.chainId,
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy
});
}

// Deploy a transparent upgradable proxy for the already deployed consensus registry
// implementation and save its address into the config.
function deployConsensusRegistryProxy() internal {
// Admin for the proxy
address l2GovernorAddress = AddressAliasHelper.applyL1ToL2Alias(config.governance);

// Call ConsensusRegistry::initialize with the initial owner.
// solhint-disable-next-line func-named-parameters
bytes memory proxyInitializationParams = abi.encodeWithSignature(
"initialize(address)",
config.consensusRegistryOwner
);

bytes memory consensusRegistryProxyConstructorData = abi.encode(
config.consensusRegistryImplementation, // _logic
l2GovernorAddress, // admin_
proxyInitializationParams // _data
);

config.consensusRegistryProxy = Utils.deployThroughL1({
bytecode: contracts.consensusRegistryProxyBytecode,
constructorargs: consensusRegistryProxyConstructorData,
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: new bytes[](0),
chainId: config.chainId,
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy
});
}

function initializeChain() internal {
L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy);

Expand Down
Loading
Loading