Skip to content

Commit 782e50a

Browse files
committed
feat: Galileo gas price oracle
1 parent 39619d8 commit 782e50a

File tree

3 files changed

+74
-36
lines changed

3 files changed

+74
-36
lines changed

src/L2/predeploys/IL1GasPriceOracle.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ interface IL1GasPriceOracle {
2323
/// @param scalar The current blob fee scalar updated.
2424
event BlobScalarUpdated(uint256 scalar);
2525

26-
/// @notice Emitted when current compression penalty threshold is updated.
27-
/// @param threshold The new compression penalty threshold.
28-
event PenaltyThresholdUpdated(uint256 threshold);
29-
3026
/// @notice Emitted when current compression penalty factor is updated.
3127
/// @param factor The new compression penalty factor.
3228
event PenaltyFactorUpdated(uint256 factor);
@@ -56,6 +52,7 @@ interface IL1GasPriceOracle {
5652
function blobScalar() external view returns (uint256);
5753

5854
/// @notice Return the current compression penalty threshold.
55+
/// @custom:deprecated The penalty threshold parameter is deprecated after the Galileo fork.
5956
function penaltyThreshold() external view returns (uint256);
6057

6158
/// @notice Return the current compression penalty factor.

src/L2/predeploys/L1GasPriceOracle.sol

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/test/L1GasPriceOracle.t.sol

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,23 @@ contract L1GasPriceOracleTest is DSTestPlus {
260260
uint256 _blobBaseFee,
261261
uint256 _commitScalar,
262262
uint256 _blobScalar,
263-
uint256 _penaltyThreshold,
264263
uint256 _penaltyFactor,
265264
bytes memory _data
266265
) external {
267266
_baseFee = bound(_baseFee, 0, 1e9 * 20000); // max 20k gwei
268267
_blobBaseFee = bound(_blobBaseFee, 0, 1e9 * 20000); // max 20k gwei
269268
_commitScalar = bound(_commitScalar, 0, MAX_COMMIT_SCALAR);
270269
_blobScalar = bound(_blobScalar, 0, MAX_BLOB_SCALAR);
271-
_penaltyThreshold = bound(_penaltyThreshold, 1e9, 1e9 * 5);
270+
// Note: setPenaltyThreshold is deprecated
271+
// _penaltyThreshold = bound(_penaltyThreshold, 1e9, 1e9 * 5);
272272
_penaltyFactor = bound(_penaltyFactor, 1e9, 1e9 * 10); // min 1x, max 10x penalty
273273

274274
oracle.enableFeynman();
275275
oracle.setCommitScalar(_commitScalar);
276276
oracle.setBlobScalar(_blobScalar);
277277
oracle.setL1BaseFeeAndBlobBaseFee(_baseFee, _blobBaseFee);
278-
oracle.setPenaltyThreshold(_penaltyThreshold);
278+
// Note: setPenaltyThreshold is deprecated
279+
// oracle.setPenaltyThreshold(_penaltyThreshold);
279280
oracle.setPenaltyFactor(_penaltyFactor);
280281

281282
assertEq(
@@ -285,4 +286,30 @@ contract L1GasPriceOracleTest is DSTestPlus {
285286
PRECISION
286287
);
287288
}
289+
290+
function testGetL1FeeGalileo(
291+
uint256 _baseFee,
292+
uint256 _blobBaseFee,
293+
uint256 _commitScalar,
294+
uint256 _blobScalar,
295+
uint256 _penaltyFactor,
296+
bytes memory _data
297+
) external {
298+
_baseFee = bound(_baseFee, 0, 1e9 * 20000); // max 20k gwei
299+
_blobBaseFee = bound(_blobBaseFee, 0, 1e9 * 20000); // max 20k gwei
300+
_commitScalar = bound(_commitScalar, 0, MAX_COMMIT_SCALAR);
301+
_blobScalar = bound(_blobScalar, 0, MAX_BLOB_SCALAR);
302+
_penaltyFactor = bound(_penaltyFactor, 1, 1e9 * 100);
303+
304+
oracle.enableGalileo();
305+
oracle.setCommitScalar(_commitScalar);
306+
oracle.setBlobScalar(_blobScalar);
307+
oracle.setL1BaseFeeAndBlobBaseFee(_baseFee, _blobBaseFee);
308+
oracle.setPenaltyFactor(_penaltyFactor);
309+
310+
uint256 _baseTerm = (_commitScalar * _baseFee + _blobScalar * _blobBaseFee) * _data.length;
311+
uint256 _penaltyTerm = (_baseTerm * _data.length) / _penaltyFactor;
312+
313+
assertEq(oracle.getL1Fee(_data), (_baseTerm + _penaltyTerm) / PRECISION);
314+
}
288315
}

0 commit comments

Comments
 (0)