Commit efc5337e authored by Maurelian's avatar Maurelian Committed by Kelvin Fichter

style(contracts): Rewrite solidity files with prettier

parent f77c5edd
......@@ -2,16 +2,15 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import {Lib_OVMCodec} from "../../libraries/codec/Lib_OVMCodec.sol";
/* Interface Imports */
import { ICrossDomainMessenger } from "../../libraries/bridge/ICrossDomainMessenger.sol";
import {ICrossDomainMessenger} from "../../libraries/bridge/ICrossDomainMessenger.sol";
/**
* @title IL1CrossDomainMessenger
*/
interface IL1CrossDomainMessenger is ICrossDomainMessenger {
/*******************
* Data Structures *
*******************/
......@@ -24,7 +23,6 @@ interface IL1CrossDomainMessenger is ICrossDomainMessenger {
bytes storageTrieWitness;
}
/********************
* Public Functions *
********************/
......
......@@ -5,12 +5,11 @@ pragma solidity >0.5.0 <0.9.0;
* @title IL1ERC20Bridge
*/
interface IL1ERC20Bridge {
/**********
* Events *
**********/
event ERC20DepositInitiated (
event ERC20DepositInitiated(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
......@@ -19,7 +18,7 @@ interface IL1ERC20Bridge {
bytes _data
);
event ERC20WithdrawalFinalized (
event ERC20WithdrawalFinalized(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
......@@ -36,7 +35,7 @@ interface IL1ERC20Bridge {
* @dev get the address of the corresponding L2 bridge contract.
* @return Address of the corresponding L2 bridge contract.
*/
function l2TokenBridge() external returns(address);
function l2TokenBridge() external returns (address);
/**
* @dev deposit an amount of the ERC20 to the caller's balance on L2.
......@@ -48,14 +47,13 @@ interface IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositERC20 (
function depositERC20(
address _l1Token,
address _l2Token,
uint _amount,
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
)
external;
) external;
/**
* @dev deposit an amount of ERC20 to a recipient's balance on L2.
......@@ -68,16 +66,14 @@ interface IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositERC20To (
function depositERC20To(
address _l1Token,
address _l2Token,
address _to,
uint _amount,
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
)
external;
) external;
/*************************
* Cross-chain Functions *
......@@ -97,13 +93,12 @@ interface IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function finalizeERC20Withdrawal (
function finalizeERC20Withdrawal(
address _l1Token,
address _l2Token,
address _from,
address _to,
uint _amount,
uint256 _amount,
bytes calldata _data
)
external;
) external;
}
......@@ -7,18 +7,17 @@ import "./IL1ERC20Bridge.sol";
* @title IL1StandardBridge
*/
interface IL1StandardBridge is IL1ERC20Bridge {
/**********
* Events *
**********/
event ETHDepositInitiated (
event ETHDepositInitiated(
address indexed _from,
address indexed _to,
uint256 _amount,
bytes _data
);
event ETHWithdrawalFinalized (
event ETHWithdrawalFinalized(
address indexed _from,
address indexed _to,
uint256 _amount,
......@@ -36,12 +35,7 @@ interface IL1StandardBridge is IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositETH (
uint32 _l2Gas,
bytes calldata _data
)
external
payable;
function depositETH(uint32 _l2Gas, bytes calldata _data) external payable;
/**
* @dev Deposit an amount of ETH to a recipient's balance on L2.
......@@ -51,13 +45,11 @@ interface IL1StandardBridge is IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function depositETHTo (
function depositETHTo(
address _to,
uint32 _l2Gas,
bytes calldata _data
)
external
payable;
) external payable;
/*************************
* Cross-chain Functions *
......@@ -74,11 +66,10 @@ interface IL1StandardBridge is IL1ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function finalizeETHWithdrawal (
function finalizeETHWithdrawal(
address _from,
address _to,
uint _amount,
uint256 _amount,
bytes calldata _data
)
external;
) external;
}
......@@ -2,16 +2,16 @@
pragma solidity ^0.8.9;
/* Interface Imports */
import { IL1StandardBridge } from "./IL1StandardBridge.sol";
import { IL1ERC20Bridge } from "./IL1ERC20Bridge.sol";
import { IL2ERC20Bridge } from "../../L2/messaging/IL2ERC20Bridge.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IL1StandardBridge} from "./IL1StandardBridge.sol";
import {IL1ERC20Bridge} from "./IL1ERC20Bridge.sol";
import {IL2ERC20Bridge} from "../../L2/messaging/IL2ERC20Bridge.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/* Library Imports */
import { CrossDomainEnabled } from "../../libraries/bridge/CrossDomainEnabled.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {CrossDomainEnabled} from "../../libraries/bridge/CrossDomainEnabled.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/**
* @title L1StandardBridge
......@@ -31,16 +31,14 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
address public l2TokenBridge;
// Maps L1 token to L2 token to balance of the L1 token deposited
mapping(address => mapping (address => uint256)) public deposits;
mapping(address => mapping(address => uint256)) public deposits;
/***************
* Constructor *
***************/
// This contract lives behind a proxy, so the constructor parameters will go unused.
constructor()
CrossDomainEnabled(address(0))
{}
constructor() CrossDomainEnabled(address(0)) {}
/******************
* Initialization *
......@@ -50,12 +48,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
* @param _l1messenger L1 Messenger address being used for cross-chain communications.
* @param _l2TokenBridge L2 standard bridge address.
*/
function initialize(
address _l1messenger,
address _l2TokenBridge
)
public
{
function initialize(address _l1messenger, address _l2TokenBridge) public {
require(messenger == address(0), "Contract has already been initialized.");
messenger = _l1messenger;
l2TokenBridge = _l2TokenBridge;
......@@ -80,36 +73,15 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
* Since the receive function doesn't take data, a conservative
* default amount is forwarded to L2.
*/
receive()
external
payable
onlyEOA()
{
_initiateETHDeposit(
msg.sender,
msg.sender,
1_300_000,
bytes("")
);
receive() external payable onlyEOA {
_initiateETHDeposit(msg.sender, msg.sender, 1_300_000, bytes(""));
}
/**
* @inheritdoc IL1StandardBridge
*/
function depositETH(
uint32 _l2Gas,
bytes calldata _data
)
external
payable
onlyEOA()
{
_initiateETHDeposit(
msg.sender,
msg.sender,
_l2Gas,
_data
);
function depositETH(uint32 _l2Gas, bytes calldata _data) external payable onlyEOA {
_initiateETHDeposit(msg.sender, msg.sender, _l2Gas, _data);
}
/**
......@@ -119,16 +91,8 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
address _to,
uint32 _l2Gas,
bytes calldata _data
)
external
payable
{
_initiateETHDeposit(
msg.sender,
_to,
_l2Gas,
_data
);
) external payable {
_initiateETHDeposit(msg.sender, _to, _l2Gas, _data);
}
/**
......@@ -146,27 +110,20 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
address _to,
uint32 _l2Gas,
bytes memory _data
)
internal
{
) internal {
// Construct calldata for finalizeDeposit call
bytes memory message =
abi.encodeWithSelector(
IL2ERC20Bridge.finalizeDeposit.selector,
address(0),
Lib_PredeployAddresses.OVM_ETH,
_from,
_to,
msg.value,
_data
);
bytes memory message = abi.encodeWithSelector(
IL2ERC20Bridge.finalizeDeposit.selector,
address(0),
Lib_PredeployAddresses.OVM_ETH,
_from,
_to,
msg.value,
_data
);
// Send calldata into L2
sendCrossDomainMessage(
l2TokenBridge,
_l2Gas,
message
);
sendCrossDomainMessage(l2TokenBridge, _l2Gas, message);
emit ETHDepositInitiated(_from, _to, msg.value, _data);
}
......@@ -180,15 +137,11 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
)
external
virtual
onlyEOA()
{
) external virtual onlyEOA {
_initiateERC20Deposit(_l1Token, _l2Token, msg.sender, msg.sender, _amount, _l2Gas, _data);
}
/**
/**
* @inheritdoc IL1ERC20Bridge
*/
function depositERC20To(
......@@ -198,10 +151,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
)
external
virtual
{
) external virtual {
_initiateERC20Deposit(_l1Token, _l2Token, msg.sender, _to, _amount, _l2Gas, _data);
}
......@@ -227,17 +177,11 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l2Gas,
bytes calldata _data
)
internal
{
) internal {
// When a deposit is initiated on L1, the L1 Bridge transfers the funds to itself for future
// withdrawals. safeTransferFrom also checks if the contract has code, so this will fail if
// _from is an EOA or address(0).
IERC20(_l1Token).safeTransferFrom(
_from,
address(this),
_amount
);
IERC20(_l1Token).safeTransferFrom(_from, address(this), _amount);
// Construct calldata for _l2Token.finalizeDeposit(_to, _amount)
bytes memory message = abi.encodeWithSelector(
......@@ -251,11 +195,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
);
// Send calldata into L2
sendCrossDomainMessage(
l2TokenBridge,
_l2Gas,
message
);
sendCrossDomainMessage(l2TokenBridge, _l2Gas, message);
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] + _amount;
......@@ -266,7 +206,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
* Cross-chain Functions *
*************************/
/**
/**
* @inheritdoc IL1StandardBridge
*/
function finalizeETHWithdrawal(
......@@ -274,10 +214,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
address _to,
uint256 _amount,
bytes calldata _data
)
external
onlyFromCrossDomainAccount(l2TokenBridge)
{
) external onlyFromCrossDomainAccount(l2TokenBridge) {
(bool success, ) = _to.call{value: _amount}(new bytes(0));
require(success, "TransferHelper::safeTransferETH: ETH transfer failed");
......@@ -294,10 +231,7 @@ contract L1StandardBridge is IL1StandardBridge, CrossDomainEnabled {
address _to,
uint256 _amount,
bytes calldata _data
)
external
onlyFromCrossDomainAccount(l2TokenBridge)
{
) external onlyFromCrossDomainAccount(l2TokenBridge) {
deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] - _amount;
// When a withdrawal is finalized on L1, the L1 Bridge transfers the funds to the withdrawer
......
......@@ -2,11 +2,11 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_Buffer } from "../../libraries/utils/Lib_Buffer.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import {Lib_Buffer} from "../../libraries/utils/Lib_Buffer.sol";
import {Lib_AddressResolver} from "../../libraries/resolver/Lib_AddressResolver.sol";
/* Interface Imports */
import { IChainStorageContainer } from "./IChainStorageContainer.sol";
import {IChainStorageContainer} from "./IChainStorageContainer.sol";
/**
* @title ChainStorageContainer
......@@ -22,14 +22,12 @@ import { IChainStorageContainer } from "./IChainStorageContainer.sol";
* Runtime target: EVM
*/
contract ChainStorageContainer is IChainStorageContainer, Lib_AddressResolver {
/*************
* Libraries *
*************/
using Lib_Buffer for Lib_Buffer.Buffer;
/*************
* Variables *
*************/
......@@ -37,7 +35,6 @@ contract ChainStorageContainer is IChainStorageContainer, Lib_AddressResolver {
string public owner;
Lib_Buffer.Buffer internal buffer;
/***************
* Constructor *
***************/
......@@ -46,16 +43,12 @@ contract ChainStorageContainer is IChainStorageContainer, Lib_AddressResolver {
* @param _libAddressManager Address of the Address Manager.
* @param _owner Name of the contract that owns this container (will be resolved later).
*/
constructor(
address _libAddressManager,
string memory _owner
)
constructor(address _libAddressManager, string memory _owner)
Lib_AddressResolver(_libAddressManager)
{
owner = _owner;
}
/**********************
* Function Modifiers *
**********************/
......@@ -68,7 +61,6 @@ contract ChainStorageContainer is IChainStorageContainer, Lib_AddressResolver {
_;
}
/********************
* Public Functions *
********************/
......@@ -76,108 +68,59 @@ contract ChainStorageContainer is IChainStorageContainer, Lib_AddressResolver {
/**
* @inheritdoc IChainStorageContainer
*/
function setGlobalMetadata(
bytes27 _globalMetadata
)
public
onlyOwner
{
function setGlobalMetadata(bytes27 _globalMetadata) public onlyOwner {
return buffer.setExtraData(_globalMetadata);
}
/**
* @inheritdoc IChainStorageContainer
*/
function getGlobalMetadata()
public
view
returns (
bytes27
)
{
function getGlobalMetadata() public view returns (bytes27) {
return buffer.getExtraData();
}
/**
* @inheritdoc IChainStorageContainer
*/
function length()
public
view
returns (
uint256
)
{
function length() public view returns (uint256) {
return uint256(buffer.getLength());
}
/**
* @inheritdoc IChainStorageContainer
*/
function push(
bytes32 _object
)
public
onlyOwner
{
function push(bytes32 _object) public onlyOwner {
buffer.push(_object);
}
/**
* @inheritdoc IChainStorageContainer
*/
function push(
bytes32 _object,
bytes27 _globalMetadata
)
public
onlyOwner
{
function push(bytes32 _object, bytes27 _globalMetadata) public onlyOwner {
buffer.push(_object, _globalMetadata);
}
/**
* @inheritdoc IChainStorageContainer
*/
function get(
uint256 _index
)
public
view
returns (
bytes32
)
{
function get(uint256 _index) public view returns (bytes32) {
return buffer.get(uint40(_index));
}
/**
* @inheritdoc IChainStorageContainer
*/
function deleteElementsAfterInclusive(
uint256 _index
)
public
onlyOwner
{
buffer.deleteElementsAfterInclusive(
uint40(_index)
);
function deleteElementsAfterInclusive(uint256 _index) public onlyOwner {
buffer.deleteElementsAfterInclusive(uint40(_index));
}
/**
* @inheritdoc IChainStorageContainer
*/
function deleteElementsAfterInclusive(
uint256 _index,
bytes27 _globalMetadata
)
function deleteElementsAfterInclusive(uint256 _index, bytes27 _globalMetadata)
public
onlyOwner
{
buffer.deleteElementsAfterInclusive(
uint40(_index),
_globalMetadata
);
buffer.deleteElementsAfterInclusive(uint40(_index), _globalMetadata);
}
}
......@@ -2,16 +2,15 @@
pragma solidity >0.5.0 <0.9.0;
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import {Lib_OVMCodec} from "../../libraries/codec/Lib_OVMCodec.sol";
/* Interface Imports */
import { IChainStorageContainer } from "./IChainStorageContainer.sol";
import {IChainStorageContainer} from "./IChainStorageContainer.sol";
/**
* @title ICanonicalTransactionChain
*/
interface ICanonicalTransactionChain {
/**********
* Events *
**********/
......@@ -51,7 +50,6 @@ interface ICanonicalTransactionChain {
bytes _extraData
);
/***********
* Structs *
***********/
......@@ -71,8 +69,7 @@ interface ICanonicalTransactionChain {
* Allows the Burn Admin to update the parameters which determine the amount of gas to burn.
* The value of enqueueL2GasPrepaid is immediately updated as well.
*/
function setGasParams(uint256 _l2GasDiscountDivisor, uint256 _enqueueGasCost)
external;
function setGasParams(uint256 _l2GasDiscountDivisor, uint256 _enqueueGasCost) external;
/********************
* Public Functions *
......@@ -82,116 +79,66 @@ interface ICanonicalTransactionChain {
* Accesses the batch storage container.
* @return Reference to the batch storage container.
*/
function batches()
external
view
returns (
IChainStorageContainer
);
function batches() external view returns (IChainStorageContainer);
/**
* Accesses the queue storage container.
* @return Reference to the queue storage container.
*/
function queue()
external
view
returns (
IChainStorageContainer
);
function queue() external view returns (IChainStorageContainer);
/**
* Retrieves the total number of elements submitted.
* @return _totalElements Total submitted elements.
*/
function getTotalElements()
external
view
returns (
uint256 _totalElements
);
function getTotalElements() external view returns (uint256 _totalElements);
/**
* Retrieves the total number of batches submitted.
* @return _totalBatches Total submitted batches.
*/
function getTotalBatches()
external
view
returns (
uint256 _totalBatches
);
function getTotalBatches() external view returns (uint256 _totalBatches);
/**
* Returns the index of the next element to be enqueued.
* @return Index for the next queue element.
*/
function getNextQueueIndex()
external
view
returns (
uint40
);
function getNextQueueIndex() external view returns (uint40);
/**
* Gets the queue element at a particular index.
* @param _index Index of the queue element to access.
* @return _element Queue element at the given index.
*/
function getQueueElement(
uint256 _index
)
function getQueueElement(uint256 _index)
external
view
returns (
Lib_OVMCodec.QueueElement memory _element
);
returns (Lib_OVMCodec.QueueElement memory _element);
/**
* Returns the timestamp of the last transaction.
* @return Timestamp for the last transaction.
*/
function getLastTimestamp()
external
view
returns (
uint40
);
function getLastTimestamp() external view returns (uint40);
/**
* Returns the blocknumber of the last transaction.
* @return Blocknumber for the last transaction.
*/
function getLastBlockNumber()
external
view
returns (
uint40
);
function getLastBlockNumber() external view returns (uint40);
/**
* Get the number of queue elements which have not yet been included.
* @return Number of pending queue elements.
*/
function getNumPendingQueueElements()
external
view
returns (
uint40
);
function getNumPendingQueueElements() external view returns (uint40);
/**
* Retrieves the length of the queue, including
* both pending and canonical transactions.
* @return Length of the queue.
*/
function getQueueLength()
external
view
returns (
uint40
);
function getQueueLength() external view returns (uint40);
/**
* Adds a transaction to the queue.
......@@ -203,8 +150,7 @@ interface ICanonicalTransactionChain {
address _target,
uint256 _gasLimit,
bytes memory _data
)
external;
) external;
/**
* Allows the sequencer to append a batch of transactions.
......@@ -219,6 +165,5 @@ interface ICanonicalTransactionChain {
// uint24 _totalElementsToAppend,
// BatchContext[] _contexts,
// bytes[] _transactionDataFields
)
external;
) external;
}
......@@ -5,7 +5,6 @@ pragma solidity >0.5.0 <0.9.0;
* @title IChainStorageContainer
*/
interface IChainStorageContainer {
/********************
* Public Functions *
********************/
......@@ -16,41 +15,25 @@ interface IChainStorageContainer {
* 27 bytes to store arbitrary data.
* @param _globalMetadata New global metadata to set.
*/
function setGlobalMetadata(
bytes27 _globalMetadata
)
external;
function setGlobalMetadata(bytes27 _globalMetadata) external;
/**
* Retrieves the container's global metadata field.
* @return Container global metadata field.
*/
function getGlobalMetadata()
external
view
returns (
bytes27
);
function getGlobalMetadata() external view returns (bytes27);
/**
* Retrieves the number of objects stored in the container.
* @return Number of objects in the container.
*/
function length()
external
view
returns (
uint256
);
function length() external view returns (uint256);
/**
* Pushes an object into the container.
* @param _object A 32 byte value to insert into the container.
*/
function push(
bytes32 _object
)
external;
function push(bytes32 _object) external;
/**
* Pushes an object into the container. Function allows setting the global metadata since
......@@ -59,34 +42,20 @@ interface IChainStorageContainer {
* @param _object A 32 byte value to insert into the container.
* @param _globalMetadata New global metadata for the container.
*/
function push(
bytes32 _object,
bytes27 _globalMetadata
)
external;
function push(bytes32 _object, bytes27 _globalMetadata) external;
/**
* Retrieves an object from the container.
* @param _index Index of the particular object to access.
* @return 32 byte object value.
*/
function get(
uint256 _index
)
external
view
returns (
bytes32
);
function get(uint256 _index) external view returns (bytes32);
/**
* Removes all objects after and including a given index.
* @param _index Object index to delete from.
*/
function deleteElementsAfterInclusive(
uint256 _index
)
external;
function deleteElementsAfterInclusive(uint256 _index) external;
/**
* Removes all objects after and including a given index. Also allows setting the global
......@@ -94,9 +63,5 @@ interface IChainStorageContainer {
* @param _index Object index to delete from.
* @param _globalMetadata New global metadata for the container.
*/
function deleteElementsAfterInclusive(
uint256 _index,
bytes27 _globalMetadata
)
external;
function deleteElementsAfterInclusive(uint256 _index, bytes27 _globalMetadata) external;
}
......@@ -2,13 +2,12 @@
pragma solidity >0.5.0 <0.9.0;
/* Library Imports */
import { Lib_OVMCodec } from "../../libraries/codec/Lib_OVMCodec.sol";
import {Lib_OVMCodec} from "../../libraries/codec/Lib_OVMCodec.sol";
/**
* @title IStateCommitmentChain
*/
interface IStateCommitmentChain {
/**********
* Events *
**********/
......@@ -21,11 +20,7 @@ interface IStateCommitmentChain {
bytes _extraData
);
event StateBatchDeleted(
uint256 indexed _batchIndex,
bytes32 _batchRoot
);
event StateBatchDeleted(uint256 indexed _batchIndex, bytes32 _batchRoot);
/********************
* Public Functions *
......@@ -35,54 +30,32 @@ interface IStateCommitmentChain {
* Retrieves the total number of elements submitted.
* @return _totalElements Total submitted elements.
*/
function getTotalElements()
external
view
returns (
uint256 _totalElements
);
function getTotalElements() external view returns (uint256 _totalElements);
/**
* Retrieves the total number of batches submitted.
* @return _totalBatches Total submitted batches.
*/
function getTotalBatches()
external
view
returns (
uint256 _totalBatches
);
function getTotalBatches() external view returns (uint256 _totalBatches);
/**
* Retrieves the timestamp of the last batch submitted by the sequencer.
* @return _lastSequencerTimestamp Last sequencer batch timestamp.
*/
function getLastSequencerTimestamp()
external
view
returns (
uint256 _lastSequencerTimestamp
);
function getLastSequencerTimestamp() external view returns (uint256 _lastSequencerTimestamp);
/**
* Appends a batch of state roots to the chain.
* @param _batch Batch of state roots.
* @param _shouldStartAtElement Index of the element at which this batch should start.
*/
function appendStateBatch(
bytes32[] calldata _batch,
uint256 _shouldStartAtElement
)
external;
function appendStateBatch(bytes32[] calldata _batch, uint256 _shouldStartAtElement) external;
/**
* Deletes all state roots after (and including) a given batch.
* @param _batchHeader Header of the batch to start deleting from.
*/
function deleteStateBatch(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
external;
function deleteStateBatch(Lib_OVMCodec.ChainBatchHeader memory _batchHeader) external;
/**
* Verifies a batch inclusion proof.
......@@ -94,24 +67,15 @@ interface IStateCommitmentChain {
bytes32 _element,
Lib_OVMCodec.ChainBatchHeader memory _batchHeader,
Lib_OVMCodec.ChainInclusionProof memory _proof
)
external
view
returns (
bool _verified
);
) external view returns (bool _verified);
/**
* Checks whether a given batch is still inside its fraud proof window.
* @param _batchHeader Header of the batch to check.
* @return _inside Whether or not the batch is inside the fraud proof window.
*/
function insideFraudProofWindow(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
function insideFraudProofWindow(Lib_OVMCodec.ChainBatchHeader memory _batchHeader)
external
view
returns (
bool _inside
);
returns (bool _inside);
}
......@@ -2,10 +2,10 @@
pragma solidity ^0.8.9;
/* Interface Imports */
import { IBondManager } from "./IBondManager.sol";
import {IBondManager} from "./IBondManager.sol";
/* Contract Imports */
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
import {Lib_AddressResolver} from "../../libraries/resolver/Lib_AddressResolver.sol";
/**
* @title BondManager
......@@ -15,15 +15,10 @@ import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolve
* Runtime target: EVM
*/
contract BondManager is IBondManager, Lib_AddressResolver {
/**
* @param _libAddressManager Address of the Address Manager.
*/
constructor(
address _libAddressManager
)
Lib_AddressResolver(_libAddressManager)
{}
constructor(address _libAddressManager) Lib_AddressResolver(_libAddressManager) {}
/**
* Checks whether a given address is properly collateralized and can perform actions within
......@@ -31,15 +26,7 @@ contract BondManager is IBondManager, Lib_AddressResolver {
* @param _who Address to check.
* @return true if the address is properly collateralized, false otherwise.
*/
function isCollateralized(
address _who
)
public
view
returns (
bool
)
{
function isCollateralized(address _who) public view returns (bool) {
// Only authenticate sequencer to submit state root batches.
return _who == resolve("OVM_Proposer");
}
......
......@@ -5,12 +5,9 @@ pragma solidity ^0.8.9;
* @title IBondManager
*/
interface IBondManager {
/********************
* Public Functions *
********************/
function isCollateralized(
address _who
) external view returns (bool);
function isCollateralized(address _who) external view returns (bool);
}
......@@ -2,13 +2,12 @@
pragma solidity ^0.8.9;
/* Interface Imports */
import { ICrossDomainMessenger } from "../../libraries/bridge/ICrossDomainMessenger.sol";
import {ICrossDomainMessenger} from "../../libraries/bridge/ICrossDomainMessenger.sol";
/**
* @title IL2CrossDomainMessenger
*/
interface IL2CrossDomainMessenger is ICrossDomainMessenger {
/********************
* Public Functions *
********************/
......
......@@ -5,12 +5,11 @@ pragma solidity ^0.8.9;
* @title IL2ERC20Bridge
*/
interface IL2ERC20Bridge {
/**********
* Events *
**********/
event WithdrawalInitiated (
event WithdrawalInitiated(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
......@@ -19,7 +18,7 @@ interface IL2ERC20Bridge {
bytes _data
);
event DepositFinalized (
event DepositFinalized(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
......@@ -28,7 +27,7 @@ interface IL2ERC20Bridge {
bytes _data
);
event DepositFailed (
event DepositFailed(
address indexed _l1Token,
address indexed _l2Token,
address indexed _from,
......@@ -37,7 +36,6 @@ interface IL2ERC20Bridge {
bytes _data
);
/********************
* Public Functions *
********************/
......@@ -46,7 +44,7 @@ interface IL2ERC20Bridge {
* @dev get the address of the corresponding L1 bridge contract.
* @return Address of the corresponding L1 bridge contract.
*/
function l1TokenBridge() external returns(address);
function l1TokenBridge() external returns (address);
/**
* @dev initiate a withdraw of some tokens to the caller's account on L1
......@@ -57,13 +55,12 @@ interface IL2ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function withdraw (
function withdraw(
address _l2Token,
uint _amount,
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
)
external;
) external;
/**
* @dev initiate a withdraw of some token to a recipient's account on L1.
......@@ -75,14 +72,13 @@ interface IL2ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function withdrawTo (
function withdrawTo(
address _l2Token,
address _to,
uint _amount,
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
)
external;
) external;
/*************************
* Cross-chain Functions *
......@@ -101,14 +97,12 @@ interface IL2ERC20Bridge {
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/
function finalizeDeposit (
function finalizeDeposit(
address _l1Token,
address _l2Token,
address _from,
address _to,
uint _amount,
uint256 _amount,
bytes calldata _data
)
external;
) external;
}
......@@ -2,60 +2,50 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { AddressAliasHelper } from "../../standards/AddressAliasHelper.sol";
import { Lib_CrossDomainUtils } from "../../libraries/bridge/Lib_CrossDomainUtils.sol";
import { Lib_DefaultValues } from "../../libraries/constants/Lib_DefaultValues.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {AddressAliasHelper} from "../../standards/AddressAliasHelper.sol";
import {Lib_CrossDomainUtils} from "../../libraries/bridge/Lib_CrossDomainUtils.sol";
import {Lib_DefaultValues} from "../../libraries/constants/Lib_DefaultValues.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
/* Interface Imports */
import { IL2CrossDomainMessenger } from "./IL2CrossDomainMessenger.sol";
import { iOVM_L2ToL1MessagePasser } from "../predeploys/iOVM_L2ToL1MessagePasser.sol";
import {IL2CrossDomainMessenger} from "./IL2CrossDomainMessenger.sol";
import {iOVM_L2ToL1MessagePasser} from "../predeploys/iOVM_L2ToL1MessagePasser.sol";
/**
* @title L2CrossDomainMessenger
* @dev The L2 Cross Domain Messenger contract sends messages from L2 to L1, and is the entry point
* for L2 messages sent via the L1 Cross Domain Messenger.
*
*/
contract L2CrossDomainMessenger is
IL2CrossDomainMessenger
{
*/
contract L2CrossDomainMessenger is IL2CrossDomainMessenger {
/*************
* Variables *
*************/
mapping (bytes32 => bool) public relayedMessages;
mapping (bytes32 => bool) public successfulMessages;
mapping (bytes32 => bool) public sentMessages;
mapping(bytes32 => bool) public relayedMessages;
mapping(bytes32 => bool) public successfulMessages;
mapping(bytes32 => bool) public sentMessages;
uint256 public messageNonce;
address internal xDomainMsgSender = Lib_DefaultValues.DEFAULT_XDOMAIN_SENDER;
address public l1CrossDomainMessenger;
/***************
* Constructor *
***************/
constructor(
address _l1CrossDomainMessenger
) {
constructor(address _l1CrossDomainMessenger) {
l1CrossDomainMessenger = _l1CrossDomainMessenger;
}
/********************
* Public Functions *
********************/
function xDomainMessageSender()
public
view
returns (
address
)
{
require(xDomainMsgSender != Lib_DefaultValues.DEFAULT_XDOMAIN_SENDER, "xDomainMessageSender is not set");
function xDomainMessageSender() public view returns (address) {
require(
xDomainMsgSender != Lib_DefaultValues.DEFAULT_XDOMAIN_SENDER,
"xDomainMessageSender is not set"
);
return xDomainMsgSender;
}
......@@ -69,9 +59,7 @@ contract L2CrossDomainMessenger is
address _target,
bytes memory _message,
uint32 _gasLimit
)
public
{
) public {
bytes memory xDomainCalldata = Lib_CrossDomainUtils.encodeXDomainCalldata(
_target,
msg.sender,
......@@ -82,9 +70,9 @@ contract L2CrossDomainMessenger is
sentMessages[keccak256(xDomainCalldata)] = true;
// Actually send the message.
iOVM_L2ToL1MessagePasser(
Lib_PredeployAddresses.L2_TO_L1_MESSAGE_PASSER
).passMessageToL1(xDomainCalldata);
iOVM_L2ToL1MessagePasser(Lib_PredeployAddresses.L2_TO_L1_MESSAGE_PASSER).passMessageToL1(
xDomainCalldata
);
// Emit an event before we bump the nonce or the nonce will be off by one.
emit SentMessage(_target, msg.sender, _message, messageNonce, _gasLimit);
......@@ -100,9 +88,7 @@ contract L2CrossDomainMessenger is
address _sender,
bytes memory _message,
uint256 _messageNonce
)
public
{
) public {
require(
AddressAliasHelper.undoL1ToL2Alias(msg.sender) == l1CrossDomainMessenger,
"Provided message could not be verified."
......@@ -146,13 +132,7 @@ contract L2CrossDomainMessenger is
// Store an identifier that can be used to prove that the given message was relayed by some
// user. Gives us an easy way to pay relayers for their work.
bytes32 relayId = keccak256(
abi.encodePacked(
xDomainCalldata,
msg.sender,
block.number
)
);
bytes32 relayId = keccak256(abi.encodePacked(xDomainCalldata, msg.sender, block.number));
relayedMessages[relayId] = true;
}
......
......@@ -2,17 +2,17 @@
pragma solidity ^0.8.9;
/* Interface Imports */
import { IL1StandardBridge } from "../../L1/messaging/IL1StandardBridge.sol";
import { IL1ERC20Bridge } from "../../L1/messaging/IL1ERC20Bridge.sol";
import { IL2ERC20Bridge } from "./IL2ERC20Bridge.sol";
import {IL1StandardBridge} from "../../L1/messaging/IL1StandardBridge.sol";
import {IL1ERC20Bridge} from "../../L1/messaging/IL1ERC20Bridge.sol";
import {IL2ERC20Bridge} from "./IL2ERC20Bridge.sol";
/* Library Imports */
import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import { CrossDomainEnabled } from "../../libraries/bridge/CrossDomainEnabled.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import {CrossDomainEnabled} from "../../libraries/bridge/CrossDomainEnabled.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
/* Contract Imports */
import { IL2StandardERC20 } from "../../standards/IL2StandardERC20.sol";
import {IL2StandardERC20} from "../../standards/IL2StandardERC20.sol";
/**
* @title L2StandardBridge
......@@ -24,7 +24,6 @@ import { IL2StandardERC20 } from "../../standards/IL2StandardERC20.sol";
* bridge to release L1 funds.
*/
contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
/********************************
* External Contract References *
********************************/
......@@ -39,10 +38,7 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
* @param _l2CrossDomainMessenger Cross-domain messenger used by this contract.
* @param _l1TokenBridge Address of the L1 bridge deployed to the main chain.
*/
constructor(
address _l2CrossDomainMessenger,
address _l1TokenBridge
)
constructor(address _l2CrossDomainMessenger, address _l1TokenBridge)
CrossDomainEnabled(_l2CrossDomainMessenger)
{
l1TokenBridge = _l1TokenBridge;
......@@ -60,18 +56,8 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
)
external
virtual
{
_initiateWithdrawal(
_l2Token,
msg.sender,
msg.sender,
_amount,
_l1Gas,
_data
);
) external virtual {
_initiateWithdrawal(_l2Token, msg.sender, msg.sender, _amount, _l1Gas, _data);
}
/**
......@@ -83,18 +69,8 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
)
external
virtual
{
_initiateWithdrawal(
_l2Token,
msg.sender,
_to,
_amount,
_l1Gas,
_data
);
) external virtual {
_initiateWithdrawal(_l2Token, msg.sender, _to, _amount, _l1Gas, _data);
}
/**
......@@ -116,9 +92,7 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
uint256 _amount,
uint32 _l1Gas,
bytes calldata _data
)
internal
{
) internal {
// When a withdrawal is initiated, we burn the withdrawer's funds to prevent subsequent L2
// usage
IL2StandardERC20(_l2Token).burn(msg.sender, _amount);
......@@ -129,30 +103,26 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
if (_l2Token == Lib_PredeployAddresses.OVM_ETH) {
message = abi.encodeWithSelector(
IL1StandardBridge.finalizeETHWithdrawal.selector,
_from,
_to,
_amount,
_data
);
IL1StandardBridge.finalizeETHWithdrawal.selector,
_from,
_to,
_amount,
_data
);
} else {
message = abi.encodeWithSelector(
IL1ERC20Bridge.finalizeERC20Withdrawal.selector,
l1Token,
_l2Token,
_from,
_to,
_amount,
_data
);
IL1ERC20Bridge.finalizeERC20Withdrawal.selector,
l1Token,
_l2Token,
_from,
_to,
_amount,
_data
);
}
// Send message up to L1 bridge
sendCrossDomainMessage(
l1TokenBridge,
_l1Gas,
message
);
sendCrossDomainMessage(l1TokenBridge, _l1Gas, message);
emit WithdrawalInitiated(l1Token, _l2Token, msg.sender, _to, _amount, _data);
}
......@@ -171,11 +141,7 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
address _to,
uint256 _amount,
bytes calldata _data
)
external
virtual
onlyFromCrossDomainAccount(l1TokenBridge)
{
) external virtual onlyFromCrossDomainAccount(l1TokenBridge) {
// Check the target token is compliant and
// verify the deposited token on L1 matches the L2 deposited token representation here
if (
......@@ -199,18 +165,14 @@ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled {
IL1ERC20Bridge.finalizeERC20Withdrawal.selector,
_l1Token,
_l2Token,
_to, // switched the _to and _from here to bounce back the deposit to the sender
_to, // switched the _to and _from here to bounce back the deposit to the sender
_from,
_amount,
_data
);
// Send message up to L1 bridge
sendCrossDomainMessage(
l1TokenBridge,
0,
message
);
sendCrossDomainMessage(l1TokenBridge, 0, message);
emit DepositFailed(_l1Token, _l2Token, _from, _to, _amount, _data);
}
}
......
......@@ -2,8 +2,8 @@
pragma solidity ^0.8.9;
/* Contract Imports */
import { L2StandardERC20 } from "../../standards/L2StandardERC20.sol";
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {L2StandardERC20} from "../../standards/L2StandardERC20.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
/**
* @title L2StandardTokenFactory
......@@ -11,7 +11,6 @@ import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployA
* compatible with and working on the standard bridge.
*/
contract L2StandardTokenFactory {
event StandardL2TokenCreated(address indexed _l1Token, address indexed _l2Token);
/**
......@@ -24,10 +23,8 @@ contract L2StandardTokenFactory {
address _l1Token,
string memory _name,
string memory _symbol
)
external
{
require (_l1Token != address(0), "Must provide L1 token address");
) external {
require(_l1Token != address(0), "Must provide L1 token address");
L2StandardERC20 l2Token = new L2StandardERC20(
Lib_PredeployAddresses.L2_STANDARD_BRIDGE,
......
......@@ -9,7 +9,6 @@ pragma solidity ^0.8.9;
* ovmCREATE or ovmCREATE2 operation to proceed if the deployer's address whitelisted.
*/
contract OVM_DeployerWhitelist {
/**********
* Events *
**********/
......@@ -18,15 +17,13 @@ contract OVM_DeployerWhitelist {
event WhitelistStatusChanged(address deployer, bool whitelisted);
event WhitelistDisabled(address oldOwner);
/**********************
* Contract Constants *
**********************/
// WARNING: When owner is set to address(0), the whitelist is disabled.
address public owner;
mapping (address => bool) public whitelist;
mapping(address => bool) public whitelist;
/**********************
* Function Modifiers *
......@@ -36,14 +33,10 @@ contract OVM_DeployerWhitelist {
* Blocks functions to anyone except the contract owner.
*/
modifier onlyOwner() {
require(
msg.sender == owner,
"Function can only be called by the owner of this contract."
);
require(msg.sender == owner, "Function can only be called by the owner of this contract.");
_;
}
/********************
* Public Functions *
********************/
......@@ -53,13 +46,7 @@ contract OVM_DeployerWhitelist {
* @param _deployer Address to update permissions for.
* @param _isWhitelisted Whether or not the address is whitelisted.
*/
function setWhitelistedDeployer(
address _deployer,
bool _isWhitelisted
)
external
onlyOwner
{
function setWhitelistedDeployer(address _deployer, bool _isWhitelisted) external onlyOwner {
whitelist[_deployer] = _isWhitelisted;
emit WhitelistStatusChanged(_deployer, _isWhitelisted);
}
......@@ -68,12 +55,7 @@ contract OVM_DeployerWhitelist {
* Updates the owner of this contract.
* @param _owner Address of the new owner.
*/
function setOwner(
address _owner
)
public
onlyOwner
{
function setOwner(address _owner) public onlyOwner {
// Prevent users from setting the whitelist owner to address(0) except via
// enableArbitraryContractDeployment. If you want to burn the whitelist owner, send it to any
// other address that doesn't have a corresponding knowable private key.
......@@ -89,10 +71,7 @@ contract OVM_DeployerWhitelist {
/**
* Permanently enables arbitrary contract deployment and deletes the owner.
*/
function enableArbitraryContractDeployment()
external
onlyOwner
{
function enableArbitraryContractDeployment() external onlyOwner {
emit WhitelistDisabled(owner);
owner = address(0);
}
......@@ -102,15 +81,7 @@ contract OVM_DeployerWhitelist {
* @param _deployer Address to check.
* @return _allowed Whether or not the address can deploy contracts.
*/
function isDeployerAllowed(
address _deployer
)
external
view
returns (
bool
)
{
function isDeployerAllowed(address _deployer) external view returns (bool) {
return (owner == address(0) || whitelist[_deployer]);
}
}
......@@ -2,10 +2,10 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
/* Contract Imports */
import { L2StandardERC20 } from "../../standards/L2StandardERC20.sol";
import {L2StandardERC20} from "../../standards/L2StandardERC20.sol";
/**
* @title OVM_ETH
......@@ -13,21 +13,14 @@ import { L2StandardERC20 } from "../../standards/L2StandardERC20.sol";
* unlike on Layer 1, Layer 2 accounts do not have a balance field.
*/
contract OVM_ETH is L2StandardERC20 {
/***************
* Constructor *
***************/
constructor()
L2StandardERC20(
Lib_PredeployAddresses.L2_STANDARD_BRIDGE,
address(0),
"Ether",
"ETH"
)
L2StandardERC20(Lib_PredeployAddresses.L2_STANDARD_BRIDGE, address(0), "Ether", "ETH")
{}
// ETH ERC20 features are disabled until further notice.
// Discussion here: https://github.com/ethereum-optimism/optimism/discussions/1444
......@@ -39,15 +32,29 @@ contract OVM_ETH is L2StandardERC20 {
revert("OVM_ETH: approve is disabled pending further community discussion.");
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
revert("OVM_ETH: transferFrom is disabled pending further community discussion.");
}
function increaseAllowance(address spender, uint256 addedValue) public virtual override returns (bool) {
function increaseAllowance(address spender, uint256 addedValue)
public
virtual
override
returns (bool)
{
revert("OVM_ETH: increaseAllowance is disabled pending further community discussion.");
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual override returns (bool) {
function decreaseAllowance(address spender, uint256 subtractedValue)
public
virtual
override
returns (bool)
{
revert("OVM_ETH: decreaseAllowance is disabled pending further community discussion.");
}
}
......@@ -2,7 +2,7 @@
pragma solidity ^0.8.9;
/* External Imports */
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title OVM_GasPriceOracle
......@@ -16,12 +16,10 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
* the deployed bytecode instead of running the initcode.
*/
contract OVM_GasPriceOracle is Ownable {
/*************
* Variables *
*************/
// Current L2 gas price
uint256 public gasPrice;
// Current L1 base fee
......@@ -40,11 +38,7 @@ contract OVM_GasPriceOracle is Ownable {
/**
* @param _owner Address that will initially own this contract.
*/
constructor(
address _owner
)
Ownable()
{
constructor(address _owner) Ownable() {
transferOwnership(_owner);
}
......@@ -66,12 +60,7 @@ contract OVM_GasPriceOracle is Ownable {
* Allows the owner to modify the l2 gas price.
* @param _gasPrice New l2 gas price.
*/
function setGasPrice(
uint256 _gasPrice
)
public
onlyOwner
{
function setGasPrice(uint256 _gasPrice) public onlyOwner {
gasPrice = _gasPrice;
emit GasPriceUpdated(_gasPrice);
}
......@@ -80,12 +69,7 @@ contract OVM_GasPriceOracle is Ownable {
* Allows the owner to modify the l1 base fee.
* @param _baseFee New l1 base fee
*/
function setL1BaseFee(
uint256 _baseFee
)
public
onlyOwner
{
function setL1BaseFee(uint256 _baseFee) public onlyOwner {
l1BaseFee = _baseFee;
emit L1BaseFeeUpdated(_baseFee);
}
......@@ -94,12 +78,7 @@ contract OVM_GasPriceOracle is Ownable {
* Allows the owner to modify the overhead.
* @param _overhead New overhead
*/
function setOverhead(
uint256 _overhead
)
public
onlyOwner
{
function setOverhead(uint256 _overhead) public onlyOwner {
overhead = _overhead;
emit OverheadUpdated(_overhead);
}
......@@ -108,12 +87,7 @@ contract OVM_GasPriceOracle is Ownable {
* Allows the owner to modify the scalar.
* @param _scalar New scalar
*/
function setScalar(
uint256 _scalar
)
public
onlyOwner
{
function setScalar(uint256 _scalar) public onlyOwner {
scalar = _scalar;
emit ScalarUpdated(_scalar);
}
......@@ -122,12 +96,7 @@ contract OVM_GasPriceOracle is Ownable {
* Allows the owner to modify the decimals.
* @param _decimals New decimals
*/
function setDecimals(
uint256 _decimals
)
public
onlyOwner
{
function setDecimals(uint256 _decimals) public onlyOwner {
decimals = _decimals;
emit DecimalsUpdated(_decimals);
}
......@@ -139,13 +108,7 @@ contract OVM_GasPriceOracle is Ownable {
* @param _data Unsigned RLP encoded tx, 6 elements
* @return L1 fee that should be paid for the tx
*/
function getL1Fee(bytes memory _data)
public
view
returns (
uint256
)
{
function getL1Fee(bytes memory _data) public view returns (uint256) {
uint256 l1GasUsed = getL1GasUsed(_data);
uint256 l1Fee = l1GasUsed * l1BaseFee;
uint256 divisor = 10**decimals;
......@@ -176,13 +139,7 @@ contract OVM_GasPriceOracle is Ownable {
* @param _data Unsigned RLP encoded tx, 6 elements
* @return Amount of L1 gas used for a transaction
*/
function getL1GasUsed(bytes memory _data)
public
view
returns (
uint256
)
{
function getL1GasUsed(bytes memory _data) public view returns (uint256) {
uint256 total = 0;
for (uint256 i = 0; i < _data.length; i++) {
if (_data[i] == 0) {
......
......@@ -2,7 +2,7 @@
pragma solidity ^0.8.9;
/* Interface Imports */
import { iOVM_L2ToL1MessagePasser } from "./iOVM_L2ToL1MessagePasser.sol";
import {iOVM_L2ToL1MessagePasser} from "./iOVM_L2ToL1MessagePasser.sol";
/**
* @title OVM_L2ToL1MessagePasser
......@@ -12,12 +12,11 @@ import { iOVM_L2ToL1MessagePasser } from "./iOVM_L2ToL1MessagePasser.sol";
* contract's `sentMessages` mapping.
*/
contract OVM_L2ToL1MessagePasser is iOVM_L2ToL1MessagePasser {
/**********************
* Contract Variables *
**********************/
mapping (bytes32 => bool) public sentMessages;
mapping(bytes32 => bool) public sentMessages;
/********************
* Public Functions *
......@@ -27,19 +26,10 @@ contract OVM_L2ToL1MessagePasser is iOVM_L2ToL1MessagePasser {
* Passes a message to L1.
* @param _message Message to pass to L1.
*/
function passMessageToL1(
bytes memory _message
)
public
{
function passMessageToL1(bytes memory _message) public {
// Note: although this function is public, only messages sent from the
// L2CrossDomainMessenger will be relayed by the L1CrossDomainMessenger.
// This is enforced by a check in L1CrossDomainMessenger._verifyStorageProof().
sentMessages[keccak256(
abi.encodePacked(
_message,
msg.sender
)
)] = true;
sentMessages[keccak256(abi.encodePacked(_message, msg.sender))] = true;
}
}
......@@ -2,10 +2,10 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol";
import {Lib_PredeployAddresses} from "../../libraries/constants/Lib_PredeployAddresses.sol";
/* Contract Imports */
import { L2StandardBridge } from "../messaging/L2StandardBridge.sol";
import {L2StandardBridge} from "../messaging/L2StandardBridge.sol";
/**
* @title OVM_SequencerFeeVault
......@@ -13,7 +13,6 @@ import { L2StandardBridge } from "../messaging/L2StandardBridge.sol";
* but "good enough for now".
*/
contract OVM_SequencerFeeVault {
/*************
* Constants *
*************/
......@@ -21,7 +20,6 @@ contract OVM_SequencerFeeVault {
// Minimum ETH balance that can be withdrawn in a single withdrawal.
uint256 public constant MIN_WITHDRAWAL_AMOUNT = 15 ether;
/*************
* Variables *
*************/
......@@ -29,7 +27,6 @@ contract OVM_SequencerFeeVault {
// Address on L1 that will hold the fees once withdrawn. Dynamically initialized within l2geth.
address public l1FeeWallet;
/***************
* Constructor *
***************/
......@@ -39,27 +36,21 @@ contract OVM_SequencerFeeVault {
* Currently HAS NO EFFECT in production because l2geth will mutate this storage slot during
* the genesis block. This is ONLY for testing purposes.
*/
constructor(
address _l1FeeWallet
) {
constructor(address _l1FeeWallet) {
l1FeeWallet = _l1FeeWallet;
}
/************
* Fallback *
************/
receive() external payable {}
/********************
* Public Functions *
********************/
function withdraw()
public
{
function withdraw() public {
require(
address(this).balance >= MIN_WITHDRAWAL_AMOUNT,
"OVM_SequencerFeeVault: withdrawal amount must be greater than minimum withdrawal amount"
......
......@@ -5,7 +5,6 @@ pragma solidity ^0.8.9;
* @title iOVM_L1BlockNumber
*/
interface iOVM_L1BlockNumber {
/********************
* Public Functions *
********************/
......
......@@ -5,17 +5,11 @@ pragma solidity ^0.8.9;
* @title iOVM_L2ToL1MessagePasser
*/
interface iOVM_L2ToL1MessagePasser {
/**********
* Events *
**********/
event L2ToL1Message(
uint256 _nonce,
address _sender,
bytes _data
);
event L2ToL1Message(uint256 _nonce, address _sender, bytes _data);
/********************
* Public Functions *
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import { iL1ChugSplashDeployer } from "./interfaces/iL1ChugSplashDeployer.sol";
import {iL1ChugSplashDeployer} from "./interfaces/iL1ChugSplashDeployer.sol";
/**
* @title L1ChugSplashProxy
......@@ -15,24 +15,22 @@ import { iL1ChugSplashDeployer } from "./interfaces/iL1ChugSplashDeployer.sol";
* modifier. And there almost certainly is not a good reason to not have that modifier. Beware!
*/
contract L1ChugSplashProxy {
/*************
* Constants *
*************/
// "Magic" prefix. When prepended to some arbitrary bytecode and used to create a contract, the
// appended bytecode will be deployed as given.
bytes13 constant internal DEPLOY_CODE_PREFIX = 0x600D380380600D6000396000f3;
bytes13 internal constant DEPLOY_CODE_PREFIX = 0x600D380380600D6000396000f3;
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
bytes32 constant internal IMPLEMENTATION_KEY =
bytes32 internal constant IMPLEMENTATION_KEY =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
// bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)
bytes32 constant internal OWNER_KEY =
bytes32 internal constant OWNER_KEY =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/***************
* Constructor *
***************/
......@@ -40,13 +38,10 @@ contract L1ChugSplashProxy {
/**
* @param _owner Address of the initial contract owner.
*/
constructor(
address _owner
) {
constructor(address _owner) {
_setOwner(_owner);
}
/**********************
* Function Modifiers *
**********************/
......@@ -62,9 +57,7 @@ contract L1ChugSplashProxy {
// L1ChugSplashDeployer contract and Solidity will throw errors if we do a normal call and
// it turns out that it isn't the right type of contract.
(bool success, bytes memory returndata) = owner.staticcall(
abi.encodeWithSelector(
iL1ChugSplashDeployer.isUpgrading.selector
)
abi.encodeWithSelector(iL1ChugSplashDeployer.isUpgrading.selector)
);
// If the call was unsuccessful then we assume that there's no "isUpgrading" method and we
......@@ -75,10 +68,7 @@ contract L1ChugSplashProxy {
// case that the isUpgrading function returned something other than 0 or 1. But we only
// really care about the case where this value is 0 (= false).
uint256 ret = abi.decode(returndata, (uint256));
require(
ret == 0,
"L1ChugSplashProxy: system is currently being upgraded"
);
require(ret == 0, "L1ChugSplashProxy: system is currently being upgraded");
}
_;
......@@ -107,20 +97,15 @@ contract L1ChugSplashProxy {
}
}
/*********************
* Fallback Function *
*********************/
fallback()
external
payable
{
fallback() external payable {
// Proxy call by default.
_doProxyCall();
}
/********************
* Public Functions *
********************/
......@@ -132,12 +117,7 @@ contract L1ChugSplashProxy {
* us a lot more freedom on the client side. Can only be triggered by the contract owner.
* @param _code New contract code to run inside this contract.
*/
function setCode(
bytes memory _code
)
proxyCallIfNotOwner
public
{
function setCode(bytes memory _code) public proxyCallIfNotOwner {
// Get the code hash of the current implementation.
address implementation = _getImplementation();
......@@ -147,10 +127,7 @@ contract L1ChugSplashProxy {
}
// Create the deploycode by appending the magic prefix.
bytes memory deploycode = abi.encodePacked(
DEPLOY_CODE_PREFIX,
_code
);
bytes memory deploycode = abi.encodePacked(DEPLOY_CODE_PREFIX, _code);
// Deploy the code and set the new implementation address.
address newImplementation;
......@@ -176,13 +153,7 @@ contract L1ChugSplashProxy {
* @param _key Storage key to modify.
* @param _value New value for the storage key.
*/
function setStorage(
bytes32 _key,
bytes32 _value
)
proxyCallIfNotOwner
public
{
function setStorage(bytes32 _key, bytes32 _value) public proxyCallIfNotOwner {
assembly {
sstore(_key, _value)
}
......@@ -192,12 +163,7 @@ contract L1ChugSplashProxy {
* Changes the owner of the proxy contract. Only callable by the owner.
* @param _owner New owner of the proxy contract.
*/
function setOwner(
address _owner
)
proxyCallIfNotOwner
public
{
function setOwner(address _owner) public proxyCallIfNotOwner {
_setOwner(_owner);
}
......@@ -206,13 +172,7 @@ contract L1ChugSplashProxy {
* eth_call and setting the "from" address to address(0).
* @return Owner address.
*/
function getOwner()
proxyCallIfNotOwner
public
returns (
address
)
{
function getOwner() public proxyCallIfNotOwner returns (address) {
return _getOwner();
}
......@@ -221,17 +181,10 @@ contract L1ChugSplashProxy {
* eth_call and setting the "from" address to address(0).
* @return Implementation address.
*/
function getImplementation()
proxyCallIfNotOwner
public
returns (
address
)
{
function getImplementation() public proxyCallIfNotOwner returns (address) {
return _getImplementation();
}
/**********************
* Internal Functions *
**********************/
......@@ -240,11 +193,7 @@ contract L1ChugSplashProxy {
* Sets the implementation address.
* @param _implementation New implementation address.
*/
function _setImplementation(
address _implementation
)
internal
{
function _setImplementation(address _implementation) internal {
assembly {
sstore(IMPLEMENTATION_KEY, _implementation)
}
......@@ -254,13 +203,7 @@ contract L1ChugSplashProxy {
* Queries the implementation address.
* @return Implementation address.
*/
function _getImplementation()
internal
view
returns (
address
)
{
function _getImplementation() internal view returns (address) {
address implementation;
assembly {
implementation := sload(IMPLEMENTATION_KEY)
......@@ -272,11 +215,7 @@ contract L1ChugSplashProxy {
* Changes the owner of the proxy contract.
* @param _owner New owner of the proxy contract.
*/
function _setOwner(
address _owner
)
internal
{
function _setOwner(address _owner) internal {
assembly {
sstore(OWNER_KEY, _owner)
}
......@@ -286,13 +225,7 @@ contract L1ChugSplashProxy {
* Queries the owner of the proxy contract.
* @return Owner address.
*/
function _getOwner()
internal
view
returns (
address
)
{
function _getOwner() internal view returns (address) {
address owner;
assembly {
owner := sload(OWNER_KEY)
......@@ -305,15 +238,7 @@ contract L1ChugSplashProxy {
* @param _account Address of the account to get a code hash for.
* @return Code hash for the account.
*/
function _getAccountCodeHash(
address _account
)
internal
view
returns (
bytes32
)
{
function _getAccountCodeHash(address _account) internal view returns (bytes32) {
bytes32 codeHash;
assembly {
codeHash := extcodehash(_account)
......@@ -324,16 +249,10 @@ contract L1ChugSplashProxy {
/**
* Performs the proxy call via a delegatecall.
*/
function _doProxyCall()
onlyWhenNotPaused
internal
{
function _doProxyCall() internal onlyWhenNotPaused {
address implementation = _getImplementation();
require(
implementation != address(0),
"L1ChugSplashProxy: implementation is not set yet"
);
require(implementation != address(0), "L1ChugSplashProxy: implementation is not set yet");
assembly {
// Copy calldata into memory at 0x0....calldatasize.
......
......@@ -5,10 +5,5 @@ pragma solidity ^0.8.9;
* @title iL1ChugSplashDeployer
*/
interface iL1ChugSplashDeployer {
function isUpgrading()
external
view
returns (
bool
);
function isUpgrading() external view returns (bool);
}
......@@ -2,7 +2,7 @@
pragma solidity >0.5.0 <0.9.0;
/* Interface Imports */
import { ICrossDomainMessenger } from "./ICrossDomainMessenger.sol";
import {ICrossDomainMessenger} from "./ICrossDomainMessenger.sol";
/**
* @title CrossDomainEnabled
......@@ -12,7 +12,6 @@ import { ICrossDomainMessenger } from "./ICrossDomainMessenger.sol";
* Runtime target: defined by inheriting contract
*/
contract CrossDomainEnabled {
/*************
* Variables *
*************/
......@@ -20,7 +19,6 @@ contract CrossDomainEnabled {
// Messenger contract used to send and recieve messages from the other domain.
address public messenger;
/***************
* Constructor *
***************/
......@@ -28,13 +26,10 @@ contract CrossDomainEnabled {
/**
* @param _messenger Address of the CrossDomainMessenger on the current layer.
*/
constructor(
address _messenger
) {
constructor(address _messenger) {
messenger = _messenger;
}
/**********************
* Function Modifiers *
**********************/
......@@ -44,9 +39,7 @@ contract CrossDomainEnabled {
* @param _sourceDomainAccount The only account on the originating domain which is
* authenticated to call this function.
*/
modifier onlyFromCrossDomainAccount(
address _sourceDomainAccount
) {
modifier onlyFromCrossDomainAccount(address _sourceDomainAccount) {
require(
msg.sender == address(getCrossDomainMessenger()),
"OVM_XCHAIN: messenger contract unauthenticated"
......@@ -60,7 +53,6 @@ contract CrossDomainEnabled {
_;
}
/**********************
* Internal Functions *
**********************/
......@@ -70,13 +62,7 @@ contract CrossDomainEnabled {
* needs to override.
* @return The address of the cross-domain messenger contract which should be used.
*/
function getCrossDomainMessenger()
internal
virtual
returns (
ICrossDomainMessenger
)
{
function getCrossDomainMessenger() internal virtual returns (ICrossDomainMessenger) {
return ICrossDomainMessenger(messenger);
}
......@@ -91,9 +77,7 @@ contract CrossDomainEnabled {
address _crossDomainTarget,
uint32 _gasLimit,
bytes memory _message
)
internal
{
) internal {
getCrossDomainMessenger().sendMessage(_crossDomainTarget, _message, _gasLimit);
}
}
......@@ -5,7 +5,6 @@ pragma solidity >0.5.0 <0.9.0;
* @title ICrossDomainMessenger
*/
interface ICrossDomainMessenger {
/**********
* Events *
**********/
......@@ -15,18 +14,17 @@ interface ICrossDomainMessenger {
address sender,
bytes message,
uint256 messageNonce,
uint256 gasLimit);
uint256 gasLimit
);
event RelayedMessage(bytes32 indexed msgHash);
event FailedRelayedMessage(bytes32 indexed msgHash);
/*************
* Variables *
*************/
function xDomainMessageSender() external view returns (address);
/********************
* Public Functions *
********************/
......
......@@ -2,7 +2,7 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
import {Lib_RLPReader} from "../rlp/Lib_RLPReader.sol";
/**
* @title Lib_CrossDomainUtils
......@@ -21,19 +21,14 @@ library Lib_CrossDomainUtils {
address _sender,
bytes memory _message,
uint256 _messageNonce
)
internal
pure
returns (
bytes memory
)
{
return abi.encodeWithSignature(
"relayMessage(address,address,bytes,uint256)",
_target,
_sender,
_message,
_messageNonce
);
) internal pure returns (bytes memory) {
return
abi.encodeWithSignature(
"relayMessage(address,address,bytes,uint256)",
_target,
_sender,
_message,
_messageNonce
);
}
}
......@@ -2,16 +2,15 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_RLPReader } from "../rlp/Lib_RLPReader.sol";
import { Lib_RLPWriter } from "../rlp/Lib_RLPWriter.sol";
import { Lib_BytesUtils } from "../utils/Lib_BytesUtils.sol";
import { Lib_Bytes32Utils } from "../utils/Lib_Bytes32Utils.sol";
import {Lib_RLPReader} from "../rlp/Lib_RLPReader.sol";
import {Lib_RLPWriter} from "../rlp/Lib_RLPWriter.sol";
import {Lib_BytesUtils} from "../utils/Lib_BytesUtils.sol";
import {Lib_Bytes32Utils} from "../utils/Lib_Bytes32Utils.sol";
/**
* @title Lib_OVMCodec
*/
library Lib_OVMCodec {
/*********
* Enums *
*********/
......@@ -21,7 +20,6 @@ library Lib_OVMCodec {
L1TOL2_QUEUE
}
/***********
* Structs *
***********/
......@@ -58,10 +56,10 @@ library Lib_OVMCodec {
struct TransactionChainElement {
bool isSequenced;
uint256 queueIndex; // QUEUED TX ONLY
uint256 timestamp; // SEQUENCER TX ONLY
uint256 queueIndex; // QUEUED TX ONLY
uint256 timestamp; // SEQUENCER TX ONLY
uint256 blockNumber; // SEQUENCER TX ONLY
bytes txData; // SEQUENCER TX ONLY
bytes txData; // SEQUENCER TX ONLY
}
struct QueueElement {
......@@ -70,7 +68,6 @@ library Lib_OVMCodec {
uint40 blockNumber;
}
/**********************
* Internal Functions *
**********************/
......@@ -80,24 +77,21 @@ library Lib_OVMCodec {
* @param _transaction OVM transaction to encode.
* @return Encoded transaction bytes.
*/
function encodeTransaction(
Transaction memory _transaction
)
function encodeTransaction(Transaction memory _transaction)
internal
pure
returns (
bytes memory
)
returns (bytes memory)
{
return abi.encodePacked(
_transaction.timestamp,
_transaction.blockNumber,
_transaction.l1QueueOrigin,
_transaction.l1TxOrigin,
_transaction.entrypoint,
_transaction.gasLimit,
_transaction.data
);
return
abi.encodePacked(
_transaction.timestamp,
_transaction.blockNumber,
_transaction.l1QueueOrigin,
_transaction.l1TxOrigin,
_transaction.entrypoint,
_transaction.gasLimit,
_transaction.data
);
}
/**
......@@ -105,15 +99,7 @@ library Lib_OVMCodec {
* @param _transaction OVM transaction to encode.
* @return Hashed transaction
*/
function hashTransaction(
Transaction memory _transaction
)
internal
pure
returns (
bytes32
)
{
function hashTransaction(Transaction memory _transaction) internal pure returns (bytes32) {
return keccak256(encodeTransaction(_transaction));
}
......@@ -122,23 +108,16 @@ library Lib_OVMCodec {
* @param _encoded RLP-encoded account state.
* @return Account state struct.
*/
function decodeEVMAccount(
bytes memory _encoded
)
internal
pure
returns (
EVMAccount memory
)
{
function decodeEVMAccount(bytes memory _encoded) internal pure returns (EVMAccount memory) {
Lib_RLPReader.RLPItem[] memory accountState = Lib_RLPReader.readList(_encoded);
return EVMAccount({
nonce: Lib_RLPReader.readUint256(accountState[0]),
balance: Lib_RLPReader.readUint256(accountState[1]),
storageRoot: Lib_RLPReader.readBytes32(accountState[2]),
codeHash: Lib_RLPReader.readBytes32(accountState[3])
});
return
EVMAccount({
nonce: Lib_RLPReader.readUint256(accountState[0]),
balance: Lib_RLPReader.readUint256(accountState[1]),
storageRoot: Lib_RLPReader.readBytes32(accountState[2]),
codeHash: Lib_RLPReader.readBytes32(accountState[3])
});
}
/**
......@@ -146,22 +125,19 @@ library Lib_OVMCodec {
* @param _batchHeader Header to hash.
* @return Hash of the header.
*/
function hashBatchHeader(
Lib_OVMCodec.ChainBatchHeader memory _batchHeader
)
function hashBatchHeader(Lib_OVMCodec.ChainBatchHeader memory _batchHeader)
internal
pure
returns (
bytes32
)
returns (bytes32)
{
return keccak256(
abi.encode(
_batchHeader.batchRoot,
_batchHeader.batchSize,
_batchHeader.prevTotalElements,
_batchHeader.extraData
)
);
return
keccak256(
abi.encode(
_batchHeader.batchRoot,
_batchHeader.batchSize,
_batchHeader.prevTotalElements,
_batchHeader.extraData
)
);
}
}
......@@ -5,10 +5,8 @@ pragma solidity ^0.8.9;
* @title Lib_DefaultValues
*/
library Lib_DefaultValues {
// The default x-domain message sender being set to a non-zero value makes
// deployment a bit more expensive, but in exchange the refund on every call to
// `relayMessage` by the L1 and L2 messengers will be higher.
address internal constant DEFAULT_XDOMAIN_SENDER = 0x000000000000000000000000000000000000dEaD;
}
......@@ -10,11 +10,13 @@ library Lib_PredeployAddresses {
address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002;
address payable internal constant OVM_ETH = payable(0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000);
// solhint-disable-next-line max-line-length
address internal constant L2_CROSS_DOMAIN_MESSENGER = 0x4200000000000000000000000000000000000007;
address internal constant L2_CROSS_DOMAIN_MESSENGER =
0x4200000000000000000000000000000000000007;
address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008;
address internal constant PROXY_EOA = 0x4200000000000000000000000000000000000009;
address internal constant L2_STANDARD_BRIDGE = 0x4200000000000000000000000000000000000010;
address internal constant SEQUENCER_FEE_WALLET = 0x4200000000000000000000000000000000000011;
address internal constant L2_STANDARD_TOKEN_FACTORY = 0x4200000000000000000000000000000000000012;
address internal constant L2_STANDARD_TOKEN_FACTORY =
0x4200000000000000000000000000000000000012;
address internal constant L1_BLOCK_NUMBER = 0x4200000000000000000000000000000000000013;
}
......@@ -2,30 +2,23 @@
pragma solidity ^0.8.9;
/* External Imports */
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title Lib_AddressManager
*/
contract Lib_AddressManager is Ownable {
/**********
* Events *
**********/
event AddressSet(
string indexed _name,
address _newAddress,
address _oldAddress
);
event AddressSet(string indexed _name, address _newAddress, address _oldAddress);
/*************
* Variables *
*************/
mapping (bytes32 => address) private addresses;
mapping(bytes32 => address) private addresses;
/********************
* Public Functions *
......@@ -36,22 +29,12 @@ contract Lib_AddressManager is Ownable {
* @param _name String name to associate an address with.
* @param _address Address to associate with the name.
*/
function setAddress(
string memory _name,
address _address
)
external
onlyOwner
{
function setAddress(string memory _name, address _address) external onlyOwner {
bytes32 nameHash = _getNameHash(_name);
address oldAddress = addresses[nameHash];
addresses[nameHash] = _address;
emit AddressSet(
_name,
_address,
oldAddress
);
emit AddressSet(_name, _address, oldAddress);
}
/**
......@@ -59,19 +42,10 @@ contract Lib_AddressManager is Ownable {
* @param _name Name to retrieve an address for.
* @return Address associated with the given name.
*/
function getAddress(
string memory _name
)
external
view
returns (
address
)
{
function getAddress(string memory _name) external view returns (address) {
return addresses[_getNameHash(_name)];
}
/**********************
* Internal Functions *
**********************/
......@@ -81,15 +55,7 @@ contract Lib_AddressManager is Ownable {
* @param _name Name to compute a hash for.
* @return Hash of the given name.
*/
function _getNameHash(
string memory _name
)
internal
pure
returns (
bytes32
)
{
function _getNameHash(string memory _name) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(_name));
}
}
......@@ -2,20 +2,18 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_AddressManager } from "./Lib_AddressManager.sol";
import {Lib_AddressManager} from "./Lib_AddressManager.sol";
/**
* @title Lib_AddressResolver
*/
abstract contract Lib_AddressResolver {
/*************
* Variables *
*************/
Lib_AddressManager public libAddressManager;
/***************
* Constructor *
***************/
......@@ -23,13 +21,10 @@ abstract contract Lib_AddressResolver {
/**
* @param _libAddressManager Address of the Lib_AddressManager.
*/
constructor(
address _libAddressManager
) {
constructor(address _libAddressManager) {
libAddressManager = Lib_AddressManager(_libAddressManager);
}
/********************
* Public Functions *
********************/
......@@ -39,15 +34,7 @@ abstract contract Lib_AddressResolver {
* @param _name Name to resolve an address for.
* @return Address associated with the given name.
*/
function resolve(
string memory _name
)
public
view
returns (
address
)
{
function resolve(string memory _name) public view returns (address) {
return libAddressManager.getAddress(_name);
}
}
......@@ -2,13 +2,12 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_AddressManager } from "./Lib_AddressManager.sol";
import {Lib_AddressManager} from "./Lib_AddressManager.sol";
/**
* @title Lib_ResolvedDelegateProxy
*/
contract Lib_ResolvedDelegateProxy {
/*************
* Variables *
*************/
......@@ -21,9 +20,8 @@ contract Lib_ResolvedDelegateProxy {
// There is a known flaw in this contract, and we will remove it from the repository
// in the near future. Due to the very limited way that we are using it, this flaw is
// not an issue in our system.
mapping (address => string) private implementationName;
mapping (address => Lib_AddressManager) private addressManager;
mapping(address => string) private implementationName;
mapping(address => Lib_AddressManager) private addressManager;
/***************
* Constructor *
......@@ -33,31 +31,21 @@ contract Lib_ResolvedDelegateProxy {
* @param _libAddressManager Address of the Lib_AddressManager.
* @param _implementationName implementationName of the contract to proxy to.
*/
constructor(
address _libAddressManager,
string memory _implementationName
) {
constructor(address _libAddressManager, string memory _implementationName) {
addressManager[address(this)] = Lib_AddressManager(_libAddressManager);
implementationName[address(this)] = _implementationName;
}
/*********************
* Fallback Function *
*********************/
fallback()
external
payable
{
fallback() external payable {
address target = addressManager[address(this)].getAddress(
(implementationName[address(this)])
);
require(
target != address(0),
"Target address must be initialized."
);
require(target != address(0), "Target address must be initialized.");
(bool success, bytes memory returndata) = target.delegatecall(msg.data);
......
......@@ -6,7 +6,6 @@ pragma solidity ^0.8.9;
* @author Bakaoh (with modifications)
*/
library Lib_RLPWriter {
/**********************
* Internal Functions *
**********************/
......@@ -16,15 +15,7 @@ library Lib_RLPWriter {
* @param _in The byte string to encode.
* @return The RLP encoded string in bytes.
*/
function writeBytes(
bytes memory _in
)
internal
pure
returns (
bytes memory
)
{
function writeBytes(bytes memory _in) internal pure returns (bytes memory) {
bytes memory encoded;
if (_in.length == 1 && uint8(_in[0]) < 128) {
......@@ -41,15 +32,7 @@ library Lib_RLPWriter {
* @param _in The list of RLP encoded byte strings.
* @return The RLP encoded list of items in bytes.
*/
function writeList(
bytes[] memory _in
)
internal
pure
returns (
bytes memory
)
{
function writeList(bytes[] memory _in) internal pure returns (bytes memory) {
bytes memory list = _flatten(_in);
return abi.encodePacked(_writeLength(list.length, 192), list);
}
......@@ -59,15 +42,7 @@ library Lib_RLPWriter {
* @param _in The string to encode.
* @return The RLP encoded string in bytes.
*/
function writeString(
string memory _in
)
internal
pure
returns (
bytes memory
)
{
function writeString(string memory _in) internal pure returns (bytes memory) {
return writeBytes(bytes(_in));
}
......@@ -76,15 +51,7 @@ library Lib_RLPWriter {
* @param _in The address to encode.
* @return The RLP encoded address in bytes.
*/
function writeAddress(
address _in
)
internal
pure
returns (
bytes memory
)
{
function writeAddress(address _in) internal pure returns (bytes memory) {
return writeBytes(abi.encodePacked(_in));
}
......@@ -93,15 +60,7 @@ library Lib_RLPWriter {
* @param _in The uint256 to encode.
* @return The RLP encoded uint256 in bytes.
*/
function writeUint(
uint256 _in
)
internal
pure
returns (
bytes memory
)
{
function writeUint(uint256 _in) internal pure returns (bytes memory) {
return writeBytes(_toBinary(_in));
}
......@@ -110,21 +69,12 @@ library Lib_RLPWriter {
* @param _in The bool to encode.
* @return The RLP encoded bool in bytes.
*/
function writeBool(
bool _in
)
internal
pure
returns (
bytes memory
)
{
function writeBool(bool _in) internal pure returns (bytes memory) {
bytes memory encoded = new bytes(1);
encoded[0] = (_in ? bytes1(0x01) : bytes1(0x80));
return encoded;
}
/*********************
* Private Functions *
*********************/
......@@ -135,16 +85,7 @@ library Lib_RLPWriter {
* @param _offset 128 if item is string, 192 if item is list.
* @return RLP encoded bytes.
*/
function _writeLength(
uint256 _len,
uint256 _offset
)
private
pure
returns (
bytes memory
)
{
function _writeLength(uint256 _len, uint256 _offset) private pure returns (bytes memory) {
bytes memory encoded;
if (_len < 56) {
......@@ -160,8 +101,8 @@ library Lib_RLPWriter {
encoded = new bytes(lenLen + 1);
encoded[0] = bytes1(uint8(lenLen) + uint8(_offset) + 55);
for(i = 1; i <= lenLen; i++) {
encoded[i] = bytes1(uint8((_len / (256**(lenLen-i))) % 256));
for (i = 1; i <= lenLen; i++) {
encoded[i] = bytes1(uint8((_len / (256**(lenLen - i))) % 256));
}
}
......@@ -174,15 +115,7 @@ library Lib_RLPWriter {
* @param _x The integer to encode.
* @return RLP encoded bytes.
*/
function _toBinary(
uint256 _x
)
private
pure
returns (
bytes memory
)
{
function _toBinary(uint256 _x) private pure returns (bytes memory) {
bytes memory b = abi.encodePacked(_x);
uint256 i = 0;
......@@ -211,15 +144,12 @@ library Lib_RLPWriter {
uint256 _dest,
uint256 _src,
uint256 _len
)
private
pure
{
) private pure {
uint256 dest = _dest;
uint256 src = _src;
uint256 len = _len;
for(; len >= 32; len -= 32) {
for (; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
......@@ -229,7 +159,7 @@ library Lib_RLPWriter {
uint256 mask;
unchecked {
mask = 256 ** (32 - len) - 1;
mask = 256**(32 - len) - 1;
}
assembly {
let srcpart := and(mload(src), not(mask))
......@@ -244,15 +174,7 @@ library Lib_RLPWriter {
* @param _list List of byte strings to flatten.
* @return The flattened byte string.
*/
function _flatten(
bytes[] memory _list
)
private
pure
returns (
bytes memory
)
{
function _flatten(bytes[] memory _list) private pure returns (bytes memory) {
if (_list.length == 0) {
return new bytes(0);
}
......@@ -265,13 +187,17 @@ library Lib_RLPWriter {
bytes memory flattened = new bytes(len);
uint256 flattenedPtr;
assembly { flattenedPtr := add(flattened, 0x20) }
assembly {
flattenedPtr := add(flattened, 0x20)
}
for(i = 0; i < _list.length; i++) {
for (i = 0; i < _list.length; i++) {
bytes memory item = _list[i];
uint256 listPtr;
assembly { listPtr := add(item, 0x20)}
assembly {
listPtr := add(item, 0x20)
}
_memcpy(flattenedPtr, listPtr, item.length);
flattenedPtr += _list[i].length;
......
......@@ -2,13 +2,12 @@
pragma solidity ^0.8.9;
/* Library Imports */
import { Lib_MerkleTrie } from "./Lib_MerkleTrie.sol";
import {Lib_MerkleTrie} from "./Lib_MerkleTrie.sol";
/**
* @title Lib_SecureMerkleTrie
*/
library Lib_SecureMerkleTrie {
/**********************
* Internal Functions *
**********************/
......@@ -30,13 +29,7 @@ library Lib_SecureMerkleTrie {
bytes memory _value,
bytes memory _proof,
bytes32 _root
)
internal
pure
returns (
bool _verified
)
{
) internal pure returns (bool _verified) {
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.verifyInclusionProof(key, _value, _proof, _root);
}
......@@ -57,13 +50,7 @@ library Lib_SecureMerkleTrie {
bytes memory _value,
bytes memory _proof,
bytes32 _root
)
internal
pure
returns (
bytes32 _updatedRoot
)
{
) internal pure returns (bytes32 _updatedRoot) {
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.update(key, _value, _proof, _root);
}
......@@ -80,14 +67,7 @@ library Lib_SecureMerkleTrie {
bytes memory _key,
bytes memory _proof,
bytes32 _root
)
internal
pure
returns (
bool _exists,
bytes memory _value
)
{
) internal pure returns (bool _exists, bytes memory _value) {
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.get(key, _proof, _root);
}
......@@ -98,21 +78,15 @@ library Lib_SecureMerkleTrie {
* @param _value Value for the single node.
* @return _updatedRoot Hash of the trie.
*/
function getSingleNodeRootHash(
bytes memory _key,
bytes memory _value
)
function getSingleNodeRootHash(bytes memory _key, bytes memory _value)
internal
pure
returns (
bytes32 _updatedRoot
)
returns (bytes32 _updatedRoot)
{
bytes memory key = _getSecureKey(_key);
return Lib_MerkleTrie.getSingleNodeRootHash(key, _value);
}
/*********************
* Private Functions *
*********************/
......@@ -122,15 +96,7 @@ library Lib_SecureMerkleTrie {
* @param _key Key to get a secure key from.
* @return _secureKey Secure version of the key.
*/
function _getSecureKey(
bytes memory _key
)
private
pure
returns (
bytes memory _secureKey
)
{
function _getSecureKey(bytes memory _key) private pure returns (bytes memory _secureKey) {
return abi.encodePacked(keccak256(_key));
}
}
......@@ -8,34 +8,30 @@ pragma solidity ^0.8.9;
* overwritable "extra data" field so we can store more information with a single SSTORE.
*/
library Lib_Buffer {
/*************
* Libraries *
*************/
using Lib_Buffer for Buffer;
/***********
* Structs *
***********/
struct Buffer {
bytes32 context;
mapping (uint256 => bytes32) buf;
mapping(uint256 => bytes32) buf;
}
struct BufferContext {
// Stores the length of the array. Uint40 is way more elements than we'll ever reasonably
// need in an array and we get an extra 27 bytes of extra data to play with.
uint40 length;
// Arbitrary extra data that can be modified whenever the length is updated. Useful for
// squeezing out some gas optimizations.
bytes27 extraData;
}
/**********************
* Internal Functions *
**********************/
......@@ -50,9 +46,7 @@ library Lib_Buffer {
Buffer storage _self,
bytes32 _value,
bytes27 _extraData
)
internal
{
) internal {
BufferContext memory ctx = _self.getContext();
_self.buf[ctx.length] = _value;
......@@ -68,18 +62,10 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @param _value Value to push to the buffer.
*/
function push(
Buffer storage _self,
bytes32 _value
)
internal
{
function push(Buffer storage _self, bytes32 _value) internal {
BufferContext memory ctx = _self.getContext();
_self.push(
_value,
ctx.extraData
);
_self.push(_value, ctx.extraData);
}
/**
......@@ -88,22 +74,10 @@ library Lib_Buffer {
* @param _index Element index to retrieve.
* @return Value of the element at the given index.
*/
function get(
Buffer storage _self,
uint256 _index
)
internal
view
returns (
bytes32
)
{
function get(Buffer storage _self, uint256 _index) internal view returns (bytes32) {
BufferContext memory ctx = _self.getContext();
require(
_index < ctx.length,
"Index out of bounds."
);
require(_index < ctx.length, "Index out of bounds.");
return _self.buf[_index];
}
......@@ -118,15 +92,10 @@ library Lib_Buffer {
Buffer storage _self,
uint40 _index,
bytes27 _extraData
)
internal
{
) internal {
BufferContext memory ctx = _self.getContext();
require(
_index < ctx.length,
"Index out of bounds."
);
require(_index < ctx.length, "Index out of bounds.");
// Set our length and extra data, save the context.
ctx.length = _index;
......@@ -139,17 +108,9 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @param _index Index of the element to delete from (inclusive).
*/
function deleteElementsAfterInclusive(
Buffer storage _self,
uint40 _index
)
internal
{
function deleteElementsAfterInclusive(Buffer storage _self, uint40 _index) internal {
BufferContext memory ctx = _self.getContext();
_self.deleteElementsAfterInclusive(
_index,
ctx.extraData
);
_self.deleteElementsAfterInclusive(_index, ctx.extraData);
}
/**
......@@ -157,15 +118,7 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @return Current global index.
*/
function getLength(
Buffer storage _self
)
internal
view
returns (
uint40
)
{
function getLength(Buffer storage _self) internal view returns (uint40) {
BufferContext memory ctx = _self.getContext();
return ctx.length;
}
......@@ -175,12 +128,7 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @param _extraData New global extra data.
*/
function setExtraData(
Buffer storage _self,
bytes27 _extraData
)
internal
{
function setExtraData(Buffer storage _self, bytes27 _extraData) internal {
BufferContext memory ctx = _self.getContext();
ctx.extraData = _extraData;
_self.setContext(ctx);
......@@ -191,15 +139,7 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @return Current global extra data.
*/
function getExtraData(
Buffer storage _self
)
internal
view
returns (
bytes27
)
{
function getExtraData(Buffer storage _self) internal view returns (bytes27) {
BufferContext memory ctx = _self.getContext();
return ctx.extraData;
}
......@@ -209,12 +149,7 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @param _ctx Current buffer context.
*/
function setContext(
Buffer storage _self,
BufferContext memory _ctx
)
internal
{
function setContext(Buffer storage _self, BufferContext memory _ctx) internal {
bytes32 context;
uint40 length = _ctx.length;
bytes27 extraData = _ctx.extraData;
......@@ -233,26 +168,21 @@ library Lib_Buffer {
* @param _self Buffer to access.
* @return Current buffer context.
*/
function getContext(
Buffer storage _self
)
internal
view
returns (
BufferContext memory
)
{
function getContext(Buffer storage _self) internal view returns (BufferContext memory) {
bytes32 context = _self.context;
uint40 length;
bytes27 extraData;
assembly {
length := and(context, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
extraData := and(context, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000)
length := and(
context,
0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF
)
extraData := and(
context,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000
)
}
return BufferContext({
length: length,
extraData: extraData
});
return BufferContext({length: length, extraData: extraData});
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IL2StandardERC20 is IERC20, IERC165 {
function l1Token() external returns (address);
......
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