Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/ac
import {ReentrancyGuard} from "../../common/ReentrancyGuard.sol";

import {IAssetTrackerBase} from "./IAssetTrackerBase.sol";
import {GatewayToL1TokenBalanceMigrationData, L1ToGatewayTokenBalanceMigrationData} from "../../common/Messaging.sol";

import {L2_TO_L1_MESSENGER_SYSTEM_CONTRACT} from "../../common/l2-helpers/L2ContractInterfaces.sol";
import {INativeTokenVaultBase} from "../ntv/INativeTokenVaultBase.sol";
import {Unauthorized} from "../../common/L1ContractErrors.sol";
import {DynamicIncrementalMerkleMemory} from "../../common/libraries/DynamicIncrementalMerkleMemory.sol";
import {SERVICE_TRANSACTION_SENDER} from "../../common/Config.sol";
import {AssetHandlerModifiers} from "../interfaces/AssetHandlerModifiers.sol";
import {InsufficientChainBalance} from "./AssetTrackerErrors.sol";
import {IAssetTrackerDataEncoding} from "./IAssetTrackerDataEncoding.sol";

abstract contract AssetTrackerBase is
IAssetTrackerBase,
Expand Down Expand Up @@ -128,24 +124,6 @@ abstract contract AssetTrackerBase is
chainBalance[_chainId][_assetId] -= _amount;
}

/// @notice Sends L1 -> Gateway migration data to L1 through the L2->L1 messenger.
/// @param _data The migration payload.
function _sendL1ToGatewayMigrationDataToL1(L1ToGatewayTokenBalanceMigrationData memory _data) internal {
// slither-disable-next-line unused-return,reentrancy-no-eth
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT.sendToL1(
abi.encodeCall(IAssetTrackerDataEncoding.receiveL1ToGatewayMigrationOnL1, _data)
);
}

/// @notice Sends Gateway -> L1 migration data to L1 through the L2->L1 messenger.
/// @param _data The migration payload.
function _sendGatewayToL1MigrationDataToL1(GatewayToL1TokenBalanceMigrationData memory _data) internal {
// slither-disable-next-line unused-return,reentrancy-no-eth
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT.sendToL1(
abi.encodeCall(IAssetTrackerDataEncoding.receiveGatewayToL1MigrationOnL1, _data)
);
}

/*//////////////////////////////////////////////////////////////
Token deposits and withdrawals
//////////////////////////////////////////////////////////////*/
Expand Down
10 changes: 10 additions & 0 deletions l1-contracts/contracts/bridge/asset-tracker/GWAssetTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
L2_KNOWN_CODE_STORAGE_SYSTEM_CONTRACT_ADDR,
L2_MESSAGE_ROOT,
L2_NATIVE_TOKEN_VAULT,
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT,
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT_ADDR,
MAX_BUILT_IN_CONTRACT_ADDR,
L2_ASSET_ROUTER,
Expand Down Expand Up @@ -734,6 +735,15 @@ contract GWAssetTracker is AssetTrackerBase, IGWAssetTracker {
emit GatewayToL1MigrationInitiated(_assetId, _chainId, amount);
}

/// @notice Sends Gateway -> L1 migration data to L1 through the L2->L1 messenger.
/// @param _data The migration payload.
function _sendGatewayToL1MigrationDataToL1(GatewayToL1TokenBalanceMigrationData memory _data) internal {
// slither-disable-next-line unused-return,reentrancy-no-eth
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT.sendToL1(
abi.encodeCall(IAssetTrackerDataEncoding.receiveGatewayToL1MigrationOnL1, _data)
);
}

function _calculatePreviousChainMigrationNumber(uint256 _chainId) internal view returns (uint256) {
uint256 settlementLayer = L2_BRIDGEHUB.settlementLayer(_chainId);
uint256 chainMigrationNumber = _getChainMigrationNumber(_chainId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.21;

bytes1 constant BALANCE_CHANGE_VERSION = bytes1(uint8(1));
bytes1 constant TOKEN_BALANCE_MIGRATION_DATA_VERSION = bytes1(uint8(1));
bytes1 constant INTEROP_BALANCE_CHANGE_VERSION = bytes1(uint8(1));
uint256 constant MAX_TOKEN_BALANCE = type(uint256).max;

struct SavedTotalSupply {
Expand Down
11 changes: 11 additions & 0 deletions l1-contracts/contracts/bridge/asset-tracker/L2AssetTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
} from "./AssetTrackerErrors.sol";
import {AssetTrackerBase} from "./AssetTrackerBase.sol";
import {IL2AssetTracker} from "./IL2AssetTracker.sol";
import {IAssetTrackerDataEncoding} from "./IAssetTrackerDataEncoding.sol";
import {L2_TO_L1_MESSENGER_SYSTEM_CONTRACT} from "../../common/l2-helpers/L2ContractInterfaces.sol";

contract L2AssetTracker is AssetTrackerBase, IL2AssetTracker {
uint256 public L1_CHAIN_ID;
Expand Down Expand Up @@ -445,6 +447,15 @@ contract L2AssetTracker is AssetTrackerBase, IL2AssetTracker {
emit IL2AssetTracker.L1ToGatewayMigrationInitiated(_assetId, block.chainid);
}

/// @notice Sends L1 -> Gateway migration data to L1 through the L2->L1 messenger.
/// @param _data The migration payload.
function _sendL1ToGatewayMigrationDataToL1(L1ToGatewayTokenBalanceMigrationData memory _data) internal {
// slither-disable-next-line unused-return,reentrancy-no-eth
L2_TO_L1_MESSENGER_SYSTEM_CONTRACT.sendToL1(
abi.encodeCall(IAssetTrackerDataEncoding.receiveL1ToGatewayMigrationOnL1, _data)
);
}

/// @notice Confirms a migration operation has been completed and updates the asset migration number.
/// @dev This function is called by L1 after a migration has been processed to update local state.
/// @param _data The migration confirmation data containing the asset ID and migration number.
Expand Down
21 changes: 1 addition & 20 deletions system-contracts/contracts/abstract/SystemContractBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
pragma solidity ^0.8.20;

import {SystemContractHelper} from "../libraries/SystemContractHelper.sol";
import {BOOTLOADER_FORMAL_ADDRESS, L2_INTEROP_CENTER_ADDRESS, L2_INTEROP_HANDLER_ADDRESS} from "../Constants.sol";
import {L2_NATIVE_TOKEN_VAULT} from "../Contracts.sol";
import {BOOTLOADER_FORMAL_ADDRESS} from "../Constants.sol";
import {
CallerMustBeBootloader,
CallerMustBeEvmContract,
CallerMustBeInteropCenterOrNTV,
CallerMustBeSystemContract,
SystemCallFlagRequired,
Unauthorized
Expand Down Expand Up @@ -69,21 +67,4 @@ abstract contract SystemContractBase {
_;
}

/// @notice Modifier that makes sure that the method
/// can only be called from the bootloader.
modifier onlyCallFromBootloaderOrInteropHandler() {
if (msg.sender != BOOTLOADER_FORMAL_ADDRESS && msg.sender != L2_INTEROP_HANDLER_ADDRESS) {
revert CallerMustBeBootloader();
}
_;
}

/// @notice Modifier that makes sure that the method
/// can only be called from the interop center or the NTV.
modifier onlyCallFromInteropCenterOrNTV() {
if (msg.sender != L2_INTEROP_CENTER_ADDRESS && msg.sender != address(L2_NATIVE_TOKEN_VAULT)) {
revert CallerMustBeInteropCenterOrNTV();
}
_;
}
}