Commit c258acd4 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat(ctp): update style for L1 contracts (#2704)

Updates and standardizes the style for the L1 contracts. Adds a few
comments where things were missing.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent c836f1cb
---
'@eth-optimism/contracts-bedrock': patch
---
Update comments and style for L1 contracts
This diff is collapsed.
...@@ -6,28 +6,22 @@ import { OptimismPortal } from "./OptimismPortal.sol"; ...@@ -6,28 +6,22 @@ import { OptimismPortal } from "./OptimismPortal.sol";
import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol"; import { CrossDomainMessenger } from "../universal/CrossDomainMessenger.sol";
/** /**
* @custom:proxied
* @title L1CrossDomainMessenger * @title L1CrossDomainMessenger
* @dev The L1 Cross Domain Messenger contract sends messages from L1 to L2, and relays messages * @notice The L1CrossDomainMessenger is a message passing interface between L1 and L2 responsible
* from L2 onto L1. * for sending and receiving data on the L1 side. Users are encouraged to use this
* This contract should be deployed behind an upgradable proxy * interface instead of interacting with lower-level contracts directly.
*/ */
contract L1CrossDomainMessenger is CrossDomainMessenger { contract L1CrossDomainMessenger is CrossDomainMessenger {
/*************
* Variables *
*************/
/** /**
* @notice Address of the OptimismPortal. * @notice Address of the OptimismPortal.
*/ */
OptimismPortal public portal; OptimismPortal public portal;
/********************
* Public Functions *
********************/
/** /**
* @notice Initialize the L1CrossDomainMessenger * @notice Initializes the L1CrossDomainMessenger.
* @param _portal The OptimismPortal *
* @param _portal Address of the OptimismPortal to send and receive messages through.
*/ */
function initialize(OptimismPortal _portal) external { function initialize(OptimismPortal _portal) external {
portal = _portal; portal = _portal;
...@@ -38,21 +32,22 @@ contract L1CrossDomainMessenger is CrossDomainMessenger { ...@@ -38,21 +32,22 @@ contract L1CrossDomainMessenger is CrossDomainMessenger {
_initialize(Lib_PredeployAddresses.L2_CROSS_DOMAIN_MESSENGER, blockedSystemAddresses); _initialize(Lib_PredeployAddresses.L2_CROSS_DOMAIN_MESSENGER, blockedSystemAddresses);
} }
/**********************
* Internal Functions *
**********************/
/** /**
* @notice Ensure that the L1CrossDomainMessenger can only be called * @notice Checks whether the message being sent from the other messenger.
* by the OptimismPortal and the L2 sender is the L2CrossDomainMessenger. *
* @return True if the message was sent from the messenger, false otherwise.
*/ */
function _isSystemMessageSender() internal view override returns (bool) { function _isSystemMessageSender() internal view override returns (bool) {
return msg.sender == address(portal) && portal.l2Sender() == otherMessenger; return msg.sender == address(portal) && portal.l2Sender() == otherMessenger;
} }
/** /**
* @notice Sending a message in the L1CrossDomainMessenger involves * @notice Sends a message via the OptimismPortal contract.
* depositing through the OptimismPortal. *
* @param _to Address of the recipient on L2.
* @param _gasLimit Minimum gas limit that the message can be executed with.
* @param _value ETH value to attach to the message and send to the recipient.
* @param _data Data to attach to the message and call the recipient with.
*/ */
function _sendMessage( function _sendMessage(
address _to, address _to,
......
...@@ -8,13 +8,24 @@ import { ExcessivelySafeCall } from "../libraries/ExcessivelySafeCall.sol"; ...@@ -8,13 +8,24 @@ import { ExcessivelySafeCall } from "../libraries/ExcessivelySafeCall.sol";
import { ResourceMetering } from "./ResourceMetering.sol"; import { ResourceMetering } from "./ResourceMetering.sol";
/** /**
* @custom:proxied
* @title OptimismPortal * @title OptimismPortal
* This contract should be deployed behind an upgradable proxy. * @notice The OptimismPortal is a low-level contract responsible for passing messages between L1
* and L2. Messages sent directly to the OptimismPortal have no form of replayability.
* Users are encouraged to use the L1CrossDomainMessenger for a higher-level interface.
*/ */
contract OptimismPortal is ResourceMetering { contract OptimismPortal is ResourceMetering {
/** /**
* Emitted when a Transaction is deposited from L1 to L2. The parameters of this * @notice Emitted when a transaction is deposited from L1 to L2. The parameters of this event
* event are read by the rollup node and used to derive deposit transactions on L2. * are read by the rollup node and used to derive deposit transactions on L2.
*
* @param from Address that triggered the deposit transaction.
* @param to Address that the deposit transaction is directed to.
* @param mint Amount of ETH to mint to the sender on L2.
* @param value Amount of ETH to send to the recipient.
* @param gasLimit Minimum gas limit that the message can be executed with.
* @param isCreation Whether the message is a contract creation.
* @param data Data to attach to the message and call the recipient with.
*/ */
event TransactionDeposited( event TransactionDeposited(
address indexed from, address indexed from,
...@@ -27,40 +38,42 @@ contract OptimismPortal is ResourceMetering { ...@@ -27,40 +38,42 @@ contract OptimismPortal is ResourceMetering {
); );
/** /**
* Emitted when a withdrawal is finalized * @notice Emitted when a withdrawal transaction is finalized.
*
* @param withdrawalHash Hash of the withdrawal transaction.
* @param success Whether the withdrawal transaction was successful.
*/ */
event WithdrawalFinalized(bytes32 indexed, bool success); event WithdrawalFinalized(bytes32 indexed withdrawalHash, bool success);
/** /**
* Value used to reset the l2Sender, this is more efficient than setting it to zero. * @notice Value used to reset the l2Sender, this is more efficient than setting it to zero.
*/ */
address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD; address internal constant DEFAULT_L2_SENDER = 0x000000000000000000000000000000000000dEaD;
/** /**
* Minimum time that must elapse before a withdrawal can be finalized. * @notice Minimum time (in seconds) that must elapse before a withdrawal can be finalized.
*/ */
uint256 public immutable FINALIZATION_PERIOD_SECONDS; uint256 public immutable FINALIZATION_PERIOD_SECONDS;
/** /**
* Address of the L2OutputOracle. * @notice Address of the L2OutputOracle.
*/ */
L2OutputOracle public immutable L2_ORACLE; L2OutputOracle public immutable L2_ORACLE;
/** /**
* Public variable which can be used to read the address of the L2 account which initiated the * @notice Address of the L2 account which initiated a withdrawal in this transaction. If the
* withdrawal. Can also be used to determine whether or not execution is occuring downstream of * of this variable is the default L2 sender address, then we are NOT inside of a call
* a call to finalizeWithdrawalTransaction(). * to finalizeWithdrawalTransaction.
*/ */
address public l2Sender = DEFAULT_L2_SENDER; address public l2Sender = DEFAULT_L2_SENDER;
/** /**
* A list of withdrawal hashes which have been successfully finalized. * @notice A list of withdrawal hashes which have been successfully finalized.
* Used for replay protection.
*/ */
mapping(bytes32 => bool) public finalizedWithdrawals; mapping(bytes32 => bool) public finalizedWithdrawals;
/** /**
* @param _l2Oracle Address of the L2OutputOracle. * @param _l2Oracle Address of the L2OutputOracle.
* @param _finalizationPeriodSeconds Finalization time in seconds. * @param _finalizationPeriodSeconds Finalization time in seconds.
*/ */
constructor(L2OutputOracle _l2Oracle, uint256 _finalizationPeriodSeconds) { constructor(L2OutputOracle _l2Oracle, uint256 _finalizationPeriodSeconds) {
...@@ -69,9 +82,9 @@ contract OptimismPortal is ResourceMetering { ...@@ -69,9 +82,9 @@ contract OptimismPortal is ResourceMetering {
} }
/** /**
* Accepts value so that users can send ETH directly to this contract and have the funds be * @notice Accepts value so that users can send ETH directly to this contract and have the
* deposited to their address on L2. This is intended as a convenience function for EOAs. * funds be deposited to their address on L2. This is intended as a convenience
* Contracts should call the depositTransaction() function directly. * function for EOAs. Contracts should call the depositTransaction() function directly.
*/ */
receive() external payable { receive() external payable {
depositTransaction(msg.sender, msg.value, 100000, false, bytes("")); depositTransaction(msg.sender, msg.value, 100000, false, bytes(""));
...@@ -79,16 +92,15 @@ contract OptimismPortal is ResourceMetering { ...@@ -79,16 +92,15 @@ contract OptimismPortal is ResourceMetering {
/** /**
* @notice Accepts deposits of ETH and data, and emits a TransactionDeposited event for use in * @notice Accepts deposits of ETH and data, and emits a TransactionDeposited event for use in
* deriving deposit transactions. Note that if a deposit is made by a contract, its address will * deriving deposit transactions. Note that if a deposit is made by a contract, its
* be aliased when retrieved using `tx.origin` or `msg.sender`. This can lead to loss of funds * address will be aliased when retrieved using `tx.origin` or `msg.sender`. Consider
* in some cases which the depositing contract may not have accounted for. Consider using the * using the CrossDomainMessenger contracts for a simpler developer experience.
* Bridge or CrossDomainMessenger contracts which provide additional safety assurances.
* *
* @param _to The L2 destination address. * @param _to Target address on L2.
* @param _value The ETH value to send in the deposit transaction. * @param _value ETH value to send to the recipient.
* @param _gasLimit The L2 gasLimit. * @param _gasLimit Minimum L2 gas limit (can be greater than or equal to this value).
* @param _isCreation Whether or not the transaction should be contract creation. * @param _isCreation Whether or not the transaction is a contract creation.
* @param _data The input data. * @param _data Data to trigger the recipient with.
*/ */
function depositTransaction( function depositTransaction(
address _to, address _to,
...@@ -119,15 +131,15 @@ contract OptimismPortal is ResourceMetering { ...@@ -119,15 +131,15 @@ contract OptimismPortal is ResourceMetering {
} }
/** /**
* Finalizes a withdrawal transaction. * @notice Finalizes a withdrawal transaction.
* *
* @param _nonce Nonce for the provided message. * @param _nonce Nonce for the provided message.
* @param _sender Message sender address on L2. * @param _sender Message sender address on L2.
* @param _target Target address on L1. * @param _target Target address on L1.
* @param _value ETH to send to the target. * @param _value ETH to send to the target.
* @param _gasLimit Gas to be forwarded to the target. * @param _gasLimit Minumum gas to be forwarded to the target.
* @param _data Data to send to the target. * @param _data Data to send to the target.
* @param _l2Timestamp L2 timestamp of the outputRoot. * @param _l2Timestamp L2 timestamp of the outputRoot.
* @param _outputRootProof Inclusion proof of the withdrawer contracts storage root. * @param _outputRootProof Inclusion proof of the withdrawer contracts storage root.
* @param _withdrawalProof Inclusion proof for the given withdrawal in the withdrawer contract. * @param _withdrawalProof Inclusion proof for the given withdrawal in the withdrawer contract.
*/ */
......
...@@ -9,11 +9,12 @@ import { Burn } from "../libraries/Burn.sol"; ...@@ -9,11 +9,12 @@ import { Burn } from "../libraries/Burn.sol";
/** /**
* @title ResourceMetering * @title ResourceMetering
* @notice ResourceMetering implements an EIP-1559 style resource metering system where pricing * @notice ResourceMetering implements an EIP-1559 style resource metering system where pricing
* updates automatically based on current demand. * updates automatically based on current demand.
*/ */
contract ResourceMetering { contract ResourceMetering {
/** /**
* Struct representing current resource parameters. * @notice Represents the various parameters that control the way in which resources are
* metered. Corresponds to the EIP-1559 resource metering system.
*/ */
struct ResourceParams { struct ResourceParams {
uint128 prevBaseFee; uint128 prevBaseFee;
...@@ -22,42 +23,42 @@ contract ResourceMetering { ...@@ -22,42 +23,42 @@ contract ResourceMetering {
} }
/** /**
* Along with the resource limit, determines the target resource limit. * @notice Maximum amount of the resource that can be used within this block.
*/ */
int256 public constant ELASTICITY_MULTIPLIER = 4; int256 public constant MAX_RESOURCE_LIMIT = 8_000_000;
/** /**
* Denominator that determines max change on fee per block. * @notice Along with the resource limit, determines the target resource limit.
*/ */
int256 public constant BASE_FEE_MAX_CHANGE_DENOMINATOR = 8; int256 public constant ELASTICITY_MULTIPLIER = 4;
/** /**
* Maximum amount of deposit gas that can be used within this block. * @notice Target amount of the resource that should be used within this block.
*/ */
int256 public constant MAX_RESOURCE_LIMIT = 8_000_000; int256 public constant TARGET_RESOURCE_LIMIT = MAX_RESOURCE_LIMIT / ELASTICITY_MULTIPLIER;
/** /**
* Target amount of deposit gas that should be used within this block. * @notice Denominator that determines max change on fee per block.
*/ */
int256 public constant TARGET_RESOURCE_LIMIT = MAX_RESOURCE_LIMIT / ELASTICITY_MULTIPLIER; int256 public constant BASE_FEE_MAX_CHANGE_DENOMINATOR = 8;
/** /**
* Minimum base fee value, cannot go lower than this. * @notice Minimum base fee value, cannot go lower than this.
*/ */
int256 public constant MINIMUM_BASE_FEE = 10_000; int256 public constant MINIMUM_BASE_FEE = 10_000;
/** /**
* Initial base fee value. * @notice Initial base fee value.
*/ */
uint128 public constant INITIAL_BASE_FEE = 1_000_000_000; uint128 public constant INITIAL_BASE_FEE = 1_000_000_000;
/** /**
* EIP-1559 style gas parameters. * @notice EIP-1559 style gas parameters.
*/ */
ResourceParams public params; ResourceParams public params;
/** /**
* Sets the initial resource values. * @notice Sets initial resource parameter values.
*/ */
constructor() { constructor() {
params = ResourceParams({ params = ResourceParams({
...@@ -68,7 +69,7 @@ contract ResourceMetering { ...@@ -68,7 +69,7 @@ contract ResourceMetering {
} }
/** /**
* Meters access to a function based an amount of a requested resource. * @notice Meters access to a function based an amount of a requested resource.
* *
* @param _amount Amount of the resource requested. * @param _amount Amount of the resource requested.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment