@@ -4,6 +4,9 @@ pragma solidity ^0.8.24;
4
4
import {Passage} from "./Passage.sol " ;
5
5
6
6
contract Zenith {
7
+ /// @notice Each `transact` call cannot use more than 1/5 of the global `transact` gasLimit for the block.
8
+ uint256 public constant PER_TRANSACT_GAS_LIMIT = 5 ;
9
+
7
10
/// @notice The chainId of rollup that Ether will be sent to by default when entering the rollup via fallback() or receive().
8
11
uint256 public immutable defaultRollupChainId;
9
12
@@ -30,9 +33,18 @@ contract Zenith {
30
33
}
31
34
32
35
/// @notice The host block number that a block was last submitted at for a given rollup chainId.
33
- /// rollupChainId => host blockNumber that block was last submitted at
36
+ /// rollupChainId => host blockNumber the last block was submitted at.
34
37
mapping (uint256 => uint256 ) public lastSubmittedAtBlock;
35
38
39
+ /// @notice The gasLimit of the last submitted block for a given rollup chainId.
40
+ /// @dev NOTE that this can change mid-block, causing some `transact` to have a different limit than others.
41
+ /// rollupChainId => gasLimit of the previous block.
42
+ mapping (uint256 => uint256 ) public currentGasLimit;
43
+
44
+ /// @notice The total gasLimit used by `transact` so far in this block.
45
+ /// rollupChainId => block number => `transasct` gasLimit used so far.
46
+ mapping (uint256 => mapping (uint256 => uint256 )) public transactGasUsed;
47
+
36
48
/// @notice Registry of permissioned sequencers.
37
49
/// address => TRUE if it's a permissioned sequencer
38
50
mapping (address => bool ) public isSequencer;
@@ -48,6 +60,12 @@ contract Zenith {
48
60
/// @notice Thrown when attempting to submit more than one rollup block per host block
49
61
error OneRollupBlockPerHostBlock ();
50
62
63
+ /// @notice Thrown when attempting to use more then the current global `transact` gasLimit for the block.
64
+ error GlobalTransactGasLimitReached (uint256 globalTransactLimit );
65
+
66
+ /// @notice Thrown when attempting to use too much gas per single `transact` call.
67
+ error PerTransactGasLimitReached (uint256 perTransactLimit );
68
+
51
69
/// @notice Thrown when attempting to modify sequencer roles if not sequencerAdmin.
52
70
error OnlySequencerAdmin ();
53
71
@@ -133,13 +151,19 @@ contract Zenith {
133
151
// assert this is the first rollup block submitted for this host block
134
152
if (lastSubmittedAtBlock[header.rollupChainId] == block .number ) revert OneRollupBlockPerHostBlock ();
135
153
lastSubmittedAtBlock[header.rollupChainId] = block .number ;
154
+ currentGasLimit[header.rollupChainId] = header.gasLimit;
136
155
137
156
// emit event
138
157
emit BlockSubmitted (
139
158
sequencer, header.rollupChainId, header.gasLimit, header.rewardAddress, header.blockDataHash
140
159
);
141
160
}
142
161
162
+ /// @dev See `transact` for docs.
163
+ function transact (address to , bytes calldata data , uint256 value , uint256 gas , uint256 maxFeePerGas ) external {
164
+ transact (defaultRollupChainId, to, data, value, gas, maxFeePerGas);
165
+ }
166
+
143
167
/// @notice Send a special transaction to be sent to the rollup with sender == L1 msg.sender.
144
168
/// @dev Transact is processed after normal rollup block execution.
145
169
/// @param rollupChainId - The rollup chain to send the transaction to.
@@ -157,15 +181,20 @@ contract Zenith {
157
181
uint256 gas ,
158
182
uint256 maxFeePerGas
159
183
) public {
184
+ // ensure per-transact gas limit is respected
185
+ uint256 globalLimit = currentGasLimit[rollupChainId];
186
+ uint256 perTransactLimit = globalLimit / PER_TRANSACT_GAS_LIMIT;
187
+ if (gas > perTransactLimit) revert PerTransactGasLimitReached (perTransactLimit);
188
+
189
+ // ensure global transact gas limit is respected
190
+ uint256 gasUsed = transactGasUsed[rollupChainId][block .number ];
191
+ if (gasUsed + gas > globalLimit) revert GlobalTransactGasLimitReached (globalLimit);
192
+ transactGasUsed[rollupChainId][block .number ] = gasUsed + gas;
193
+
160
194
// emit Transact event
161
195
emit Transact (rollupChainId, msg .sender , to, data, value, gas, maxFeePerGas);
162
196
}
163
197
164
- /// @dev See `transact` for docs.
165
- function transact (address to , bytes calldata data , uint256 value , uint256 gas , uint256 maxFeePerGas ) external {
166
- transact (defaultRollupChainId, to, data, value, gas, maxFeePerGas);
167
- }
168
-
169
198
/// @notice Construct hash of block details that the sequencer signs.
170
199
/// @param header - the header information for the rollup block.
171
200
/// @return commit - the hash of the encoded block details.
0 commit comments