-
Notifications
You must be signed in to change notification settings - Fork 357
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
1 parent
a71a049
commit 2bcd5de
Showing
13 changed files
with
256 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,15 @@ import {NativeTokenVault} from "./NativeTokenVault.sol"; | |
|
||
import {IL2SharedBridgeLegacy} from "../interfaces/IL2SharedBridgeLegacy.sol"; | ||
import {BridgedStandardERC20} from "../BridgedStandardERC20.sol"; | ||
import {IL2AssetRouter} from "../asset-router/IL2AssetRouter.sol"; | ||
|
||
import {DEPLOYER_SYSTEM_CONTRACT, L2_ASSET_ROUTER_ADDR} from "../../common/L2ContractAddresses.sol"; | ||
import {L2ContractHelper, IContractDeployer} from "../../common/libraries/L2ContractHelper.sol"; | ||
|
||
import {SystemContractsCaller} from "../../common/libraries/SystemContractsCaller.sol"; | ||
import {DataEncoding} from "../../common/libraries/DataEncoding.sol"; | ||
|
||
import {EmptyAddress, EmptyBytes32, AddressMismatch, DeployFailed, AssetIdNotSupported} from "../../common/L1ContractErrors.sol"; | ||
import {NoLegacySharedBridge, TokenIsLegacy, TokenIsNotLegacy, EmptyAddress, EmptyBytes32, AddressMismatch, DeployFailed, AssetIdNotSupported} from "../../common/L1ContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -85,8 +86,16 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault { | |
|
||
/// @notice Sets the legacy token asset ID for the given L2 token address. | ||
function setLegacyTokenAssetId(address _l2TokenAddress) public { | ||
if (address(L2_LEGACY_SHARED_BRIDGE) == address(0)) { | ||
revert NoLegacySharedBridge(); | ||
} | ||
address l1TokenAddress = L2_LEGACY_SHARED_BRIDGE.l1TokenAddress(_l2TokenAddress); | ||
bytes32 newAssetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1TokenAddress); | ||
if (l1TokenAddress == address(0)) { | ||
revert TokenIsNotLegacy(); | ||
} | ||
|
||
IL2AssetRouter(L2_ASSET_ROUTER_ADDR).setLegacyTokenAssetHandler(newAssetId); | ||
tokenAddress[newAssetId] = _l2TokenAddress; | ||
assetId[_l2TokenAddress] = newAssetId; | ||
originChainId[newAssetId] = L1_CHAIN_ID; | ||
|
@@ -244,6 +253,17 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault { | |
// on L2s we don't track the balance | ||
} | ||
|
||
function _registerToken(address _nativeToken) internal override { | ||
if ( | ||
address(L2_LEGACY_SHARED_BRIDGE) != address(0) && | ||
L2_LEGACY_SHARED_BRIDGE.l1TokenAddress(_nativeToken) != address(0) | ||
) { | ||
// Legacy tokens should be registered via `setLegacyTokenAssetId`. | ||
revert TokenIsLegacy(); | ||
} | ||
super._registerToken(_nativeToken); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
LEGACY FUNCTIONS | ||
//////////////////////////////////////////////////////////////*/ | ||
|
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
56 changes: 56 additions & 0 deletions
56
...ntracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2NativeTokenVaultL1Test.t.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,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
// solhint-disable gas-custom-errors | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
import {BridgedStandardERC20} from "contracts/bridge/BridgedStandardERC20.sol"; | ||
import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol"; | ||
import {IL2NativeTokenVault} from "contracts/bridge/ntv/IL2NativeTokenVault.sol"; | ||
|
||
import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol"; | ||
import {BeaconProxy} from "@openzeppelin/contracts-v4/proxy/beacon/BeaconProxy.sol"; | ||
|
||
import {L2_ASSET_ROUTER_ADDR, L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "contracts/common/L2ContractAddresses.sol"; | ||
import {ETH_TOKEN_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER} from "contracts/common/Config.sol"; | ||
|
||
import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol"; | ||
import {BridgehubMintCTMAssetData} from "contracts/bridgehub/IBridgehub.sol"; | ||
import {IAdmin} from "contracts/state-transition/chain-interfaces/IAdmin.sol"; | ||
import {IL2AssetRouter} from "contracts/bridge/asset-router/IL2AssetRouter.sol"; | ||
import {IL1Nullifier} from "contracts/bridge/interfaces/IL1Nullifier.sol"; | ||
import {IL1AssetRouter} from "contracts/bridge/asset-router/IL1AssetRouter.sol"; | ||
import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol"; | ||
|
||
import {SharedL2ContractDeployer} from "./_SharedL2ContractDeployer.sol"; | ||
import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol"; | ||
import {IZKChain} from "contracts/state-transition/chain-interfaces/IZKChain.sol"; | ||
import {SystemContractsArgs} from "./_SharedL2ContractL1DeployerUtils.sol"; | ||
|
||
import {DeployUtils} from "deploy-scripts/DeployUtils.s.sol"; | ||
import {L2NativeTokenVaultTestAbstract} from "./L2NativeTokenVaultTestAbstract.t.sol"; | ||
import {SharedL2ContractL1DeployerUtils} from "./_SharedL2ContractL1DeployerUtils.sol"; | ||
|
||
contract L2GatewayL1Test is | ||
Test, | ||
SharedL2ContractL1DeployerUtils, | ||
SharedL2ContractDeployer, | ||
L2NativeTokenVaultTestAbstract | ||
{ | ||
function test() internal virtual override(DeployUtils, SharedL2ContractL1DeployerUtils) {} | ||
|
||
function initSystemContracts( | ||
SystemContractsArgs memory _args | ||
) internal virtual override(SharedL2ContractDeployer, SharedL2ContractL1DeployerUtils) { | ||
super.initSystemContracts(_args); | ||
} | ||
|
||
function deployL2Contracts( | ||
uint256 _l1ChainId | ||
) public virtual override(SharedL2ContractDeployer, SharedL2ContractL1DeployerUtils) { | ||
super.deployL2Contracts(_l1ChainId); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...s/test/foundry/l1/integration/l2-tests-in-l1-context/L2NativeTokenVaultTestAbstract.t.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,69 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
// solhint-disable gas-custom-errors | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
import {BridgedStandardERC20} from "contracts/bridge/BridgedStandardERC20.sol"; | ||
import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol"; | ||
import {IL2NativeTokenVault} from "contracts/bridge/ntv/IL2NativeTokenVault.sol"; | ||
|
||
import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol"; | ||
import {BeaconProxy} from "@openzeppelin/contracts-v4/proxy/beacon/BeaconProxy.sol"; | ||
|
||
import {L2_ASSET_ROUTER_ADDR, L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "contracts/common/L2ContractAddresses.sol"; | ||
import {ETH_TOKEN_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER} from "contracts/common/Config.sol"; | ||
|
||
import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol"; | ||
import {BridgehubMintCTMAssetData} from "contracts/bridgehub/IBridgehub.sol"; | ||
import {IAdmin} from "contracts/state-transition/chain-interfaces/IAdmin.sol"; | ||
import {IL2AssetRouter} from "contracts/bridge/asset-router/IL2AssetRouter.sol"; | ||
import {IL1Nullifier} from "contracts/bridge/interfaces/IL1Nullifier.sol"; | ||
import {IL1AssetRouter} from "contracts/bridge/asset-router/IL1AssetRouter.sol"; | ||
import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol"; | ||
|
||
import {SharedL2ContractDeployer} from "./_SharedL2ContractDeployer.sol"; | ||
import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol"; | ||
import {IZKChain} from "contracts/state-transition/chain-interfaces/IZKChain.sol"; | ||
import {SystemContractsArgs} from "./_SharedL2ContractL1DeployerUtils.sol"; | ||
|
||
import {DeployUtils} from "deploy-scripts/DeployUtils.s.sol"; | ||
import {TokenIsLegacy, TokenIsNotLegacy, Unauthorized, UnimplementedMessage, BridgeMintNotImplemented} from "contracts/common/L1ContractErrors.sol"; | ||
|
||
import {IL2SharedBridgeLegacy} from "contracts/bridge/interfaces/IL2SharedBridgeLegacy.sol"; | ||
import {L2NativeTokenVault} from "contracts/bridge/ntv/L2NativeTokenVault.sol"; | ||
|
||
abstract contract L2NativeTokenVaultTestAbstract is Test, SharedL2ContractDeployer { | ||
function test_registerLegacyToken() external { | ||
address l2Token = makeAddr("l2Token"); | ||
address l1Token = makeAddr("l1Token"); | ||
vm.mockCall( | ||
sharedBridgeLegacy, | ||
abi.encodeCall(IL2SharedBridgeLegacy.l1TokenAddress, (l2Token)), | ||
abi.encode(l1Token) | ||
); | ||
L2NativeTokenVault(addresses.vaults.l1NativeTokenVaultProxy).setLegacyTokenAssetId(l2Token); | ||
} | ||
|
||
function test_registerLegacyTokenRevertNotLegacy() external { | ||
address l2Token = makeAddr("l2Token"); | ||
vm.expectRevert(TokenIsNotLegacy.selector); | ||
L2NativeTokenVault(addresses.vaults.l1NativeTokenVaultProxy).setLegacyTokenAssetId(l2Token); | ||
} | ||
|
||
function test_registerTokenRevertIsLegacy() external { | ||
address l2Token = makeAddr("l2Token"); | ||
address l1Token = makeAddr("l1Token"); | ||
vm.mockCall( | ||
sharedBridgeLegacy, | ||
abi.encodeCall(IL2SharedBridgeLegacy.l1TokenAddress, (l2Token)), | ||
abi.encode(l1Token) | ||
); | ||
|
||
vm.expectRevert(TokenIsLegacy.selector); | ||
L2NativeTokenVault(addresses.vaults.l1NativeTokenVaultProxy).registerToken(l2Token); | ||
} | ||
} |
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.