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