@@ -39,17 +39,15 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
3939 /// @dev Thrown when we enable Curie fork after Curie fork.
4040 error ErrAlreadyInCurieFork ();
4141
42- /// @dev Thrown when the compression penalty threshold exceeds `MAX_PENALTY_THRESHOLD`,
43- /// or is less than 1 * PRECISION.
44- error ErrInvalidPenaltyThreshold ();
45-
46- /// @dev Thrown when the compression penalty factor exceeds `MAX_PENALTY_FACTOR`,
47- /// or is less than 1 * PRECISION.
42+ /// @dev Thrown when the penalty factor is zero.
4843 error ErrInvalidPenaltyFactor ();
4944
5045 /// @dev Thrown when we enable Feynman fork after Feynman fork.
5146 error ErrAlreadyInFeynmanFork ();
5247
48+ /// @dev Thrown when we enable Galileo fork after Galileo fork.
49+ error ErrAlreadyInGalileoFork ();
50+
5351 /*************
5452 * Constants *
5553 *************/
@@ -81,14 +79,6 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
8179 /// So, the value should not exceed 10^9 * 1e9 normally.
8280 uint256 private constant MAX_BLOB_SCALAR = 10 ** 9 * PRECISION;
8381
84- /// @dev The maximum possible compression penalty threshold after Feynman.
85- /// The value should not exceed 10^9 * 1e9 normally.
86- uint256 private constant MAX_PENALTY_THRESHOLD = 10 ** 9 * PRECISION;
87-
88- /// @dev The maximum possible compression penalty factor after Feynman.
89- /// The value should not exceed 10^9 * 1e9 normally.
90- uint256 private constant MAX_PENALTY_FACTOR = 10 ** 9 * PRECISION;
91-
9282 /*************
9383 * Variables *
9484 *************/
@@ -117,15 +107,28 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
117107 /// @notice Indicates whether the network has gone through the Curie upgrade.
118108 bool public isCurie;
119109
120- /// @inheritdoc IL1GasPriceOracle
121- uint256 public override penaltyThreshold;
110+ /// @custom:deprecated The penalty threshold parameter is deprecated after the Galileo fork.
111+ // slither-disable-next-line uninitialized-state
112+ uint256 public __penaltyThreshold;
122113
123114 /// @inheritdoc IL1GasPriceOracle
124115 uint256 public override penaltyFactor;
125116
126117 /// @notice Indicates whether the network has gone through the Feynman upgrade.
127118 bool public isFeynman;
128119
120+ /// @notice Indicates whether the network has gone through the Galileo upgrade.
121+ bool public isGalileo;
122+
123+ /******************
124+ * View functions *
125+ ******************/
126+
127+ /// @inheritdoc IL1GasPriceOracle
128+ function penaltyThreshold () external view override returns (uint256 ) {
129+ return __penaltyThreshold;
130+ }
131+
129132 /*************
130133 * Modifiers *
131134 *************/
@@ -149,7 +152,9 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
149152
150153 /// @inheritdoc IL1GasPriceOracle
151154 function getL1Fee (bytes memory _data ) external view override returns (uint256 ) {
152- if (isFeynman) {
155+ if (isGalileo) {
156+ return _getL1FeeGalileo (_data);
157+ } else if (isFeynman) {
153158 return _getL1FeeFeynman (_data);
154159 } else if (isCurie) {
155160 return _getL1FeeCurie (_data);
@@ -160,7 +165,7 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
160165
161166 /// @inheritdoc IL1GasPriceOracle
162167 function getL1GasUsed (bytes memory _data ) public view override returns (uint256 ) {
163- if (isFeynman || isCurie) {
168+ if (isGalileo || isFeynman || isCurie) {
164169 // It is near zero since we put all transactions to blob.
165170 return 0 ;
166171 } else {
@@ -232,20 +237,10 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
232237 emit BlobScalarUpdated (_scalar);
233238 }
234239
235- /// Allows the owner to modify the penaltyThreshold.
236- /// @param _threshold New threshold
237- function setPenaltyThreshold (uint256 _threshold ) external onlyOwner {
238- if (_threshold < PRECISION || _threshold > MAX_PENALTY_THRESHOLD) revert ErrInvalidPenaltyThreshold ();
239-
240- penaltyThreshold = _threshold;
241- emit PenaltyThresholdUpdated (_threshold);
242- }
243-
244240 /// Allows the owner to modify the penaltyFactor.
245241 /// @param _factor New factor
246242 function setPenaltyFactor (uint256 _factor ) external onlyOwner {
247- if (_factor < PRECISION || _factor > MAX_PENALTY_FACTOR) revert ErrInvalidPenaltyFactor ();
248-
243+ if (_factor == 0 ) revert ErrInvalidPenaltyFactor ();
249244 penaltyFactor = _factor;
250245 emit PenaltyFactorUpdated (_factor);
251246 }
@@ -280,6 +275,16 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
280275 isFeynman = true ;
281276 }
282277
278+ /// @notice Enable the Galileo fork (callable by contract owner).
279+ ///
280+ /// @dev Since this is a predeploy contract, we will directly set the slot while hard fork
281+ /// to avoid external owner operations.
282+ /// The reason that we keep this function is for easy unit testing.
283+ function enableGalileo () external onlyOwner {
284+ if (isGalileo) revert ErrAlreadyInGalileoFork ();
285+ isGalileo = true ;
286+ }
287+
283288 /**********************
284289 * Internal Functions *
285290 **********************/
@@ -334,4 +339,14 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
334339 PRECISION /
335340 PRECISION;
336341 }
342+
343+ /// @dev Internal function to compute the L1 portion of the fee based on the size of the compressed rlp-
344+ /// encoded input transaction, the current L1 base fee, and the various dynamic parameters, after the Galileo fork.
345+ /// @param _data Signed fully RLP-encoded transaction to get the L1 fee for, compressed using zstd.
346+ /// @return L1 fee that should be paid for the tx
347+ function _getL1FeeGalileo (bytes memory _data ) private view returns (uint256 ) {
348+ uint256 baseTerm = (commitScalar * l1BaseFee + blobScalar * l1BlobBaseFee) * _data.length ;
349+ uint256 penaltyTerm = (baseTerm * _data.length ) / penaltyFactor;
350+ return (baseTerm + penaltyTerm) / PRECISION;
351+ }
337352}
0 commit comments