Skip to content

Commit

Permalink
started renaming chain's governor to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Feb 16, 2024
1 parent fb39679 commit 46fa6af
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 89 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridgehub/IBridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ interface IBridgehub {
address _stateTransitionManager,
address _baseToken,
uint256 _salt,
address _governor,
address _admin,
bytes calldata _initData
) external returns (uint256 chainId);

Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/contracts/dev-contracts/test/AdminFacetTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../../state-transition/chain-deps/facets/Admin.sol";

contract AdminFacetTest is AdminFacet {
constructor() {
s.governor = msg.sender;
s.admin = msg.sender;
s.stateTransitionManager = msg.sender;
}

Expand All @@ -22,11 +22,11 @@ contract AdminFacetTest is AdminFacet {
return s.priorityTxMaxGasLimit;
}

function getGovernor() external view returns (address) {
return s.governor;
function getAdmin() external view returns (address) {
return s.admin;
}

function getPendingGovernor() external view returns (address) {
return s.pendingGovernor;
function getPendingAdmin() external view returns (address) {
return s.pendingAdmin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract DummyExecutor is IExecutor {
_;
}

function getGovernor() external view returns (address) {
function getAdmin() external view returns (address) {
return owner;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "../../common/Config.sol";

contract MailboxFacetTest is MailboxFacet {
constructor() {
s.governor = msg.sender;
s.admin = msg.sender;
}

function setFeeParams(FeeParams memory _feeParams) external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ interface IStateTransitionManager {

function setValidatorTimelock(address _validatorTimelock) external;

function getChainGovernor(uint256 _chainId) external view returns (address);
function getChainAdmin(uint256 _chainId) external view returns (address);

/// @notice
function createNewChain(
uint256 _chainId,
address _baseToken,
address _sharedBridge,
address _governor,
address _admin,
bytes calldata _diamondCut
) external;

Expand Down
22 changes: 4 additions & 18 deletions l1-contracts/contracts/state-transition/StateTransitionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,9 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
_;
}

/// @notice only the state transition chain contract can call
modifier onlyChain(uint256 _chainId) {
require(stateTransition[_chainId] == msg.sender, "StateTransition: only chain");
_;
}

/// @notice only the governor of the chain can call
modifier onlyChainGovernor(uint256 _chainId) {
require(
IZkSyncStateTransition(stateTransition[_chainId]).getGovernor() == msg.sender,
"StateTransition: only chain governor"
);
_;
}

function getChainGovernor(uint256 _chainId) external view override returns (address) {
return IZkSyncStateTransition(stateTransition[_chainId]).getGovernor();
function getChainAdmin(uint256 _chainId) external view override returns (address) {
return IZkSyncStateTransition(stateTransition[_chainId]).getAdmin();
}

/// @dev initialize
Expand Down Expand Up @@ -208,7 +194,7 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
uint256 _chainId,
address _baseToken,
address _sharedBridge,
address _governor,
address _admin,
bytes calldata _diamondCut
) external onlyBridgehub {
// check not registered
Expand All @@ -227,7 +213,7 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
bytes32(uint256(uint160(bridgehub))),
bytes32(uint256(uint160(address(this)))),
bytes32(uint256(protocolVersion)),
bytes32(uint256(uint160(_governor))),
bytes32(uint256(uint160(_admin))),
bytes32(uint256(uint160(validatorTimelock))),
bytes32(uint256(uint160(_baseToken))),
bytes32(uint256(uint160(_sharedBridge))),
Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/contracts/state-transition/ValidatorTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ contract ValidatorTimelock is IExecutor, Ownable2Step {
executionDelay = _executionDelay;
}

/// @notice Checks if the caller is the governor of the chain.
modifier onlyChainOwner(uint256 _chainId) {
require(msg.sender == stateTransitionManager.getChainGovernor(_chainId), "9h");
/// @notice Checks if the caller is the admin of the chain.
modifier onlyChainAdmin(uint256 _chainId) {
require(msg.sender == stateTransitionManager.getChainAdmin(_chainId), "9h");
_;
}

Expand All @@ -69,7 +69,7 @@ contract ValidatorTimelock is IExecutor, Ownable2Step {
}

/// @dev Set new validator address.
function setValidator(uint256 _chainId, address _newValidator) external onlyChainOwner(_chainId) {
function setValidator(uint256 _chainId, address _newValidator) external onlyChainAdmin(_chainId) {
address oldValidator = validator[_chainId];
validator[_chainId] = _newValidator;
emit NewValidatorSharedBridge(_chainId, oldValidator, _newValidator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract DiamondInit is ZkSyncStateTransitionBase, IDiamondInit {
/// initializer
function initialize(InitializeData calldata _initializeData) external reentrancyGuardInitializer returns (bytes32) {
require(address(_initializeData.verifier) != address(0), "vt");
require(_initializeData.governor != address(0), "vy");
require(_initializeData.admin != address(0), "vy");
require(_initializeData.validatorTimelock != address(0), "hc");
require(_initializeData.priorityTxMaxGasLimit <= MAX_GAS_PER_TRANSACTION, "vu");

Expand All @@ -35,7 +35,7 @@ contract DiamondInit is ZkSyncStateTransitionBase, IDiamondInit {
s.protocolVersion = _initializeData.protocolVersion;

s.verifier = _initializeData.verifier;
s.governor = _initializeData.governor;
s.admin = _initializeData.admin;
s.validators[_initializeData.validatorTimelock] = true;

s.storedBatchHashes[0] = _initializeData.storedBatchZero;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ struct FeeParams {
struct ZkSyncStateTransitionStorage {
/// @dev Storage of variables needed for deprecated diamond cut facet
uint256[7] __DEPRECATED_diamondCutStorage;
/// @notice Address which will exercise critical changes to the Diamond Proxy (upgrades, freezing & unfreezing)
address governor;
/// @notice Address which will exercise critical changes to the Diamond Proxy (upgrades, freezing & unfreezing). Replaced by STM
address __DEPRECATED_governor;
/// @notice Address that the governor proposed as one that will replace it
address pendingGovernor;
address __DEPRECATED_pendingGovernor;
/// @notice List of permitted validators
mapping(address validatorAddress => bool isValidator) validators;
/// @dev Verifier contract. Used to verify aggregated proof for batches
Expand Down Expand Up @@ -127,9 +127,9 @@ struct ZkSyncStateTransitionStorage {
/// yet.
uint256 l2SystemContractsUpgradeBatchNumber;
/// @dev Address which will exercise non-critical changes to the Diamond Proxy (changing validator set & unfreezing)
address __DEPRECATED_admin;
/// @notice Address that the governor or admin proposed as one that will replace admin role
address __DEPRECATED_pendingAdmin;
address admin;
/// @notice Address that the admin proposed as one that will replace admin role
address pendingAdmin;
/// @dev Fee params used to derive gasPrice for the L1->L2 transactions. For L2 transactions,
/// the bootloader gives enough freedom to the operator.
FeeParams feeParams;
Expand Down
36 changes: 18 additions & 18 deletions l1-contracts/contracts/state-transition/chain-deps/facets/Admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
string public constant override getName = "AdminFacet";

/// @inheritdoc IAdmin
function setPendingGovernor(address _newPendingGovernor) external onlyGovernor {
function setPendingAdmin(address _newPendingAdmin) external onlyAdmin {
// Save previous value into the stack to put it into the event later
address oldPendingGovernor = s.pendingGovernor;
// Change pending governor
s.pendingGovernor = _newPendingGovernor;
emit NewPendingGovernor(oldPendingGovernor, _newPendingGovernor);
address oldPendingAdmin = s.pendingAdmin;
// Change pending admin
s.pendingAdmin = _newPendingAdmin;
emit NewPendingAdmin(oldPendingAdmin, _newPendingAdmin);
}

/// @inheritdoc IAdmin
function acceptGovernor() external {
address pendingGovernor = s.pendingGovernor;
require(msg.sender == pendingGovernor, "n4"); // Only proposed by current governor address can claim the governor rights
function acceptAdmin() external {
address pendingAdmin = s.pendingAdmin;
require(msg.sender == pendingAdmin, "n4"); // Only proposed by current admin address can claim the admin rights

address previousGovernor = s.governor;
s.governor = pendingGovernor;
delete s.pendingGovernor;
address previousAdmin = s.admin;
s.admin = pendingAdmin;
delete s.pendingAdmin;

emit NewPendingGovernor(pendingGovernor, address(0));
emit NewGovernor(previousGovernor, pendingGovernor);
emit NewPendingAdmin(pendingAdmin, address(0));
emit NewAdmin(previousAdmin, pendingAdmin);
}

/// @inheritdoc IAdmin
Expand All @@ -64,7 +64,7 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
}

/// @inheritdoc IAdmin
function changeFeeParams(FeeParams calldata _newFeeParams) external onlyGovernorOrStateTransitionManager {
function changeFeeParams(FeeParams calldata _newFeeParams) external onlyAdminOrStateTransitionManager {
// Double checking that the new fee params are valid, i.e.
// the maximal pubdata per batch is not less than the maximal pubdata per priority transaction.
require(_newFeeParams.maxPubdataPerBatch >= _newFeeParams.priorityTxMaxPubdata, "n6");
Expand All @@ -79,7 +79,7 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
function setTokenMultiplier(
uint128 _nominator,
uint128 _denominator
) external onlyGovernorOrStateTransitionManager {
) external onlyAdminOrStateTransitionManager {
uint128 oldNominator = s.baseTokenGasPriceMultiplierNominator;
uint128 oldDenominator = s.baseTokenGasPriceMultiplierDenominator;

Expand All @@ -97,7 +97,7 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
function upgradeChainFromVersion(
uint256 _oldProtocolVersion,
Diamond.DiamondCutData calldata _diamondCut
) external onlyGovernorOrStateTransitionManager {
) external onlyAdminOrStateTransitionManager {
bytes32 cutHashInput = keccak256(abi.encode(_diamondCut));
require(
cutHashInput == IStateTransitionManager(s.stateTransitionManager).upgradeCutHash(_oldProtocolVersion),
Expand Down Expand Up @@ -127,7 +127,7 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
//////////////////////////////////////////////////////////////*/

/// @inheritdoc IAdmin
function freezeDiamond() external onlyGovernorOrStateTransitionManager {
function freezeDiamond() external onlyAdminOrStateTransitionManager {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();

require(!diamondStorage.isFrozen, "a9"); // diamond proxy is frozen already
Expand All @@ -137,7 +137,7 @@ contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
}

/// @inheritdoc IAdmin
function unfreezeDiamond() external onlyGovernorOrStateTransitionManager {
function unfreezeDiamond() external onlyAdminOrStateTransitionManager {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();

require(diamondStorage.isFrozen, "a7"); // diamond proxy is not frozen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {ReentrancyGuard} from "../../../common/ReentrancyGuard.sol";
contract ZkSyncStateTransitionBase is ReentrancyGuard {
ZkSyncStateTransitionStorage internal s;

/// @notice Checks that the message sender is an active governor
modifier onlyGovernor() {
require(msg.sender == s.governor, "StateTransition Chain: not governor");
/// @notice Checks that the message sender is an active admin
modifier onlyAdmin() {
require(msg.sender == s.admin, "StateTransition Chain: not admin");
_;
}

Expand All @@ -33,10 +33,10 @@ contract ZkSyncStateTransitionBase is ReentrancyGuard {
_;
}

modifier onlyGovernorOrStateTransitionManager() {
modifier onlyAdminOrStateTransitionManager() {
require(
msg.sender == s.governor || msg.sender == s.stateTransitionManager,
"StateTransition Chain: Only by governor or state transition manager"
msg.sender == s.admin || msg.sender == s.stateTransitionManager,
"StateTransition Chain: Only by admin or state transition manager"
);
_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ contract GettersFacet is ZkSyncStateTransitionBase, IGetters, ILegacyGetters {
}

/// @inheritdoc IGetters
function getGovernor() external view returns (address) {
return s.governor;
function getAdmin() external view returns (address) {
return s.admin;
}

/// @inheritdoc IGetters
function getPendingGovernor() external view returns (address) {
return s.pendingGovernor;
function getPendingAdmin() external view returns (address) {
return s.pendingAdmin;
}

/// @inheritdoc IGetters
Expand Down
26 changes: 13 additions & 13 deletions l1-contracts/contracts/state-transition/chain-interfaces/IAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {FeeParams} from "../chain-deps/ZkSyncStateTransitionStorage.sol";
/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IAdmin is IZkSyncStateTransitionBase {
/// @notice Starts the transfer of governor rights. Only the current governor can propose a new pending one.
/// @notice New governor can accept governor rights by calling `acceptGovernor` function.
/// @param _newPendingGovernor Address of the new governor
function setPendingGovernor(address _newPendingGovernor) external;
/// @notice Starts the transfer of admin rights. Only the current admin can propose a new pending one.
/// @notice New admin can accept admin rights by calling `acceptAdmin` function.
/// @param _newPendingAdmin Address of the new admin
function setPendingAdmin(address _newPendingAdmin) external;

/// @notice Accepts transfer of governor rights. Only pending governor can accept the role.
function acceptGovernor() external;
/// @notice Accepts transfer of admin rights. Only pending admin can accept the role.
function acceptAdmin() external;

/// @notice Change validator status (active or not active)
/// @param _validator Validator address
Expand All @@ -42,7 +42,7 @@ interface IAdmin is IZkSyncStateTransitionBase {
function upgradeChainFromVersion(uint256 _protocolVersion, Diamond.DiamondCutData calldata _cutData) external;

/// @notice Executes a proposed governor upgrade
/// @dev Only the current governor can execute the upgrade
/// @dev Only the current admin can execute the upgrade
/// @param _diamondCut The diamond cut parameters to be executed
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut) external;

Expand All @@ -51,7 +51,7 @@ interface IAdmin is IZkSyncStateTransitionBase {
function freezeDiamond() external;

/// @notice Unpause the functionality of all freezable facets & their selectors
/// @dev Both the governor and its owner can unfreeze Diamond Proxy
/// @dev Both the admin and the STM can unfreeze Diamond Proxy
function unfreezeDiamond() external;

/// @notice Porter availability status changes
Expand All @@ -60,12 +60,12 @@ interface IAdmin is IZkSyncStateTransitionBase {
/// @notice Validator's status changed
event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive);

/// @notice pendingGovernor is changed
/// @dev Also emitted when new governor is accepted and in this case, `newPendingGovernor` would be zero address
event NewPendingGovernor(address indexed oldPendingGovernor, address indexed newPendingGovernor);
/// @notice pendingAdmin is changed
/// @dev Also emitted when new admin is accepted and in this case, `newPendingAdmin` would be zero address
event NewPendingAdmin(address indexed oldPendingAdmin, address indexed newPendingAdmin);

/// @notice Governor changed
event NewGovernor(address indexed oldGovernor, address indexed newGovernor);
/// @notice Admin changed
event NewAdmin(address indexed oldAdmin, address indexed newAdmin);

/// @notice Priority transaction max L2 gas limit changed
event NewPriorityTxMaxGasLimit(uint256 oldPriorityTxMaxGasLimit, uint256 newPriorityTxMaxGasLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {FeeParams} from "../chain-deps/ZkSyncStateTransitionStorage.sol";
/// @param chainId
/// @param stateTransition contract's address
/// @param verifier address of Verifier contract
/// @param governor address who can manage the contract
/// @param admin address who can manage the contract
/// @param allowList The address of the allow list smart contract
/// @param verifierParams Verifier config parameters that describes the circuit to be verified
/// @param l2BootloaderBytecodeHash The hash of bootloader L2 bytecode
Expand All @@ -20,7 +20,7 @@ struct InitializeData {
address bridgehub;
address stateTransitionManager;
uint256 protocolVersion;
address governor;
address admin;
address validatorTimelock;
address baseToken;
address baseTokenBridge;
Expand Down
Loading

0 comments on commit 46fa6af

Please sign in to comment.