Skip to content

Commit

Permalink
Merge branch 'develop' into fix/indexer-op-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Jun 27, 2022
2 parents 5d6c6bc + ef29d8a commit 39fece1
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 114 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-grapes-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-bedrock': patch
---

Make the Portal upgradeable
190 changes: 188 additions & 2 deletions op-bindings/bindings/optimismportal.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/optimismportal_deployed.go

Large diffs are not rendered by default.

95 changes: 50 additions & 45 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ L1CrossDomainMessenger_Test:testCannot_L1MessengerPause() (gas: 10844)
L1CrossDomainMessenger_Test:testCannot_L1MessengerUnpause() (gas: 10858)
L1CrossDomainMessenger_Test:test_L1MessengerMessageVersion() (gas: 8388)
L1CrossDomainMessenger_Test:test_L1MessengerPause() (gas: 31860)
L1CrossDomainMessenger_Test:test_L1MessengerRelayMessageSucceeds() (gas: 61283)
L1CrossDomainMessenger_Test:test_L1MessengerRelayMessageToSystemContract() (gas: 44903)
L1CrossDomainMessenger_Test:test_L1MessengerRelayMessageSucceeds() (gas: 61217)
L1CrossDomainMessenger_Test:test_L1MessengerRelayMessageToSystemContract() (gas: 44837)
L1CrossDomainMessenger_Test:test_L1MessengerRelayShouldRevertIfPaused() (gas: 41587)
L1CrossDomainMessenger_Test:test_L1MessengerSendMessage() (gas: 172193)
L1CrossDomainMessenger_Test:test_L1MessengerTwiceSendMessage() (gas: 1254199)
L1CrossDomainMessenger_Test:test_L1MessengerSendMessage() (gas: 172199)
L1CrossDomainMessenger_Test:test_L1MessengerTwiceSendMessage() (gas: 1254211)
L1CrossDomainMessenger_Test:test_L1MessengerUnpause() (gas: 23804)
L1CrossDomainMessenger_Test:test_L1MessengerXDomainSenderReverts() (gas: 10599)
L1CrossDomainMessenger_Test:test_L1MessengerxDomainMessageSenderResets() (gas: 58601)
L1StandardBridge_Test:test_depositERC20() (gas: 452856)
L1StandardBridge_Test:test_depositERC20To() (gas: 454632)
L1StandardBridge_Test:test_depositETH() (gas: 247077)
L1StandardBridge_Test:test_depositETHTo() (gas: 204961)
L1StandardBridge_Test:test_finalizeERC20Withdrawal() (gas: 438745)
L1CrossDomainMessenger_Test:test_L1MessengerxDomainMessageSenderResets() (gas: 59022)
L1StandardBridge_Test:test_depositERC20() (gas: 452889)
L1StandardBridge_Test:test_depositERC20To() (gas: 454644)
L1StandardBridge_Test:test_depositETH() (gas: 247083)
L1StandardBridge_Test:test_depositETHTo() (gas: 204967)
L1StandardBridge_Test:test_finalizeERC20Withdrawal() (gas: 438779)
L1StandardBridge_Test:test_finalizeETHWithdrawal() (gas: 48005)
L1StandardBridge_Test:test_initialize() (gas: 14885)
L1StandardBridge_Test:test_onlyEOADepositERC20() (gas: 12085)
L1StandardBridge_Test:test_onlyEOADepositETH() (gas: 30637)
L1StandardBridge_Test:test_onlyL2BridgeFinalizeERC20Withdrawal() (gas: 23565)
L1StandardBridge_Test:test_onlyPortalFinalizeERC20Withdrawal() (gas: 22919)
L1StandardBridge_Test:test_receive() (gas: 391817)
L1StandardBridge_Test:test_receive() (gas: 391823)
L2CrossDomainMessenger_Test:testCannot_L2MessengerPause() (gas: 10843)
L2CrossDomainMessenger_Test:test_L2MessengerMessageVersion() (gas: 8410)
L2CrossDomainMessenger_Test:test_L2MessengerPause() (gas: 31837)
Expand All @@ -57,27 +57,28 @@ L2CrossDomainMessenger_Test:test_L2MessengerSendMessage() (gas: 119682)
L2CrossDomainMessenger_Test:test_L2MessengerTwiceSendMessage() (gas: 133142)
L2CrossDomainMessenger_Test:test_L2MessengerXDomainSenderReverts() (gas: 10599)
L2CrossDomainMessenger_Test:test_L2MessengerxDomainMessageSenderResets() (gas: 54881)
L2OutputOracleTest:testCannot_appendEmptyOutput() (gas: 18216)
L2OutputOracleTest:testCannot_appendFutureTimetamp() (gas: 20183)
L2OutputOracleTest:testCannot_appendOnWrongFork() (gas: 20462)
L2OutputOracleTest:testCannot_appendOutputIfNotSequencer() (gas: 17607)
L2OutputOracleTest:testCannot_appendUnexpectedBlockNumber() (gas: 20086)
L2OutputOracleTest:testCannot_deleteL2Output_ifNotOwner() (gas: 18893)
L2OutputOracleTest:testCannot_deleteL2Output_withWrongRoot() (gas: 83353)
L2OutputOracleTest:testCannot_deleteL2Output_withWrongTime() (gas: 79346)
L2OutputOracleTest:test_appendWithBlockhashAndHeight() (gas: 69126)
L2OutputOracleTest:test_appendingAnotherOutput() (gas: 70475)
L2OutputOracleTest:test_changeSequencer() (gas: 35473)
L2OutputOracleTest:test_computeL2Timestamp() (gas: 19323)
L2OutputOracleTest:test_constructor() (gas: 40152)
L2OutputOracleTest:test_deleteL2Output() (gas: 69237)
L2OutputOracleTest:test_getL2Output() (gas: 76099)
L2OutputOracleTest:test_latestBlockNumber() (gas: 69878)
L2OutputOracleTest:test_nextBlockNumber() (gas: 9281)
L2OutputOracleTest:test_updateOwner() (gas: 24185)
L2OutputOracleUpgradeable_Test:test_cannotInitImpl() (gas: 8431)
L2OutputOracleTest:testCannot_appendEmptyOutput() (gas: 24163)
L2OutputOracleTest:testCannot_appendFutureTimetamp() (gas: 26130)
L2OutputOracleTest:testCannot_appendOnWrongFork() (gas: 26415)
L2OutputOracleTest:testCannot_appendOutputIfNotSequencer() (gas: 23554)
L2OutputOracleTest:testCannot_appendUnexpectedBlockNumber() (gas: 26039)
L2OutputOracleTest:testCannot_deleteL2Output_ifNotOwner() (gas: 24799)
L2OutputOracleTest:testCannot_deleteL2Output_withWrongRoot() (gas: 91157)
L2OutputOracleTest:testCannot_deleteL2Output_withWrongTime() (gas: 87150)
L2OutputOracleTest:test_appendWithBlockhashAndHeight() (gas: 75061)
L2OutputOracleTest:test_appendingAnotherOutput() (gas: 76861)
L2OutputOracleTest:test_changeSequencer() (gas: 55776)
L2OutputOracleTest:test_computeL2Timestamp() (gas: 30288)
L2OutputOracleTest:test_constructor() (gas: 48845)
L2OutputOracleTest:test_deleteL2Output() (gas: 76604)
L2OutputOracleTest:test_getL2Output() (gas: 83012)
L2OutputOracleTest:test_latestBlockNumber() (gas: 76264)
L2OutputOracleTest:test_nextBlockNumber() (gas: 15166)
L2OutputOracleTest:test_updateOwner() (gas: 34646)
L2OutputOracleUpgradeable_Test:test_cannotInitImpl() (gas: 8453)
L2OutputOracleUpgradeable_Test:test_cannotInitProxy() (gas: 13430)
L2OutputOracleUpgradeable_Test:test_initValuesOnProxy() (gas: 38906)
L2OutputOracleUpgradeable_Test:test_upgrading() (gas: 230843)
L2StandardBridge_Test:test_ERC20BridgeFailed_whenLocalTokenIsBridge() (gas: 133097)
L2StandardBridge_Test:test_cannotWithdrawEthWithoutSendingIt() (gas: 21611)
L2StandardBridge_Test:test_finalizeDeposit() (gas: 93100)
Expand Down Expand Up @@ -113,21 +114,25 @@ OptimismMintableTokenFactory_Test:test_createStandardL2Token() (gas: 1100125)
OptimismMintableTokenFactory_Test:test_createStandardL2TokenSameTwice() (gas: 2181161)
OptimismMintableTokenFactory_Test:test_createStandardL2TokenShouldRevertIfRemoteIsZero() (gas: 9374)
OptimismMintableTokenFactory_Test:test_initializeShouldRevert() (gas: 12696)
OptimismPortal_Test:test_OptimismPortalConstructor() (gas: 11435)
OptimismPortal_Test:test_OptimismPortalContractCreationReverts() (gas: 9192)
OptimismPortal_Test:test_OptimismPortalReceiveEth() (gas: 121771)
OptimismPortal_Test:test_cannotVerifyRecentWithdrawal() (gas: 21886)
OptimismPortal_Test:test_depositTransaction_NoValueContract() (gas: 70746)
OptimismPortal_Test:test_depositTransaction_NoValueEOA() (gas: 71092)
OptimismPortal_Test:test_depositTransaction_createWithZeroValueForContract() (gas: 70751)
OptimismPortal_Test:test_depositTransaction_createWithZeroValueForEOA() (gas: 71095)
OptimismPortal_Test:test_depositTransaction_withEthValueAndContractContractCreation() (gas: 77795)
OptimismPortal_Test:test_depositTransaction_withEthValueAndEOAContractCreation() (gas: 69925)
OptimismPortal_Test:test_depositTransaction_withEthValueFromContract() (gas: 77456)
OptimismPortal_Test:test_depositTransaction_withEthValueFromEOA() (gas: 78072)
OptimismPortal_Test:test_invalidWithdrawalProof() (gas: 33769)
OptimismPortal_Test:test_isOutputFinalized() (gas: 109379)
OptimismPortal_Test:test_simple_isOutputFinalized() (gas: 17076)
OptimismPortalUpgradeable_Test:test_cannotInitImpl() (gas: 10958)
OptimismPortalUpgradeable_Test:test_cannotInitProxy() (gas: 15956)
OptimismPortalUpgradeable_Test:test_initValuesOnProxy() (gas: 15967)
OptimismPortalUpgradeable_Test:test_upgrading() (gas: 230843)
OptimismPortal_Test:test_OptimismPortalConstructor() (gas: 17286)
OptimismPortal_Test:test_OptimismPortalContractCreationReverts() (gas: 14214)
OptimismPortal_Test:test_OptimismPortalReceiveEth() (gas: 126643)
OptimismPortal_Test:test_cannotVerifyRecentWithdrawal() (gas: 31945)
OptimismPortal_Test:test_depositTransaction_NoValueContract() (gas: 75774)
OptimismPortal_Test:test_depositTransaction_NoValueEOA() (gas: 76120)
OptimismPortal_Test:test_depositTransaction_createWithZeroValueForContract() (gas: 75779)
OptimismPortal_Test:test_depositTransaction_createWithZeroValueForEOA() (gas: 76123)
OptimismPortal_Test:test_depositTransaction_withEthValueAndContractContractCreation() (gas: 82823)
OptimismPortal_Test:test_depositTransaction_withEthValueAndEOAContractCreation() (gas: 74941)
OptimismPortal_Test:test_depositTransaction_withEthValueFromContract() (gas: 82484)
OptimismPortal_Test:test_depositTransaction_withEthValueFromEOA() (gas: 83100)
OptimismPortal_Test:test_invalidWithdrawalProof() (gas: 45251)
OptimismPortal_Test:test_isOutputFinalized() (gas: 132162)
OptimismPortal_Test:test_simple_isOutputFinalized() (gas: 23965)
Proxy_Test:test_clashingFunctionSignatures() (gas: 101427)
Proxy_Test:test_implementationKey() (gas: 20942)
Proxy_Test:test_implementationProxyCallIfNotAdmin() (gas: 30021)
Expand Down
14 changes: 11 additions & 3 deletions packages/contracts-bedrock/.storage-layout
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,19 @@
+----------------------+----------------------------------------+------+--------+-------+
| Name | Type | Slot | Offset | Bytes |
+=======================================================================================+
| params | struct ResourceMetering.ResourceParams | 0 | 0 | 32 |
| _initialized | uint8 | 0 | 0 | 1 |
|----------------------+----------------------------------------+------+--------+-------|
| l2Sender | address | 1 | 0 | 20 |
| _initializing | bool | 0 | 1 | 1 |
|----------------------+----------------------------------------+------+--------+-------|
| finalizedWithdrawals | mapping(bytes32 => bool) | 2 | 0 | 32 |
| params | struct ResourceMetering.ResourceParams | 1 | 0 | 32 |
|----------------------+----------------------------------------+------+--------+-------|
| __gap | uint256[49] | 2 | 0 | 1568 |
|----------------------+----------------------------------------+------+--------+-------|
| l2Sender | address | 51 | 0 | 20 |
|----------------------+----------------------------------------+------+--------+-------|
| finalizedWithdrawals | mapping(bytes32 => bool) | 52 | 0 | 32 |
|----------------------+----------------------------------------+------+--------+-------|
| __gap | uint256[48] | 53 | 0 | 1536 |
+----------------------+----------------------------------------+------+--------+-------+

