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

use chain admin for bridgehub manipulations #799

Merged
merged 3 commits into from
Sep 12, 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
4 changes: 4 additions & 0 deletions l1-contracts/deploy-scripts/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,15 @@ contract DeployL1Script is Script {

Bridgehub bridgehub = Bridgehub(addresses.bridgehub.bridgehubProxy);
bridgehub.transferOwnership(addresses.governance);
bridgehub.setPendingAdmin(addresses.chainAdmin);

L1SharedBridge sharedBridge = L1SharedBridge(addresses.bridges.sharedBridgeProxy);
sharedBridge.transferOwnership(addresses.governance);
sharedBridge.setPendingAdmin(addresses.chainAdmin);

StateTransitionManager stm = StateTransitionManager(addresses.stateTransition.stateTransitionProxy);
stm.transferOwnership(addresses.governance);
stm.setPendingAdmin(addresses.chainAdmin);
Copy link
Member

Choose a reason for hiding this comment

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

should you also accept ownership?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's a script from one private key, i can't accept it right here i do it in the zk_toolbox

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the counterpart matter-labs/zksync-era#2857


vm.stopBroadcast();
console.log("Owners updated");
Expand Down Expand Up @@ -702,6 +705,7 @@ contract DeployL1Script is Script {
addresses.blobVersionedHashRetriever
);
vm.serializeAddress("deployed_addresses", "validator_timelock_addr", addresses.validatorTimelock);
vm.serializeAddress("deployed_addresses", "chain_admin", addresses.chainAdmin);
vm.serializeString("deployed_addresses", "bridgehub", bridgehub);
vm.serializeString("deployed_addresses", "state_transition", stateTransition);
string memory deployedAddresses = vm.serializeString("deployed_addresses", "bridges", bridges);
Expand Down
26 changes: 7 additions & 19 deletions l1-contracts/deploy-scripts/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {Script, console2 as console} from "forge-std/Script.sol";
import {Vm} from "forge-std/Vm.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol";
import {Bridgehub} from "contracts/bridgehub/Bridgehub.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol";
import {Governance} from "contracts/governance/Governance.sol";
Expand Down Expand Up @@ -118,20 +117,17 @@ contract RegisterHyperchainScript is Script {
}

function registerTokenOnBridgehub() internal {
IBridgehub bridgehub = IBridgehub(config.bridgehub);
Ownable ownable = Ownable(config.bridgehub);
Bridgehub bridgehub = Bridgehub(config.bridgehub);

if (bridgehub.tokenIsRegistered(config.baseToken)) {
console.log("Token already registered on Bridgehub");
} else {
bytes memory data = abi.encodeCall(bridgehub.addToken, (config.baseToken));
Utils.executeUpgrade({
_governor: ownable.owner(),
_salt: bytes32(config.bridgehubCreateNewChainSalt),
Utils.chainAdminMulticall({
_chainAdmin: bridgehub.admin(),
_target: config.bridgehub,
_data: data,
_value: 0,
_delay: 0
_value: 0
});
console.log("Token registered on Bridgehub");
}
Expand All @@ -156,8 +152,7 @@ contract RegisterHyperchainScript is Script {
}

function registerHyperchain() internal {
IBridgehub bridgehub = IBridgehub(config.bridgehub);
Ownable ownable = Ownable(config.bridgehub);
Bridgehub bridgehub = Bridgehub(config.bridgehub);

vm.recordLogs();
bytes memory data = abi.encodeCall(
Expand All @@ -172,14 +167,7 @@ contract RegisterHyperchainScript is Script {
)
);

Utils.executeUpgrade({
_governor: ownable.owner(),
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
_value: 0,
_delay: 0
});
Utils.chainAdminMulticall({_chainAdmin: bridgehub.admin(), _target: config.bridgehub, _data: data, _value: 0});
console.log("Hyperchain registered");

// Get new diamond proxy address from emitted events
Expand Down
10 changes: 10 additions & 0 deletions l1-contracts/deploy-scripts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "contracts/common/Config.sol";
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "contracts/common/L2ContractAddresses.sol";
import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol";
import {IChainAdmin} from "contracts/governance/IChainAdmin.sol";

library Utils {
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
Expand Down Expand Up @@ -288,6 +289,15 @@ library Utils {
return bytecode;
}

function chainAdminMulticall(address _chainAdmin, address _target, bytes memory _data, uint256 _value) internal {
IChainAdmin chainAdmin = IChainAdmin(_chainAdmin);

IChainAdmin.Call[] memory calls = new IChainAdmin.Call[](1);
calls[0] = IChainAdmin.Call({target: _target, value: _value, data: _data});
vm.broadcast();
chainAdmin.multicall(calls, true);
}

function executeUpgrade(
address _governor,
bytes32 _salt,
Expand Down
Loading