-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]> Co-authored-by: Bence Haromi <[email protected]> Co-authored-by: kelemeno <[email protected]> Co-authored-by: kelemeno <[email protected]> Co-authored-by: Stanislav Bezkorovainyi <[email protected]> Co-authored-by: Raid Ateir <[email protected]> Co-authored-by: Grzegorz Prusak <[email protected]> Co-authored-by: Moshe Shababo <[email protected]> Co-authored-by: Akosh Farkash <[email protected]> Co-authored-by: Bruno França <[email protected]> Co-authored-by: Vlad Bochok <[email protected]> Co-authored-by: Roman Brodetski <[email protected]> Co-authored-by: vladbochok <[email protected]> Co-authored-by: Danil <[email protected]> Co-authored-by: Neo <[email protected]> Co-authored-by: tommysr <[email protected]> Co-authored-by: Rahul Saxena <[email protected]> Co-authored-by: Artem Makhortov <[email protected]> Co-authored-by: Zach Kolodny <[email protected]> Co-authored-by: perekopskiy <[email protected]> Co-authored-by: perekopskiy <[email protected]> Co-authored-by: Ivan Schasny <[email protected]> Co-authored-by: mm <[email protected]> Co-authored-by: Dima Zhornyk <[email protected]> Co-authored-by: Yberjon <[email protected]>
- Loading branch information
1 parent
45cf28c
commit 79215dc
Showing
23 changed files
with
180 additions
and
103 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
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 |
---|---|---|
|
@@ -7,7 +7,6 @@ import {IAssetRouterBase} from "./IAssetRouterBase.sol"; | |
import {AssetRouterBase} from "./AssetRouterBase.sol"; | ||
|
||
import {IL2NativeTokenVault} from "../ntv/IL2NativeTokenVault.sol"; | ||
import {INativeTokenVault} from "../ntv/INativeTokenVault.sol"; | ||
import {IL2SharedBridgeLegacy} from "../interfaces/IL2SharedBridgeLegacy.sol"; | ||
import {IAssetHandler} from "../interfaces/IAssetHandler.sol"; | ||
import {IBridgedStandardToken} from "../interfaces/IBridgedStandardToken.sol"; | ||
|
@@ -19,7 +18,7 @@ import {AddressAliasHelper} from "../../vendor/AddressAliasHelper.sol"; | |
import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "../../common/L2ContractAddresses.sol"; | ||
import {L2ContractHelper} from "../../common/libraries/L2ContractHelper.sol"; | ||
import {DataEncoding} from "../../common/libraries/DataEncoding.sol"; | ||
import {EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol"; | ||
import {TokenNotLegacy, EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -69,6 +68,13 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter { | |
_; | ||
} | ||
|
||
modifier onlyNTV() { | ||
if (msg.sender != L2_NATIVE_TOKEN_VAULT_ADDR) { | ||
revert InvalidCaller(msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
/// @dev Disable the initialization to prevent Parity hack. | ||
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy. | ||
/// @param _l1AssetRouter The address of the L1 Bridge contract. | ||
|
@@ -109,6 +115,12 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter { | |
_setAssetHandlerAddressThisChain(L2_NATIVE_TOKEN_VAULT_ADDR, _assetRegistrationData, _assetHandlerAddress); | ||
} | ||
|
||
function setLegacyTokenAssetHandler(bytes32 _assetId) external override onlyNTV { | ||
// Note, that it is an asset handler, but not asset deployment tracker, | ||
// which is located on L1. | ||
_setAssetHandler(_assetId, L2_NATIVE_TOKEN_VAULT_ADDR); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
Receive transaction Functions | ||
//////////////////////////////////////////////////////////////*/ | ||
|
@@ -131,26 +143,16 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter { | |
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
LEGACY FUNCTIONS | ||
INITIATTE DEPOSIT Functions | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @notice Initiates a withdrawal by burning funds on the contract and sending the message to L1 | ||
/// where tokens would be unlocked | ||
/// @dev do not rely on this function, it will be deprecated in the future | ||
/// @param _assetId The asset id of the withdrawn asset | ||
/// @param _assetData The data that is passed to the asset handler contract | ||
function withdraw(bytes32 _assetId, bytes memory _assetData) public override returns (bytes32) { | ||
return _withdrawSender(_assetId, _assetData, msg.sender, true); | ||
} | ||
|
||
function withdrawToken(address _l2NativeToken, bytes memory _assetData) public returns (bytes32) { | ||
bytes32 recordedAssetId = INativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).assetId(_l2NativeToken); | ||
uint256 recordedOriginChainId = INativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).originChainId(recordedAssetId); | ||
if (recordedOriginChainId == L1_CHAIN_ID) { | ||
revert AssetIdNotSupported(recordedAssetId); | ||
} | ||
bytes32 assetId = _ensureTokenRegisteredWithNTV(_l2NativeToken); | ||
return _withdrawSender(assetId, _assetData, msg.sender, true); | ||
function withdraw(bytes32 _assetId, bytes calldata _assetData) external returns (bytes32) { | ||
_withdrawSender(_assetId, _assetData, msg.sender, true); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
|
@@ -313,16 +315,29 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter { | |
} | ||
|
||
function _withdrawLegacy(address _l1Receiver, address _l2Token, uint256 _amount, address _sender) internal { | ||
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1TokenAddress(_l2Token)); | ||
bytes memory data = abi.encode(_amount, _l1Receiver); | ||
address l1Address = l1TokenAddress(_l2Token); | ||
if (l1Address == address(0)) { | ||
revert TokenNotLegacy(); | ||
} | ||
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1Address); | ||
bytes memory data = DataEncoding.encodeBridgeBurnData(_amount, _l1Receiver, _l2Token); | ||
_withdrawSender(assetId, data, _sender, false); | ||
} | ||
|
||
/// @notice Legacy getL1TokenAddress. | ||
/// @param _l2Token The address of token on L2. | ||
/// @return The address of token on L1. | ||
function l1TokenAddress(address _l2Token) public view returns (address) { | ||
return IBridgedStandardToken(_l2Token).l1Address(); | ||
bytes32 assetId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).assetId(_l2Token); | ||
if (assetId == bytes32(0)) { | ||
return address(0); | ||
} | ||
uint256 originChainId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).originChainId(assetId); | ||
if (originChainId != L1_CHAIN_ID) { | ||
return address(0); | ||
} | ||
|
||
return IBridgedStandardToken(_l2Token).originToken(); | ||
} | ||
|
||
/// @notice Legacy function used for backward compatibility to return L2 wrapped token | ||
|
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,4 +7,13 @@ 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,8 +2,6 @@ | |
|
||
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 { | ||
|
@@ -14,8 +12,6 @@ interface IL2SharedBridgeLegacy { | |
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,14 +4,13 @@ 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, IL1AssetDeploymentTracker { | ||
interface IL1NativeTokenVault is INativeTokenVault { | ||
/// @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
Oops, something went wrong.