Skip to content

Commit a96cbe7

Browse files
feat(ctb): update L2 contract style (#2764)
Updates L2 contract style to match L1 contract style. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent e4b8b70 commit a96cbe7

11 files changed

Lines changed: 317 additions & 225 deletions

File tree

.changeset/gentle-pants-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@eth-optimism/contracts-bedrock': patch
3+
---
4+
5+
Fix style for L2 contracts to match L1 contracts

op-bindings/bindings/l1block.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

op-bindings/bindings/l1block_deployed.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contracts-bedrock/contracts/L2/GasPriceOracle.sol

Lines changed: 82 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.10;
33

4-
/* External Imports */
54
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
65
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
76
import { L1Block } from "../L2/L1Block.sol";
87

98
/**
9+
* @custom:proxied
10+
* @custom:predeploy 0x420000000000000000000000000000000000000F
1011
* @title GasPriceOracle
11-
* @dev This contract maintains the variables responsible for computing the L1
12-
* portion of the total fee charged on L2. The values stored in the contract
13-
* are looked up as part of the L2 state transition function and used to compute
14-
* the total fee paid by the user.
15-
* The contract exposes an API that is useful for knowing how large the L1
16-
* portion of their transaction fee will be.
17-
* This predeploy is found at 0x420000000000000000000000000000000000000F in the
18-
* L2 state.
19-
* This contract should be behind an upgradable proxy such that when the gas
20-
* prices change, the values can be updated accordingly.
12+
* @notice This contract maintains the variables responsible for computing the L1 portion of the
13+
* total fee charged on L2. The values stored in the contract are looked up as part of the
14+
* L2 state transition function and used to compute the total fee paid by the user. The
15+
* contract exposes an API that is useful for knowing how large the L1 portion of their
16+
* transaction fee will be.
2117
*/
2218
contract GasPriceOracle is Ownable {
23-
/*************
24-
* Variables *
25-
*************/
26-
27-
// backwards compatibility
19+
/**
20+
* @custom:legacy
21+
* @notice Spacer for backwards compatibility.
22+
*/
2823
uint256 internal spacer0;
24+
25+
/**
26+
* @custom:legacy
27+
* @notice Spacer for backwards compatibility.
28+
*/
2929
uint256 internal spacer1;
3030

31-
// Amortized cost of batch submission per transaction
31+
/**
32+
* @notice Constant L1 gas overhead per transaction.
33+
*/
3234
uint256 public overhead;
33-
// Value to scale the fee up by
35+
36+
/**
37+
* @notice Dynamic L1 gas overhead per transaction.
38+
*/
3439
uint256 public scalar;
35-
// Number of decimals of the scalar
36-
uint256 public decimals;
3740

38-
/***************
39-
* Constructor *
40-
***************/
41+
/**
42+
* @notice Number of decimals used in the scalar.
43+
*/
44+
uint256 public decimals;
4145

4246
/**
4347
* @param _owner Address that will initially own this contract.
@@ -46,70 +50,87 @@ contract GasPriceOracle is Ownable {
4650
transferOwnership(_owner);
4751
}
4852

49-
/**********
50-
* Events *
51-
**********/
53+
/**
54+
* @notice Emitted when the overhead value is updated.
55+
*/
56+
event OverheadUpdated(uint256 overhead);
5257

53-
event OverheadUpdated(uint256);
54-
event ScalarUpdated(uint256);
55-
event DecimalsUpdated(uint256);
58+
/**
59+
* @notice Emitted when the scalar value is updated.
60+
*/
61+
event ScalarUpdated(uint256 scalar);
5662

57-
/********************
58-
* Public Functions *
59-
********************/
63+
/**
64+
* @notice Emitted when the decimals value is updated.
65+
*/
66+
event DecimalsUpdated(uint256 decimals);
6067

61-
// legacy backwards compat
68+
/**
69+
* @notice Retrieves the current gas price (base fee).
70+
*
71+
* @return Current L2 gas price (base fee).
72+
*/
6273
function gasPrice() public returns (uint256) {
6374
return block.basefee;
6475
}
6576

77+
/**
78+
* @notice Retrieves the current base fee.
79+
*
80+
* @return Current L2 base fee.
81+
*/
6682
function baseFee() public returns (uint256) {
6783
return block.basefee;
6884
}
6985

86+
/**
87+
* @notice Retrieves the latest known L1 base fee.
88+
*
89+
* @return Latest known L1 base fee.
90+
*/
7091
function l1BaseFee() public view returns (uint256) {
7192
return L1Block(Lib_PredeployAddresses.L1_BLOCK_ATTRIBUTES).basefee();
7293
}
7394

7495
/**
75-
* Allows the owner to modify the overhead.
76-
* @param _overhead New overhead
96+
* @notice Allows the owner to modify the overhead.
97+
*
98+
* @param _overhead New overhead value.
7799
*/
78-
// slither-disable-next-line external-function
79-
function setOverhead(uint256 _overhead) public onlyOwner {
100+
function setOverhead(uint256 _overhead) external onlyOwner {
80101
overhead = _overhead;
81102
emit OverheadUpdated(_overhead);
82103
}
83104

84105
/**
85-
* Allows the owner to modify the scalar.
86-
* @param _scalar New scalar
106+
* @notice Allows the owner to modify the scalar.
107+
*
108+
* @param _scalar New scalar value.
87109
*/
88-
// slither-disable-next-line external-function
89-
function setScalar(uint256 _scalar) public onlyOwner {
110+
function setScalar(uint256 _scalar) external onlyOwner {
90111
scalar = _scalar;
91112
emit ScalarUpdated(_scalar);
92113
}
93114

94115
/**
95-
* Allows the owner to modify the decimals.
96-
* @param _decimals New decimals
116+
* @notice Allows the owner to modify the decimals.
117+
*
118+
* @param _decimals New decimals value.
97119
*/
98-
// slither-disable-next-line external-function
99-
function setDecimals(uint256 _decimals) public onlyOwner {
120+
function setDecimals(uint256 _decimals) external onlyOwner {
100121
decimals = _decimals;
101122
emit DecimalsUpdated(_decimals);
102123
}
103124

104125
/**
105-
* Computes the L1 portion of the fee
106-
* based on the size of the RLP encoded tx
107-
* and the current l1BaseFee
108-
* @param _data Unsigned RLP encoded tx, 6 elements
126+
* @notice Computes the L1 portion of the fee based on the size of the rlp encoded input
127+
* transaction, the current L1 base fee, and the various dynamic parameters.
128+
*
129+
* @param _data Unsigned fully RLP-encoded transaction to get the L1 fee for.
130+
*
109131
* @return L1 fee that should be paid for the tx
110132
*/
111-
// slither-disable-next-line external-function
112-
function getL1Fee(bytes memory _data) public view returns (uint256) {
133+
function getL1Fee(bytes memory _data) external view returns (uint256) {
113134
uint256 l1GasUsed = getL1GasUsed(_data);
114135
uint256 l1Fee = l1GasUsed * l1BaseFee();
115136
uint256 divisor = 10**decimals;
@@ -118,30 +139,16 @@ contract GasPriceOracle is Ownable {
118139
return scaled;
119140
}
120141

121-
// solhint-disable max-line-length
122-
/**
123-
* Computes the amount of L1 gas used for a transaction
124-
* The overhead represents the per batch gas overhead of
125-
* posting both transaction and state roots to L1 given larger
126-
* batch sizes.
127-
* 4 gas for 0 byte
128-
* https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L33
129-
* 16 gas for non zero byte
130-
* https://github.com/ethereum/go-ethereum/blob/9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L87
131-
* This will need to be updated if calldata gas prices change
132-
* Account for the transaction being unsigned
133-
* Padding is added to account for lack of signature on transaction
134-
* 1 byte for RLP V prefix
135-
* 1 byte for V
136-
* 1 byte for RLP R prefix
137-
* 32 bytes for R
138-
* 1 byte for RLP S prefix
139-
* 32 bytes for S
140-
* Total: 68 bytes of padding
141-
* @param _data Unsigned RLP encoded tx, 6 elements
142-
* @return Amount of L1 gas used for a transaction
143-
*/
144-
// solhint-enable max-line-length
142+
/**
143+
* @notice Computes the amount of L1 gas used for a transaction. Adds the overhead which
144+
* represents the per-transaction gas overhead of posting the transaction and state
145+
* roots to L1. Adds 68 bytes of padding to account for the fact that the input does
146+
* not have a signature.
147+
*
148+
* @param _data Unsigned fully RLP-encoded transaction to get the L1 gas for.
149+
*
150+
* @return Amount of L1 gas used to publish the transaction.
151+
*/
145152
function getL1GasUsed(bytes memory _data) public view returns (uint256) {
146153
uint256 total = 0;
147154
uint256 length = _data.length;

0 commit comments

Comments
 (0)