@@ -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,27 @@ 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+ uint256 public __penaltyThreshold ;
122112
123113 /// @inheritdoc IL1GasPriceOracle
124114 uint256 public override penaltyFactor;
125115
126116 /// @notice Indicates whether the network has gone through the Feynman upgrade.
127117 bool public isFeynman;
128118
119+ /// @notice Indicates whether the network has gone through the Galileo upgrade.
120+ bool public isGalileo;
121+
122+ /******************
123+ * View functions *
124+ ******************/
125+
126+ /// @inheritdoc IL1GasPriceOracle
127+ function penaltyThreshold () external view override returns (uint256 ) {
128+ return __penaltyThreshold;
129+ }
130+
129131 /*************
130132 * Modifiers *
131133 *************/
@@ -149,7 +151,9 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
149151
150152 /// @inheritdoc IL1GasPriceOracle
151153 function getL1Fee (bytes memory _data ) external view override returns (uint256 ) {
152- if (isFeynman) {
154+ if (isGalileo) {
155+ return _getL1FeeGalileo (_data);
156+ } else if (isFeynman) {
153157 return _getL1FeeFeynman (_data);
154158 } else if (isCurie) {
155159 return _getL1FeeCurie (_data);
@@ -160,7 +164,7 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
160164
161165 /// @inheritdoc IL1GasPriceOracle
162166 function getL1GasUsed (bytes memory _data ) public view override returns (uint256 ) {
163- if (isFeynman || isCurie) {
167+ if (isGalileo || isFeynman || isCurie) {
164168 // It is near zero since we put all transactions to blob.
165169 return 0 ;
166170 } else {
@@ -232,20 +236,10 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
232236 emit BlobScalarUpdated (_scalar);
233237 }
234238
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-
244239 /// Allows the owner to modify the penaltyFactor.
245240 /// @param _factor New factor
246241 function setPenaltyFactor (uint256 _factor ) external onlyOwner {
247- if (_factor < PRECISION || _factor > MAX_PENALTY_FACTOR) revert ErrInvalidPenaltyFactor ();
248-
242+ if (_factor == 0 ) revert ErrInvalidPenaltyFactor ();
249243 penaltyFactor = _factor;
250244 emit PenaltyFactorUpdated (_factor);
251245 }
@@ -280,6 +274,16 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
280274 isFeynman = true ;
281275 }
282276
277+ /// @notice Enable the Galileo fork (callable by contract owner).
278+ ///
279+ /// @dev Since this is a predeploy contract, we will directly set the slot while hard fork
280+ /// to avoid external owner operations.
281+ /// The reason that we keep this function is for easy unit testing.
282+ function enableGalileo () external onlyOwner {
283+ if (isGalileo) revert ErrAlreadyInGalileoFork ();
284+ isGalileo = true ;
285+ }
286+
283287 /**********************
284288 * Internal Functions *
285289 **********************/
@@ -334,4 +338,14 @@ contract L1GasPriceOracle is OwnableBase, IL1GasPriceOracle {
334338 PRECISION /
335339 PRECISION;
336340 }
341+
342+ /// @dev Internal function to compute the L1 portion of the fee based on the size of the compressed rlp-
343+ // encoded input transaction, the current L1 base fee, and the various dynamic parameters, after the Galileo fork.
344+ /// @param _data Signed fully RLP-encoded transaction to get the L1 fee for, compressed using zstd.
345+ /// @return L1 fee that should be paid for the tx
346+ function _getL1FeeGalileo (bytes memory _data ) private view returns (uint256 ) {
347+ uint256 baseTerm = (commitScalar * l1BaseFee + blobScalar * l1BlobBaseFee) * _data.length ;
348+ uint256 penaltyTerm = (baseTerm * _data.length ) / penaltyFactor;
349+ return (baseTerm + penaltyTerm) / PRECISION;
350+ }
337351}
0 commit comments