-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
…a-contracts into kl/interop
- Loading branch information
Showing
77 changed files
with
3,317 additions
and
577 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 |
---|---|---|
|
@@ -5,11 +5,13 @@ pragma solidity ^0.8.21; | |
import {IL1Nullifier} from "../interfaces/IL1Nullifier.sol"; | ||
import {INativeTokenVault} from "../ntv/INativeTokenVault.sol"; | ||
import {IAssetRouterBase} from "./IAssetRouterBase.sol"; | ||
import {L2TransactionRequestTwoBridgesInner} from "../../bridgehub/IBridgehub.sol"; | ||
Check failure on line 8 in l1-contracts/contracts/bridge/asset-router/IL1AssetRouter.sol GitHub Actions / lint
Check failure on line 8 in l1-contracts/contracts/bridge/asset-router/IL1AssetRouter.sol GitHub Actions / lint
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,14 @@ pragma solidity 0.8.24; | |
|
||
import {IL1Nullifier} from "../interfaces/IL1Nullifier.sol"; | ||
import {INativeTokenVault} from "./INativeTokenVault.sol"; | ||
import {IL1AssetDeploymentTracker} from "../interfaces/IL1AssetDeploymentTracker.sol"; | ||
|
||
/// @title L1 Native token vault contract interface | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @notice The NTV is an Asset Handler for the L1AssetRouter to handle native tokens | ||
// is IL1AssetHandler, IL1BaseTokenAssetHandler { | ||
interface IL1NativeTokenVault is INativeTokenVault { | ||
interface IL1NativeTokenVault is INativeTokenVault, IL1AssetDeploymentTracker { | ||
/// @notice The L1Nullifier contract | ||
function L1_NULLIFIER() external view returns (IL1Nullifier); | ||
|
||
|
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import {ChainAdmin} from "./ChainAdmin.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @dev Contract used to deploy ChainAdmin contracts on L2. | ||
/// @dev It can be used to ensure that certain L2 admins are deployed with | ||
/// predefined restrictions. E.g. it can be used to deploy admins that ensure that | ||
/// a chain is a permanent rollup. | ||
/// @dev This contract is expected to be deployed in zkEVM (L2) environment. | ||
/// @dev The contract is immutable, in case the restrictions need to be changed, | ||
/// a new contract should be deployed. | ||
contract L2AdminFactory { | ||
event AdminDeployed(address admin); | ||
|
||
/// @dev We use storage instead of immutable variables due to the | ||
/// specifics of the zkEVM environment, where storage is actually cheaper. | ||
address[] public requiredRestrictions; | ||
|
||
constructor(address[] memory _requiredRestrictions) { | ||
requiredRestrictions = _requiredRestrictions; | ||
} | ||
|
||
/// @notice Deploys a new L2 admin contract. | ||
/// @return admin The address of the deployed admin contract. | ||
function deployAdmin(address[] calldata _additionalRestrictions, bytes32 _salt) external returns (address admin) { | ||
address[] memory restrictions = new address[](requiredRestrictions.length + _additionalRestrictions.length); | ||
uint256 cachedRequired = requiredRestrictions.length; | ||
for (uint256 i = 0; i < cachedRequired; ++i) { | ||
restrictions[i] = requiredRestrictions[i]; | ||
} | ||
uint256 cachedAdditional = _additionalRestrictions.length; | ||
for (uint256 i = 0; i < cachedAdditional; ++i) { | ||
restrictions[requiredRestrictions.length + i] = _additionalRestrictions[i]; | ||
} | ||
|
||
admin = address(new ChainAdmin{salt: _salt}(restrictions)); | ||
} | ||
} |
Oops, something went wrong.