-
Notifications
You must be signed in to change notification settings - Fork 28
/
Getters.sol
247 lines (202 loc) · 10.6 KB
/
Getters.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "./Base.sol";
import "../libraries/Diamond.sol";
import "../libraries/PriorityQueue.sol";
import "../../common/libraries/UncheckedMath.sol";
import "../interfaces/IGetters.sol";
import "../interfaces/ILegacyGetters.sol";
/// @title Getters Contract implements functions for getting contract state from outside the batchchain.
/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
contract GettersFacet is Base, IGetters, ILegacyGetters {
using UncheckedMath for uint256;
using PriorityQueue for PriorityQueue.Queue;
string public constant override getName = "GettersFacet";
/*//////////////////////////////////////////////////////////////
CUSTOM GETTERS
//////////////////////////////////////////////////////////////*/
/// @return The address of the verifier smart contract
function getVerifier() external view returns (address) {
return address(s.verifier);
}
/// @return The address of the current governor
function getGovernor() external view returns (address) {
return s.governor;
}
/// @return The address of the pending governor
function getPendingGovernor() external view returns (address) {
return s.pendingGovernor;
}
/// @return The total number of batches that were committed
function getTotalBatchesCommitted() external view returns (uint256) {
return s.totalBatchesCommitted;
}
/// @return The total number of batches that were committed & verified
function getTotalBatchesVerified() external view returns (uint256) {
return s.totalBatchesVerified;
}
/// @return The total number of batches that were committed & verified & executed
function getTotalBatchesExecuted() external view returns (uint256) {
return s.totalBatchesExecuted;
}
/// @return The total number of priority operations that were added to the priority queue, including all processed ones
function getTotalPriorityTxs() external view returns (uint256) {
return s.priorityQueue.getTotalPriorityTxs();
}
/// @notice Returns zero if and only if no operations were processed from the queue
/// @notice Reverts if there are no unprocessed priority transactions
/// @return Index of the oldest priority operation that wasn't processed yet
function getFirstUnprocessedPriorityTx() external view returns (uint256) {
return s.priorityQueue.getFirstUnprocessedPriorityTx();
}
/// @return The number of priority operations currently in the queue
function getPriorityQueueSize() external view returns (uint256) {
return s.priorityQueue.getSize();
}
/// @return The first unprocessed priority operation from the queue
function priorityQueueFrontOperation() external view returns (PriorityOperation memory) {
return s.priorityQueue.front();
}
/// @return Whether the address has a validator access
function isValidator(address _address) external view returns (bool) {
return s.validators[_address];
}
/// @return Merkle root of the tree with L2 logs for the selected batch
function l2LogsRootHash(uint256 _batchNumber) external view returns (bytes32) {
return s.l2LogsRootHashes[_batchNumber];
}
/// @notice For unfinalized (non executed) batches may change
/// @dev returns zero for non-committed batches
/// @return The hash of committed L2 batch.
function storedBatchHash(uint256 _batchNumber) external view returns (bytes32) {
return s.storedBatchHashes[_batchNumber];
}
/// @return Bytecode hash of bootloader program.
function getL2BootloaderBytecodeHash() external view returns (bytes32) {
return s.l2BootloaderBytecodeHash;
}
/// @return Bytecode hash of default account (bytecode for EOA).
function getL2DefaultAccountBytecodeHash() external view returns (bytes32) {
return s.l2DefaultAccountBytecodeHash;
}
/// @return Verifier parameters.
function getVerifierParams() external view returns (VerifierParams memory) {
return s.verifierParams;
}
/// @return The current protocol version
function getProtocolVersion() external view returns (uint256) {
return s.protocolVersion;
}
/// @return The upgrade system contract transaction hash, 0 if the upgrade is not initialized
function getL2SystemContractsUpgradeTxHash() external view returns (bytes32) {
return s.l2SystemContractsUpgradeTxHash;
}
/// @return The L2 batch number in which the upgrade transaction was processed.
/// @dev It is equal to 0 in the following two cases:
/// - No upgrade transaction has ever been processed.
/// - The upgrade transaction has been processed and the batch with such transaction has been
/// executed (i.e. finalized).
function getL2SystemContractsUpgradeBatchNumber() external view returns (uint256) {
return s.l2SystemContractsUpgradeBatchNumber;
}
/// @return Whether the diamond is frozen or not
function isDiamondStorageFrozen() external view returns (bool) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
return ds.isFrozen;
}
/// @return isFreezable Whether the facet can be frozen by the governor or always accessible
function isFacetFreezable(address _facet) external view returns (bool isFreezable) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
// There is no direct way to get whether the facet address is freezable,
// so we get it from one of the selectors that are associated with the facet.
uint256 selectorsArrayLen = ds.facetToSelectors[_facet].selectors.length;
if (selectorsArrayLen != 0) {
bytes4 selector0 = ds.facetToSelectors[_facet].selectors[0];
isFreezable = ds.selectorToFacet[selector0].isFreezable;
}
}
/// @return The maximum number of L2 gas that a user can request for L1 -> L2 transactions
function getPriorityTxMaxGasLimit() external view returns (uint256) {
return s.priorityTxMaxGasLimit;
}
/// @return The allow list smart contract
function getAllowList() external view returns (address) {
return address(s.allowList);
}
/// @return Whether the selector can be frozen by the governor or always accessible
function isFunctionFreezable(bytes4 _selector) external view returns (bool) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
require(ds.selectorToFacet[_selector].facetAddress != address(0), "g2");
return ds.selectorToFacet[_selector].isFreezable;
}
/// @return Whether a withdrawal has been finalized.
/// @param _l2BatchNumber The L2 batch number within which the withdrawal happened.
/// @param _l2MessageIndex The index of the L2->L1 message denoting the withdrawal.
function isEthWithdrawalFinalized(uint256 _l2BatchNumber, uint256 _l2MessageIndex) external view returns (bool) {
return s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex];
}
/*//////////////////////////////////////////////////////////////
DIAMOND LOUPE
//////////////////////////////////////////////////////////////*/
/// @return result All facet addresses and their function selectors
function facets() external view returns (Facet[] memory result) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
uint256 facetsLen = ds.facets.length;
result = new Facet[](facetsLen);
for (uint256 i = 0; i < facetsLen; i = i.uncheckedInc()) {
address facetAddr = ds.facets[i];
Diamond.FacetToSelectors memory facetToSelectors = ds.facetToSelectors[facetAddr];
result[i] = Facet(facetAddr, facetToSelectors.selectors);
}
}
/// @return NON-sorted array with function selectors supported by a specific facet
function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
return ds.facetToSelectors[_facet].selectors;
}
/// @return NON-sorted array of facet addresses supported on diamond
function facetAddresses() external view returns (address[] memory) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
return ds.facets;
}
/// @return Facet address associated with a selector. Zero if the selector is not added to the diamond
function facetAddress(bytes4 _selector) external view returns (address) {
Diamond.DiamondStorage storage ds = Diamond.getDiamondStorage();
return ds.selectorToFacet[_selector].facetAddress;
}
/*//////////////////////////////////////////////////////////////
DEPRECATED METHODS
//////////////////////////////////////////////////////////////*/
/// @return The total number of batches that were committed
/// @dev It is a *deprecated* method, please use `getTotalBatchesCommitted` instead
function getTotalBlocksCommitted() external view returns (uint256) {
return s.totalBatchesCommitted;
}
/// @return The total number of batches that were committed & verified
/// @dev It is a *deprecated* method, please use `getTotalBatchesVerified` instead.
function getTotalBlocksVerified() external view returns (uint256) {
return s.totalBatchesVerified;
}
/// @return The total number of batches that were committed & verified & executed
/// @dev It is a *deprecated* method, please use `getTotalBatchesExecuted` instead.
function getTotalBlocksExecuted() external view returns (uint256) {
return s.totalBatchesExecuted;
}
/// @notice For unfinalized (non executed) batches may change
/// @dev It is a *deprecated* method, please use `storedBatchHash` instead.
/// @dev returns zero for non-committed batches
/// @return The hash of committed L2 batch.
function storedBlockHash(uint256 _batchNumber) external view returns (bytes32) {
return s.storedBatchHashes[_batchNumber];
}
/// @return The L2 batch number in which the upgrade transaction was processed.
/// @dev It is a *deprecated* method, please use `getL2SystemContractsUpgradeBatchNumber` instead.
/// @dev It is equal to 0 in the following two cases:
/// - No upgrade transaction has ever been processed.
/// - The upgrade transaction has been processed and the batch with such transaction has been
/// executed (i.e. finalized).
function getL2SystemContractsUpgradeBlockNumber() external view returns (uint256) {
return s.l2SystemContractsUpgradeBatchNumber;
}
}