Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EVM-708 bridge fixes #703

Merged
merged 19 commits into from
Aug 16, 2024
23 changes: 0 additions & 23 deletions l1-contracts/contracts/upgrades/CustomAssetBridging.sol

This file was deleted.

43 changes: 43 additions & 0 deletions l1-contracts/contracts/upgrades/GatewayUpgrade.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Diamond} from "../state-transition/libraries/Diamond.sol";
import {BaseZkSyncUpgrade, ProposedUpgrade} from "./BaseZkSyncUpgrade.sol";

import {DataEncoding} from "../common/libraries/DataEncoding.sol";

import {AdminFacet} from "../state-transition/chain-deps/facets/Admin.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, AdminFacet {
/// @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) {
(
address l1DAValidator,
address l2DAValidator,
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
address l2LegacyBridge,
bytes memory l2TxDataStart,
bytes memory l2TxDataFinish
) = abi.decode(_proposedUpgrade.postUpgradeCalldata, (address, address, address, bytes, bytes));

s.baseTokenAssetId = DataEncoding.encodeNTVAssetId(block.chainid, s.baseToken);
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
/// maybe set baseTokenAssetId in Bridgehub here
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
_setDAValidatorPair(l1DAValidator, l2DAValidator);

ProposedUpgrade memory proposedUpgrade = _proposedUpgrade;
/// We might want to read the l2LegacyBridge address from a specific contract based on chainId.
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
proposedUpgrade.l2ProtocolUpgradeTx.data = bytes.concat(l2TxDataStart, bytes20(l2LegacyBridge), l2TxDataFinish);
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
this.upgradeExternal(proposedUpgrade);
return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE;
}

function upgradeExternal(ProposedUpgrade calldata _proposedUpgrade) external {
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
// solhint-disable-next-line gas-custom-errors
require(msg.sender == address(this), "GatewayUpgrade: upgradeExternal");
super.upgrade(_proposedUpgrade);
}
}
17 changes: 14 additions & 3 deletions l2-contracts/contracts/bridge/L2NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,20 @@ contract L2NativeTokenVault is IL2NativeTokenVault, Ownable2StepUpgradeable {
// Make sure that a NativeTokenVault sent the message
revert AssetIdMismatch(expectedAssetId, _assetId);
}
address deployedToken = _deployL2Token(originToken, erc20Data);
if (deployedToken != expectedToken) {
revert AddressMismatch(expectedToken, deployedToken);
address l1LegacyToken;
if (address(L2_LEGACY_SHARED_BRIDGE) != address(0)) {
l1LegacyToken = L2_LEGACY_SHARED_BRIDGE.l1TokenAddress(expectedToken);
}
if (l1LegacyToken != address(0)) {
/// token is a legacy token, no need to deploy
if (l1LegacyToken != originToken) {
revert AddressMismatch(originToken, l1LegacyToken);
}
} else {
address deployedToken = _deployL2Token(originToken, erc20Data);
if (deployedToken != expectedToken) {
revert AddressMismatch(expectedToken, deployedToken);
}
}
tokenAddress[_assetId] = expectedToken;
token = expectedToken;
Expand Down
9 changes: 5 additions & 4 deletions l2-contracts/contracts/bridge/L2StandardERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ERC1967Upgrade} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgra

import {IL2StandardToken} from "./interfaces/IL2StandardToken.sol";
import {EmptyAddress, Unauthorized, NonSequentialVersion, Unimplemented} from "../L2ContractErrors.sol";
import {L2_NATIVE_TOKEN_VAULT} from "../L2ContractHelper.sol";

/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
Expand Down Expand Up @@ -37,8 +38,8 @@ contract L2StandardERC20 is ERC20PermitUpgradeable, IL2StandardToken, ERC1967Upg
/// @dev Address of the L1 token that can be deposited to mint this L2 token
address public override l1Address;

modifier onlyBridge() {
if (msg.sender != l2Bridge) {
modifier onlyNTV() {
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
if (msg.sender != address(L2_NATIVE_TOKEN_VAULT)) {
revert Unauthorized();
}
_;
Expand Down Expand Up @@ -151,7 +152,7 @@ contract L2StandardERC20 is ERC20PermitUpgradeable, IL2StandardToken, ERC1967Upg
/// @param _to The account that will receive the created tokens.
/// @param _amount The amount that will be created.
/// @notice Should be called by bridge after depositing tokens from L1.
function bridgeMint(address _to, uint256 _amount) external override onlyBridge {
function bridgeMint(address _to, uint256 _amount) external override onlyNTV {
_mint(_to, _amount);
emit BridgeMint(_to, _amount);
}
Expand All @@ -160,7 +161,7 @@ contract L2StandardERC20 is ERC20PermitUpgradeable, IL2StandardToken, ERC1967Upg
/// @param _from The account from which tokens will be burned.
/// @param _amount The amount that will be burned.
/// @notice Should be called by bridge before withdrawing tokens to L1.
function bridgeBurn(address _from, uint256 _amount) external override onlyBridge {
function bridgeBurn(address _from, uint256 _amount) external override onlyNTV {
_burn(_from, _amount);
emit BridgeBurn(_from, _amount);
}
Expand Down
Loading