Skip to content

Commit

Permalink
use chain admin for bridgehub manipulations (#799)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
  • Loading branch information
Deniallugo and vladbochok authored Sep 12, 2024
1 parent 73b20c4 commit 3a1b5d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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);

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

0 comments on commit 3a1b5d4

Please sign in to comment.