-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
135 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
l1-contracts/contracts/bridge/interfaces/IL1SharedBridgeLegacy.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
/// @title L1 Bridge contract interface | ||
/// @author Matter Labs | ||
/// @custom:security-contact security@matterlabs.dev | ||
interface IL1SharedBridgeLegacy { | ||
function l2BridgeAddress(uint256 _chainId) external view returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
import {BaseZkSyncUpgrade, ProposedUpgrade} from "./BaseZkSyncUpgrade.sol"; | ||
|
||
import {DataEncoding} from "../common/libraries/DataEncoding.sol"; | ||
|
||
import {Diamond} from "../state-transition/libraries/Diamond.sol"; | ||
import {PriorityQueue} from "../state-transition/libraries/PriorityQueue.sol"; | ||
import {PriorityTree} from "../state-transition/libraries/PriorityTree.sol"; | ||
|
||
import {IGatewayUpgrade} from "./IGatewayUpgrade.sol"; | ||
import {IL1SharedBridgeLegacy} from "../bridge/interfaces/IL1SharedBridgeLegacy.sol"; | ||
|
||
import {IBridgehub} from "../bridgehub/IBridgehub.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact security@matterlabs.dev | ||
/// @notice This upgrade will be used to migrate Era to be part of the hyperchain ecosystem contracts. | ||
contract GatewayUpgrade is BaseZkSyncUpgrade, Initializable { | ||
using PriorityQueue for PriorityQueue.Queue; | ||
using PriorityTree for PriorityTree.Tree; | ||
|
||
address public immutable THIS_ADDRESS; | ||
|
||
constructor() { | ||
THIS_ADDRESS = address(this); | ||
} | ||
|
||
/// @notice The main function that will be called by the upgrade proxy. | ||
/// @param _proposedUpgrade The upgrade to be executed. | ||
function upgrade(ProposedUpgrade calldata _proposedUpgrade) public override returns (bytes32) { | ||
(bytes memory l2TxDataStart, bytes memory l2TxDataFinish) = abi.decode( | ||
_proposedUpgrade.postUpgradeCalldata, | ||
(bytes, bytes) | ||
); | ||
|
||
s.baseTokenAssetId = DataEncoding.encodeNTVAssetId(block.chainid, s.baseToken); | ||
s.priorityTree.setup(s.priorityQueue.getTotalPriorityTxs()); | ||
IBridgehub(s.bridgehub).setLegacyBaseTokenAssetId(s.chainId); | ||
ProposedUpgrade memory proposedUpgrade = _proposedUpgrade; | ||
address l2LegacyBridge = IL1SharedBridgeLegacy(s.baseTokenBridge).l2BridgeAddress(s.chainId); | ||
proposedUpgrade.l2ProtocolUpgradeTx.data = bytes.concat( | ||
l2TxDataStart, | ||
bytes32(uint256(uint160(l2LegacyBridge))), | ||
l2TxDataFinish | ||
); | ||
// slither-disable-next-line controlled-delegatecall | ||
(bool success, ) = THIS_ADDRESS.delegatecall( | ||
abi.encodeWithSelector(IGatewayUpgrade.upgradeExternal.selector, proposedUpgrade) | ||
); | ||
// solhint-disable-next-line gas-custom-errors | ||
require(success, "GatewayUpgrade: upgrade failed"); | ||
return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE; | ||
} | ||
|
||
/// @notice The function that will be called from this same contract, we need an external call to be able to modify _proposedUpgrade (memory/calldata). | ||
function upgradeExternal(ProposedUpgrade calldata _proposedUpgrade) external { | ||
// solhint-disable-next-line gas-custom-errors | ||
require(msg.sender == address(this), "GatewayUpgrade: upgradeExternal"); | ||
super.upgrade(_proposedUpgrade); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {ProposedUpgrade} from "./BaseZkSyncUpgrade.sol"; | ||
|
||
interface IGatewayUpgrade { | ||
function upgradeExternal(ProposedUpgrade calldata _upgrade) external returns (bytes32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters