-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathAdmin.sol
151 lines (121 loc) · 6.24 KB
/
Admin.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {IAdmin} from "../../chain-interfaces/IAdmin.sol";
import {Diamond} from "../../libraries/Diamond.sol";
import {MAX_GAS_PER_TRANSACTION} from "../../../common/Config.sol";
import {FeeParams, PubdataPricingMode} from "../ZkSyncStateTransitionStorage.sol";
import {ZkSyncStateTransitionBase} from "./ZkSyncStateTransitionBase.sol";
import {IStateTransitionManager} from "../../IStateTransitionManager.sol";
// While formally the following import is not used, it is needed to inherit documentation from it
import {IZkSyncStateTransitionBase} from "../../chain-interfaces/IZkSyncStateTransitionBase.sol";
/// @title Admin Contract controls access rights for contract management.
/// @author Matter Labs
/// @custom:security-contact [email protected]
contract AdminFacet is ZkSyncStateTransitionBase, IAdmin {
/// @inheritdoc IZkSyncStateTransitionBase
string public constant override getName = "AdminFacet";
/// @inheritdoc IAdmin
function setPendingAdmin(address _newPendingAdmin) external onlyAdmin {
// Save previous value into the stack to put it into the event later
address oldPendingAdmin = s.pendingAdmin;
// Change pending admin
s.pendingAdmin = _newPendingAdmin;
emit NewPendingAdmin(oldPendingAdmin, _newPendingAdmin);
}
/// @inheritdoc IAdmin
function acceptAdmin() external {
address pendingAdmin = s.pendingAdmin;
require(msg.sender == pendingAdmin, "n4"); // Only proposed by current admin address can claim the admin rights
address previousAdmin = s.admin;
s.admin = pendingAdmin;
delete s.pendingAdmin;
emit NewPendingAdmin(pendingAdmin, address(0));
emit NewAdmin(previousAdmin, pendingAdmin);
}
/// @inheritdoc IAdmin
function setValidator(address _validator, bool _active) external onlyStateTransitionManager {
s.validators[_validator] = _active;
emit ValidatorStatusUpdate(_validator, _active);
}
/// @inheritdoc IAdmin
function setPorterAvailability(bool _zkPorterIsAvailable) external onlyStateTransitionManager {
// Change the porter availability
s.zkPorterIsAvailable = _zkPorterIsAvailable;
emit IsPorterAvailableStatusUpdate(_zkPorterIsAvailable);
}
/// @inheritdoc IAdmin
function setPriorityTxMaxGasLimit(uint256 _newPriorityTxMaxGasLimit) external onlyStateTransitionManager {
require(_newPriorityTxMaxGasLimit <= MAX_GAS_PER_TRANSACTION, "n5");
uint256 oldPriorityTxMaxGasLimit = s.priorityTxMaxGasLimit;
s.priorityTxMaxGasLimit = _newPriorityTxMaxGasLimit;
emit NewPriorityTxMaxGasLimit(oldPriorityTxMaxGasLimit, _newPriorityTxMaxGasLimit);
}
/// @inheritdoc IAdmin
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");
FeeParams memory oldFeeParams = s.feeParams;
s.feeParams = _newFeeParams;
emit NewFeeParams(oldFeeParams, _newFeeParams);
}
/// @inheritdoc IAdmin
function setTokenMultiplier(uint128 _nominator, uint128 _denominator) external onlyAdminOrStateTransitionManager {
uint128 oldNominator = s.baseTokenGasPriceMultiplierNominator;
uint128 oldDenominator = s.baseTokenGasPriceMultiplierDenominator;
s.baseTokenGasPriceMultiplierNominator = _nominator;
s.baseTokenGasPriceMultiplierDenominator = _denominator;
emit NewBaseTokenMultiplier(oldNominator, oldDenominator, _nominator, _denominator);
}
function setValidiumMode(PubdataPricingMode _validiumMode) external onlyAdmin {
require(s.totalBatchesCommitted == 0, "AdminFacet: set validium only after genesis"); // Validium mode can be set only before the first batch is committed
s.feeParams.pubdataPricingMode = _validiumMode;
emit ValidiumModeStatusUpdate(_validiumMode);
}
/*//////////////////////////////////////////////////////////////
UPGRADE EXECUTION
//////////////////////////////////////////////////////////////*/
/// upgrade a specific chain
function upgradeChainFromVersion(
uint256 _oldProtocolVersion,
Diamond.DiamondCutData calldata _diamondCut
) external onlyAdminOrStateTransitionManager {
bytes32 cutHashInput = keccak256(abi.encode(_diamondCut));
require(
cutHashInput == IStateTransitionManager(s.stateTransitionManager).upgradeCutHash(_oldProtocolVersion),
"StateTransition: cutHash mismatch"
);
require(
s.protocolVersion == _oldProtocolVersion,
"StateTransition: protocolVersion mismatch in STC when upgrading"
);
Diamond.diamondCut(_diamondCut);
emit ExecuteUpgrade(_diamondCut);
require(
s.protocolVersion > _oldProtocolVersion,
"StateTransition: protocolVersion mismatch in STC after upgrading"
);
}
/// @inheritdoc IAdmin
function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut) external onlyStateTransitionManager {
Diamond.diamondCut(_diamondCut);
emit ExecuteUpgrade(_diamondCut);
}
/*//////////////////////////////////////////////////////////////
CONTRACT FREEZING
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IAdmin
function freezeDiamond() external onlyAdminOrStateTransitionManager {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();
require(!diamondStorage.isFrozen, "a9"); // diamond proxy is frozen already
diamondStorage.isFrozen = true;
emit Freeze();
}
/// @inheritdoc IAdmin
function unfreezeDiamond() external onlyAdminOrStateTransitionManager {
Diamond.DiamondStorage storage diamondStorage = Diamond.getDiamondStorage();
require(diamondStorage.isFrozen, "a7"); // diamond proxy is not frozen
diamondStorage.isFrozen = false;
emit Unfreeze();
}
}