Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import { ISemver } from "interfaces/universal/ISemver.sol";

interface ILiquidityController is ISemver {
error Unauthorized();
error LiquidityController_Unauthorized();

event Initialized(uint8 version);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ pragma solidity ^0.8.0;
import { ISemver } from "interfaces/universal/ISemver.sol";

interface INativeAssetLiquidity is ISemver {
error Unauthorized();
error InvalidAmount();
error NativeAssetLiquidity_Unauthorized();
error NativeAssetLiquidity_InsufficientBalance();

event LiquidityDeposited(address indexed caller, uint256 value);
event LiquidityWithdrawn(address indexed caller, uint256 value);
event LiquidityFunded(address indexed funder, uint256 value);

function deposit() external payable;
function withdraw(uint256 _amount) external;
function fund() external payable;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Test validation exclusions configuration
# Test validation exclusions configuration
# This file contains lists of paths and test names that should be excluded
# from various validation checks in the test validation script.

Expand Down Expand Up @@ -56,7 +56,6 @@ contract_name_validation = [
"test/L2/GasPriceOracle.t.sol", # Contains contracts not matching GasPriceOracle base name
"test/universal/StandardBridge.t.sol", # Contains contracts not matching StandardBridge base name
"test/L1/OPContractsManagerContractsContainer.t.sol", # Contains contracts not matching OPContractsManagerContractsContainer base name
"test/L1/OptimismPortal2.t.sol", # Contains contracts not matching OptimismPortal2 base name
]

# PATHS EXCLUDED FROM FUNCTION NAME VALIDATION:
Expand Down Expand Up @@ -92,4 +91,5 @@ contracts = [
"OptimismPortal2_MigrateLiquidity_Test", # Interop tests hosted in the OptimismPortal2 test file
"OptimismPortal2_MigrateToSuperRoots_Test", # Interop tests hosted in the OptimismPortal2 test file
"OptimismPortal2_UpgradeInterop_Test", # Interop tests hosted in the OptimismPortal2 test file
"L1Block_SetCustomGasToken_Test", # Custom gas token tests hosted in the L1Block test file
]
10 changes: 10 additions & 0 deletions packages/contracts-bedrock/scripts/deploy/DeployConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ contract DeployConfig is Script {
useCustomGasToken = _useCustomGasToken;
}

/// @notice Allow the `gasPayingTokenName` config to be overridden in testing environments
function setGasPayingTokenName(string memory _gasPayingTokenName) public {
gasPayingTokenName = _gasPayingTokenName;
}

/// @notice Allow the `gasPayingTokenSymbol` config to be overridden in testing environments
function setGasPayingTokenSymbol(string memory _gasPayingTokenSymbol) public {
gasPayingTokenSymbol = _gasPayingTokenSymbol;
}

/// @notice Allow the `nativeAssetLiquidityAmount` config to be overridden in testing environments
function setNativeAssetLiquidityAmount(uint256 _nativeAssetLiquidityAmount) public {
nativeAssetLiquidityAmount = _nativeAssetLiquidityAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
},
{
"inputs": [],
"name": "Unauthorized",
"name": "LiquidityController_Unauthorized",
"type": "error"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "fund",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "version",
Expand Down Expand Up @@ -58,25 +51,6 @@
"name": "LiquidityDeposited",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "funder",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "LiquidityFunded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand All @@ -98,12 +72,12 @@
},
{
"inputs": [],
"name": "InvalidAmount",
"name": "NativeAssetLiquidity_InsufficientBalance",
"type": "error"
},
{
"inputs": [],
"name": "Unauthorized",
"name": "NativeAssetLiquidity_Unauthorized",
"type": "error"
}
]
12 changes: 6 additions & 6 deletions packages/contracts-bedrock/snapshots/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@
"sourceCodeHash": "0xdc7bd63134eeab163a635950f2afd16b59f40f9cf1306f2ed33ad661cc7b4962"
},
"src/L2/L2ToL1MessagePasserCGT.sol:L2ToL1MessagePasserCGT": {
"initCodeHash": "0xe09e6219f705bc120b604f25997610f3107daef880f33e380da7ed618b45bb6e",
"sourceCodeHash": "0x1ba0f62d5101f3541fe074a39fd67ab6a06b5b72678a4f08d08366fbe4bef764"
"initCodeHash": "0xf36eab44c41249b4d8ea95a21b70f1eae55b1a555384870c2f4ca306fa9121b6",
"sourceCodeHash": "0xec1736e67134e22ad9ceb0b8b6c116fd169637aa6729c05d9f0f4b02547aaac0"
},
"src/L2/L2ToL2CrossDomainMessenger.sol:L2ToL2CrossDomainMessenger": {
"initCodeHash": "0x975fd33a3a386310d54dbb01b56f3a6a8350f55a3b6bd7781e5ccc2166ddf2e6",
"sourceCodeHash": "0xbea4229c5c6988243dbc7cf5a086ddd412fe1f2903b8e20d56699fec8de0c2c9"
},
"src/L2/LiquidityController.sol:LiquidityController": {
"initCodeHash": "0x8a21d16da3377aa61375755d37010c0c37c99817fdce9d16f78f0ab9bc3a84c5",
"sourceCodeHash": "0xb4fca8d4532e88e0dd53d3643aa4022953e37c745753009b3c8f9bcca5806f57"
"initCodeHash": "0x19ce7a691d1f8631bfce9fea002c385c418fc69c2e9a9aa5d44ee0cf348c1026",
"sourceCodeHash": "0x87351013f5bcca917dfdd916b06b8ece6bd447acae146f004a33d88f59ce2487"
},
"src/L2/NativeAssetLiquidity.sol:NativeAssetLiquidity": {
"initCodeHash": "0x2c50c7cac8eab6867ffb969a65a8aa3026d415f2e9464726683ff6cd5da0b8f3",
"sourceCodeHash": "0x9432883dd4aa4d5ffc733ad99fa7bcc9cc8c319e654b385b8cd093a37a4c94cb"
"initCodeHash": "0x04b176e5d484e54173a5644c833117c5fd9f055dce8678be9ec4cf07c0f01f00",
"sourceCodeHash": "0x79289174e875ead5a6290df9af1951d6c0ff0dc6809601e1c7a80110ceb8e945"
},
"src/L2/OperatorFeeVault.sol:OperatorFeeVault": {
"initCodeHash": "0x3d8c0d7736e8767f2f797da1c20c5fe30bd7f48a4cf75f376290481ad7c0f91f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ contract L2ToL1MessagePasserCGT is L2ToL1MessagePasser {
/// @notice The error thrown when a withdrawal is initiated with value and custom gas token is used.
error L2ToL1MessagePasserCGT_NotAllowedOnCGTMode();

/// @custom:semver +custom-gas-token.1
/// @custom:semver +custom-gas-token
function version() public pure override returns (string memory) {
return string.concat(super.version(), "+custom-gas-token.1");
return string.concat(super.version(), "+custom-gas-token");
}

/// @notice Sends a message from L2 to L1.
Expand Down
12 changes: 7 additions & 5 deletions packages/contracts-bedrock/src/L2/LiquidityController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable
import { SafeSend } from "src/universal/SafeSend.sol";

// Libraries
import { Unauthorized } from "src/libraries/errors/CommonErrors.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";

// Interfaces
Expand Down Expand Up @@ -39,6 +38,9 @@ contract LiquidityController is ISemver, Initializable {
/// @param amount The amount of liquidity that was burned
event LiquidityBurned(address indexed minter, uint256 amount);

/// @notice Error for when an address is unauthorized to perform liquidity control operations
error LiquidityController_Unauthorized();

/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";
Expand Down Expand Up @@ -67,15 +69,15 @@ contract LiquidityController is ISemver, Initializable {
/// @notice Authorizes an address to perform liquidity control operations
/// @param _minter The address to authorize as a minter
function authorizeMinter(address _minter) external {
if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert Unauthorized();
if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert LiquidityController_Unauthorized();
minters[_minter] = true;
emit MinterAuthorized(_minter);
}

/// @notice Deauthorizes an address from performing liquidity control operations
/// @param _minter The address to deauthorize as a minter
function deauthorizeMinter(address _minter) external {
if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert Unauthorized();
if (msg.sender != IProxyAdmin(Predeploys.PROXY_ADMIN).owner()) revert LiquidityController_Unauthorized();
delete minters[_minter];
emit MinterDeauthorized(_minter);
}
Expand All @@ -84,7 +86,7 @@ contract LiquidityController is ISemver, Initializable {
/// @param _to The address to receive the minted native asset
/// @param _amount The amount of native asset to mint and send
function mint(address _to, uint256 _amount) external {
if (!minters[msg.sender]) revert Unauthorized();
if (!minters[msg.sender]) revert LiquidityController_Unauthorized();
INativeAssetLiquidity(Predeploys.NATIVE_ASSET_LIQUIDITY).withdraw(_amount);

// This is a forced ETH send to the recipient, the recipient should NOT expect to be called
Expand All @@ -95,7 +97,7 @@ contract LiquidityController is ISemver, Initializable {

/// @notice Burns native asset liquidity by sending ETH to the contract
function burn() external payable {
if (!minters[msg.sender]) revert Unauthorized();
if (!minters[msg.sender]) revert LiquidityController_Unauthorized();
INativeAssetLiquidity(Predeploys.NATIVE_ASSET_LIQUIDITY).deposit{ value: msg.value }();

emit LiquidityBurned(msg.sender, msg.value);
Expand Down
24 changes: 9 additions & 15 deletions packages/contracts-bedrock/src/L2/NativeAssetLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
// Interfaces
import { ISemver } from "interfaces/universal/ISemver.sol";

// Errors
import { Unauthorized, InvalidAmount } from "src/libraries/errors/CommonErrors.sol";

/// @custom:predeploy 0x4200000000000000000000000000000000000029
/// @title NativeAssetLiquidity
/// @notice The NativeAssetLiquidity contract allows other contracts to access native asset liquidity
Expand All @@ -23,35 +20,32 @@ contract NativeAssetLiquidity is ISemver {
/// @notice Emitted when an address deposits native asset liquidity.
event LiquidityDeposited(address indexed caller, uint256 value);

/// @notice Emitted when funds are received.
event LiquidityFunded(address indexed funder, uint256 value);
/// @notice Error for when the contract has insufficient balance.
error NativeAssetLiquidity_InsufficientBalance();

/// @notice Error for when an address is unauthorized to perform native asset liquidity operations
error NativeAssetLiquidity_Unauthorized();

/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";

/// @notice Allows an address to lock native asset liquidity into this contract.
function deposit() external payable {
if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert Unauthorized();
if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert NativeAssetLiquidity_Unauthorized();

emit LiquidityDeposited(msg.sender, msg.value);
}

/// @notice Allows an address to unlock native asset liquidity from this contract.
/// @param _amount The amount of liquidity to unlock.
function withdraw(uint256 _amount) external {
if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert Unauthorized();
if (msg.sender != Predeploys.LIQUIDITY_CONTROLLER) revert NativeAssetLiquidity_Unauthorized();

if (_amount > address(this).balance) revert NativeAssetLiquidity_InsufficientBalance();

new SafeSend{ value: _amount }(payable(msg.sender));

emit LiquidityWithdrawn(msg.sender, _amount);
}

/// @notice Fund the contract by sending native asset.
/// @dev The function is payable to accept native asset.
function fund() external payable {
if (msg.value == 0) revert InvalidAmount();

emit LiquidityFunded(msg.sender, msg.value);
}
}
25 changes: 10 additions & 15 deletions packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ contract OptimismPortal2_TestInit is DisputeGameFactory_TestInit {
Types.OutputRootProof internal _outputRootProof;
GameType internal respectedGameType;

/// @dev Setup the system for a ready-to-use state.
function setUp() public virtual override {
// Use a constructor to set the storage vars above, so as to minimize the number of ffi calls.
constructor() {
super.setUp();

_defaultTx = Types.WithdrawalTransaction({
Expand All @@ -77,7 +77,10 @@ contract OptimismPortal2_TestInit is DisputeGameFactory_TestInit {
messagePasserStorageRoot: _storageRoot,
latestBlockhash: bytes32(uint256(0))
});
}

/// @dev Setup the system for a ready-to-use state.
function setUp() public virtual override {
if (isForkTest()) {
// Set the proposed block number to be the next block number on the forked network
(, _proposedBlockNumber) = anchorStateRegistry.getAnchorRoot();
Expand Down Expand Up @@ -716,18 +719,15 @@ contract OptimismPortal2_Receive_Test is OptimismPortal2_TestInit {
}

/// @notice Tests that `receive` reverts when custom gas token is enabled
function testFuzz_receive_customGasToken_reverts(uint256 _value) external virtual {
function testFuzz_receive_customGasToken_reverts(uint256 _value) external {
skipIfDevFeatureDisabled(DevFeatures.CUSTOM_GAS_TOKEN);
_value = bound(_value, 1, type(uint128).max);
vm.deal(alice, _value);

address portal = address(optimismPortal2);

vm.prank(alice);
vm.expectRevert(IOptimismPortal.OptimismPortal_NotAllowedOnCGTMode.selector);
assembly {
pop(call(gas(), portal, _value, 0, 0, 0, 0))
}
(bool revertsAsExpected,) = address(optimismPortal2).call{ value: _value }(hex"");
assertTrue(revertsAsExpected, "expectRevert: call did not revert");
}
}

Expand Down Expand Up @@ -830,7 +830,7 @@ contract OptimismPortal2_MigrateLiquidity_Test is CommonTest {
/// @title OptimismPortal2_MigrateToSuperRoots_Test
/// @notice Test contract for OptimismPortal2 `migrateToSuperRoots` function.
contract OptimismPortal2_MigrateToSuperRoots_Test is OptimismPortal2_TestInit {
function setUp() public virtual override {
function setUp() public override {
super.setUp();
skipIfDevFeatureDisabled(DevFeatures.OPTIMISM_PORTAL_INTEROP);
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ contract OptimismPortal2_ProveWithdrawalTransaction_Test is OptimismPortal2_Test
contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_TestInit {
/// @notice Tests that `finalizeWithdrawalTransaction` reverts when the target is the portal
/// contract or the lockbox.
function test_finalizeWithdrawalTransaction_badTarget_reverts() external virtual {
function test_finalizeWithdrawalTransaction_badTarget_reverts() external {
_defaultTx.target = address(optimismPortal2);
vm.expectRevert(IOptimismPortal.OptimismPortal_BadTarget.selector);
optimismPortal2.finalizeWithdrawalTransaction(_defaultTx);
Expand Down Expand Up @@ -1932,7 +1932,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T
bytes memory _data
)
external
virtual
{
skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below");
if (isUsingCustomGasToken()) {
Expand Down Expand Up @@ -2017,7 +2016,6 @@ contract OptimismPortal2_FinalizeWithdrawalTransaction_Test is OptimismPortal2_T
GameType _newGameType
)
external
virtual
{
skipIfForkTest("Skipping on forked tests because of the L2ToL1MessageParser call below");
if (isUsingCustomGasToken()) {
Expand Down Expand Up @@ -2565,7 +2563,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit {
bytes memory _data
)
external
virtual
{
// Prevent overflow on an upgrade context
if (isUsingLockbox()) {
Expand Down Expand Up @@ -2636,7 +2633,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit {
address _7702Target
)
external
virtual
{
assumeNotForgeAddress(_7702Target);

Expand Down Expand Up @@ -2703,7 +2699,6 @@ contract OptimismPortal2_DepositTransaction_Test is OptimismPortal2_TestInit {
bytes memory _data
)
external
virtual
{
// Prevent overflow on an upgrade context
_mint = bound(_mint, 0, type(uint256).max - address(ethLockbox).balance);
Expand Down
7 changes: 2 additions & 5 deletions packages/contracts-bedrock/test/L2/BaseFeeVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ pragma solidity 0.8.15;
// Testing utilities
import { CommonTest } from "test/setup/CommonTest.sol";

// Libraries
import { Types } from "src/libraries/Types.sol";

/// @title BaseFeeVault_Constructor_Test
/// @notice Tests the `constructor` of the `BaseFeeVault` contract.
contract BaseFeeVault_Constructor_Test is CommonTest {
Expand All @@ -16,7 +13,7 @@ contract BaseFeeVault_Constructor_Test is CommonTest {
assertEq(baseFeeVault.recipient(), deploy.cfg().baseFeeVaultRecipient());
assertEq(baseFeeVault.MIN_WITHDRAWAL_AMOUNT(), deploy.cfg().baseFeeVaultMinimumWithdrawalAmount());
assertEq(baseFeeVault.minWithdrawalAmount(), deploy.cfg().baseFeeVaultMinimumWithdrawalAmount());
assertEq(uint8(baseFeeVault.WITHDRAWAL_NETWORK()), uint8(Types.WithdrawalNetwork.L1));
assertEq(uint8(baseFeeVault.withdrawalNetwork()), uint8(Types.WithdrawalNetwork.L1));
assertEq(uint8(baseFeeVault.WITHDRAWAL_NETWORK()), deploy.cfg().baseFeeVaultWithdrawalNetwork());
assertEq(uint8(baseFeeVault.withdrawalNetwork()), deploy.cfg().baseFeeVaultWithdrawalNetwork());
}
}
Loading