-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First iteration on testing the gateway upgrade (#826)
- Loading branch information
1 parent
c99b936
commit c3030f5
Showing
64 changed files
with
2,461 additions
and
297 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,20 @@ import {BridgedStandardERC20} from "./BridgedStandardERC20.sol"; | |
import {DEPLOYER_SYSTEM_CONTRACT, L2_ASSET_ROUTER_ADDR, L2_NATIVE_TOKEN_VAULT_ADDR} from "../common/L2ContractAddresses.sol"; | ||
import {SystemContractsCaller} from "../common/libraries/SystemContractsCaller.sol"; | ||
import {L2ContractHelper, IContractDeployer} from "../common/libraries/L2ContractHelper.sol"; | ||
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol"; | ||
|
||
import {IL2AssetRouter} from "./asset-router/IL2AssetRouter.sol"; | ||
import {IL2NativeTokenVault} from "./ntv/IL2NativeTokenVault.sol"; | ||
|
||
import {IL2SharedBridgeLegacy} from "./interfaces/IL2SharedBridgeLegacy.sol"; | ||
import {ZeroAddress, EmptyBytes32, Unauthorized, AmountMustBeGreaterThanZero, DeployFailed} from "../common/L1ContractErrors.sol"; | ||
import {InvalidCaller, ZeroAddress, EmptyBytes32, Unauthorized, AmountMustBeGreaterThanZero, DeployFailed} from "../common/L1ContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @notice The "default" bridge implementation for the ERC20 tokens. Note, that it does not | ||
/// support any custom token logic, i.e. rebase tokens' functionality is not supported. | ||
/// @dev Note, that this contract should be compatible with its previous version as it will be | ||
/// the primary bridge to be used during migration. | ||
contract L2SharedBridgeLegacy is IL2SharedBridgeLegacy, Initializable { | ||
/// @dev The address of the L1 shared bridge counterpart. | ||
address public override l1SharedBridge; | ||
|
@@ -37,6 +40,7 @@ contract L2SharedBridgeLegacy is IL2SharedBridgeLegacy, Initializable { | |
|
||
/// @dev The address of the legacy L1 erc20 bridge counterpart. | ||
/// This is non-zero only on Era, and should not be renamed for backward compatibility with the SDKs. | ||
// slither-disable-next-line uninitialized-state | ||
address public override l1Bridge; | ||
|
||
modifier onlyNTV() { | ||
|
@@ -103,6 +107,44 @@ contract L2SharedBridgeLegacy is IL2SharedBridgeLegacy, Initializable { | |
IL2AssetRouter(L2_ASSET_ROUTER_ADDR).withdrawLegacyBridge(_l1Receiver, _l2Token, _amount, msg.sender); | ||
} | ||
|
||
/// @notice Finalize the deposit and mint funds | ||
/// @param _l1Sender The account address that initiated the deposit on L1 | ||
/// @param _l2Receiver The account address that would receive minted ether | ||
/// @param _l1Token The address of the token that was locked on the L1 | ||
/// @param _amount Total amount of tokens deposited from L1 | ||
/// @param _data The additional data that user can pass with the deposit | ||
function finalizeDeposit( | ||
address _l1Sender, | ||
address _l2Receiver, | ||
address _l1Token, | ||
uint256 _amount, | ||
bytes calldata _data | ||
) external { | ||
// Only the L1 bridge counterpart can initiate and finalize the deposit. | ||
if ( | ||
AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1Bridge && | ||
AddressAliasHelper.undoL1ToL2Alias(msg.sender) != l1SharedBridge | ||
) { | ||
revert InvalidCaller(msg.sender); | ||
} | ||
|
||
IL2AssetRouter(L2_ASSET_ROUTER_ADDR).finalizeDepositLegacyBridge({ | ||
_l1Sender: _l1Sender, | ||
_l2Receiver: _l2Receiver, | ||
_l1Token: _l1Token, | ||
_amount: _amount, | ||
_data: _data | ||
}); | ||
|
||
address l2Token = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).l2TokenAddress(_l1Token); | ||
|
||
if (l1TokenAddress[l2Token] == address(0)) { | ||
l1TokenAddress[l2Token] = _l1Token; | ||
} | ||
|
||
emit FinalizeDeposit(_l1Sender, _l2Receiver, l2Token, _amount); | ||
} | ||
|
||
/// @return Address of an L2 token counterpart | ||
function l2TokenAddress(address _l1Token) public view override returns (address) { | ||
address token = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).l2TokenAddress(_l1Token); | ||
|
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 |
---|---|---|
|
@@ -6,11 +6,12 @@ import {IL1Nullifier} from "../interfaces/IL1Nullifier.sol"; | |
import {INativeTokenVault} from "../ntv/INativeTokenVault.sol"; | ||
import {IAssetRouterBase} from "./IAssetRouterBase.sol"; | ||
import {L2TransactionRequestTwoBridgesInner} from "../../bridgehub/IBridgehub.sol"; | ||
import {IL1SharedBridgeLegacy} from "../interfaces/IL1SharedBridgeLegacy.sol"; | ||
|
||
/// @title L1 Bridge contract interface | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
interface IL1AssetRouter is IAssetRouterBase { | ||
interface IL1AssetRouter is IAssetRouterBase, IL1SharedBridgeLegacy { | ||
event BridgehubMintData(bytes bridgeMintData); | ||
|
||
event BridgehubDepositFinalized( | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,4 @@ pragma solidity 0.8.24; | |
/// @custom:security-contact [email protected] | ||
interface IL1SharedBridgeLegacy { | ||
function l2BridgeAddress(uint256 _chainId) external view returns (address); | ||
|
||
event LegacyDepositInitiated( | ||
uint256 indexed chainId, | ||
bytes32 indexed l2DepositTxHash, | ||
address indexed from, | ||
address to, | ||
address l1Asset, | ||
uint256 amount | ||
); | ||
} |
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 |
---|---|---|
|
@@ -2,9 +2,20 @@ | |
|
||
pragma solidity ^0.8.20; | ||
|
||
import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
interface IL2SharedBridgeLegacy { | ||
event FinalizeDeposit( | ||
address indexed l1Sender, | ||
address indexed l2Receiver, | ||
address indexed l2Token, | ||
uint256 amount | ||
); | ||
|
||
function l2TokenBeacon() external returns (UpgradeableBeacon); | ||
|
||
function withdraw(address _l1Receiver, address _l2Token, uint256 _amount) external; | ||
|
||
function l1TokenAddress(address _l2Token) 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
22 changes: 22 additions & 0 deletions
22
l1-contracts/contracts/governance/L2ProxyAdminDeployer.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,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
// solhint-disable gas-length-in-loops | ||
|
||
import {ProxyAdmin} from "@openzeppelin/contracts-v4/proxy/transparent/ProxyAdmin.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @notice The contract that deterministically deploys a ProxyAdmin, while | ||
/// ensuring that its owner is the aliased governance contract | ||
contract L2ProxyAdminDeployer { | ||
address public immutable PROXY_ADMIN_ADDRESS; | ||
|
||
constructor(address _aliasedGovernance) { | ||
ProxyAdmin admin = new ProxyAdmin{salt: bytes32(0)}(); | ||
admin.transferOwnership(_aliasedGovernance); | ||
|
||
PROXY_ADMIN_ADDRESS = address(admin); | ||
} | ||
} |
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,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
// solhint-disable gas-length-in-loops | ||
|
||
import {Ownable2Step} from "@openzeppelin/contracts-v4/access/Ownable2Step.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @notice The contract that is used a temporary owner for Ownable2Step contracts until the | ||
/// governance can accept the ownership | ||
contract TransitionaryOwner { | ||
address public immutable GOVERNANCE_ADDRESS; | ||
|
||
constructor(address _governanceAddress) { | ||
GOVERNANCE_ADDRESS = _governanceAddress; | ||
} | ||
|
||
/// @notice Claims that ownership of a contract and transfers it to the governance | ||
function claimOwnershipAndGiveToGovernance(address target) external { | ||
Ownable2Step(target).acceptOwnership(); | ||
Ownable2Step(target).transferOwnership(GOVERNANCE_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 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
Oops, something went wrong.