=======================
Expand Down
31 changes: 27 additions & 4 deletions packages/contracts-bedrock/contracts/L1/OptimismPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WithdrawalVerifier } from "../libraries/Lib_WithdrawalVerifier.sol";
import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { ExcessivelySafeCall } from "../libraries/ExcessivelySafeCall.sol";
import { ResourceMetering } from "./ResourceMetering.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

/**
* @custom:proxied
Expand All @@ -14,7 +15,12 @@ import { ResourceMetering } from "./ResourceMetering.sol";
* and L2. Messages sent directly to the OptimismPortal have no form of replayability.
* Users are encouraged to use the L1CrossDomainMessenger for a higher-level interface.
*/
contract OptimismPortal is ResourceMetering {
contract OptimismPortal is Initializable, ResourceMetering {
/**
* @notice Contract version number.
*/
uint8 public constant OPTIMISM_PORTAL_VERSION = 1;

/**
* @notice Emitted when a transaction is deposited from L1 to L2. The parameters of this event
* are read by the rollup node and used to derive deposit transactions on L2.
Expand Down Expand Up @@ -65,7 +71,7 @@ contract OptimismPortal is ResourceMetering {
* of this variable is the default L2 sender address, then we are NOT inside of a call
* to finalizeWithdrawalTransaction.
*/
address public l2Sender = DEFAULT_L2_SENDER;
address public l2Sender;

/**
* @notice The L2 gas limit set when eth is deposited using the receive() function.
Expand All @@ -83,12 +89,29 @@ contract OptimismPortal is ResourceMetering {
mapping(bytes32 => bool) public finalizedWithdrawals;

/**
* @param _l2Oracle Address of the L2OutputOracle.
* @param _finalizationPeriodSeconds Finalization time in seconds.
* @notice Reserve extra slots (to to a total of 50) in the storage layout for future upgrades.
*/
uint256[48] private __gap;

/**
* @notice The constructor sets immutable values in the implementation.
* This means that these values can only changed by an upgrade. But the efficiency gains
* are worthwhile.
* Also ensures that the implementation is initialized upon deployment.
*/
constructor(L2OutputOracle _l2Oracle, uint256 _finalizationPeriodSeconds) {
// Set these immutable values into the bytcode of the implementation.
L2_ORACLE = _l2Oracle;
FINALIZATION_PERIOD_SECONDS = _finalizationPeriodSeconds;
initialize();
}

/**
* @notice Initializes the contract and parent contract(s).
*/
function initialize() public reinitializer(OPTIMISM_PORTAL_VERSION) {
l2Sender = DEFAULT_L2_SENDER;
__ResourceMetering_init();
}

/**
Expand Down
16 changes: 15 additions & 1 deletion packages/contracts-bedrock/contracts/L1/ResourceMetering.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,23 @@ contract ResourceMetering {
ResourceParams public params;

/**
* @notice Sets initial resource parameter values.
* @notice Reserve extra slots (to a total of 50) in the storage layout for future upgrades.
*/
uint256[49] private __gap;

/**
* @notice Set the initial values. In order to enable this contract to be used in an upgradable
* context, the constructor calls a separate init function.
*/
constructor() {
__ResourceMetering_init();
}

/**
* @notice Sets initial resource parameter values. This function must either be called by the
* initializer function of an upgradeable child contract.
*/
function __ResourceMetering_init() internal {
params = ResourceParams({
prevBaseFee: INITIAL_BASE_FEE,
prevBoughtGas: 0,
Expand Down
56 changes: 54 additions & 2 deletions packages/contracts-bedrock/contracts/test/CommonTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { AddressAliasHelper } from "../libraries/AddressAliasHelper.sol";
import { OVM_ETH } from "../L2/OVM_ETH.sol";
import { Lib_PredeployAddresses } from "../libraries/Lib_PredeployAddresses.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Proxy } from "../universal/Proxy.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

contract CommonTest is Test {
address alice = address(128);
Expand Down Expand Up @@ -46,6 +48,7 @@ contract CommonTest is Test {
contract L2OutputOracle_Initializer is CommonTest {
// Test target
L2OutputOracle oracle;
L2OutputOracle oracleImpl;

// Constructor arguments
address sequencer = 0x000000000000000000000000000000000000AbBa;
Expand All @@ -69,7 +72,7 @@ contract L2OutputOracle_Initializer is CommonTest {
vm.warp(initL1Time);
vm.roll(startingBlockNumber);
// Deploy the L2OutputOracle and transfer owernship to the sequencer
oracle = new L2OutputOracle(
oracleImpl = new L2OutputOracle(
submissionInterval,
genesisL2Output,
historicalTotalBlocks,
Expand All @@ -79,6 +82,39 @@ contract L2OutputOracle_Initializer is CommonTest {
sequencer,
owner
);
Proxy proxy = new Proxy(alice);
vm.prank(alice);
proxy.upgradeToAndCall(
address(oracleImpl),
abi.encodeWithSelector(
L2OutputOracle.initialize.selector,
genesisL2Output,
startingBlockNumber,
sequencer,
owner
)
);
oracle = L2OutputOracle(address(proxy));
}
}

contract Portal_Initializer is L2OutputOracle_Initializer {
// Test target
OptimismPortal opImpl;
OptimismPortal op;

function setUp() public override virtual {
L2OutputOracle_Initializer.setUp();
opImpl = new OptimismPortal(oracle, 7 days);
Proxy proxy = new Proxy(alice);
vm.prank(alice);
proxy.upgradeToAndCall(
address(opImpl),
abi.encodeWithSelector(
OptimismPortal.initialize.selector
)
);
op = OptimismPortal(payable(address(proxy)));
}
}

Expand Down Expand Up @@ -125,7 +161,7 @@ contract Messenger_Initializer is L2OutputOracle_Initializer {
super.setUp();

// Deploy the OptimismPortal
op = new OptimismPortal(oracle, 100);
op = new OptimismPortal(oracle, 7 days);
vm.label(address(op), "OptimismPortal");

L1Messenger = new L1CrossDomainMessenger();
Expand Down Expand Up @@ -320,3 +356,19 @@ contract Bridge_Initializer is Messenger_Initializer {
);
}
}

// Used for testing a future upgrade beyond the current implementations.
// We include some variables so that we can sanity check accessing storage values after an upgrade.
contract NextImpl is Initializable {
// Initializable occupies the zero-th slot.
bytes32 slot1;
bytes32[19] __gap;
bytes32 slot21;
bytes32 public constant slot21Init = bytes32(hex"1337");

function initialize() public reinitializer(2) {
// Slot21 is unused by an of our upgradeable contracts.
// This is used to verify that we can access this value after an upgrade.
slot21 = slot21Init;
}
}
Loading

0 comments on commit 39fece1

Please sign in to comment.