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

Migrate to custom errors #828

Draft
wants to merge 34 commits into
base: gateway-release-candidate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a3a1f54
L1 Bridge Errors
Yberjon Sep 2, 2024
8feb4b1
Bridgehub errors
Yberjon Sep 2, 2024
87ee08c
Dev Contracts errors
Yberjon Sep 2, 2024
0aeea30
State Transition Manager Errors
Yberjon Sep 2, 2024
ba96aec
Upgrades Errors
Yberjon Sep 2, 2024
608187b
L1 Deploy Scripts errors
Yberjon Sep 2, 2024
1aa23fb
Dummy Executor errors
Yberjon Sep 2, 2024
dba883b
Bridgehub modifiers errors
Yberjon Sep 3, 2024
87028b5
Add missing L1 contracts errors
Yberjon Sep 3, 2024
4bae608
Add L1 Tests errors
Yberjon Sep 3, 2024
0ca2c2a
L2 contracts tests
Yberjon Sep 3, 2024
4e855b8
System Contracts errors
Yberjon Sep 3, 2024
53da1f1
DA Contracts Errors
Yberjon Sep 3, 2024
623e682
Gas Bound Caller Errors
Yberjon Sep 3, 2024
201ecf4
Adjust expect reverts
Yberjon Sep 4, 2024
7ee76fe
Prettier fixes
Yberjon Sep 4, 2024
18fd81d
Small fixes
Yberjon Sep 4, 2024
57d6525
Import fixes
Yberjon Sep 4, 2024
55934ef
Fixes
Yberjon Sep 4, 2024
b3e0d63
Fix
Yberjon Sep 4, 2024
e05b88a
Fix 2
Yberjon Sep 4, 2024
89ae205
Import fixes 2
Yberjon Sep 4, 2024
e3872a8
Import fixes 3
Yberjon Sep 4, 2024
9bdd6ff
Import fixes 4
Yberjon Sep 4, 2024
48b9cc1
Fix error name
Yberjon Sep 4, 2024
6a2fba4
Fixes 3
Yberjon Sep 4, 2024
76b68e7
Fix L1 tests
Yberjon Sep 4, 2024
33b25da
Fixes 4
Yberjon Sep 5, 2024
52b555d
Add CR fixes
Yberjon Sep 9, 2024
773209f
Prettier fixes
Yberjon Sep 9, 2024
7d6b440
Fix expect reverts
Yberjon Sep 9, 2024
fcb0138
upd with sync layer reorg
StanislavBreadless Sep 10, 2024
9800e40
sync with base branch and it compiles
StanislavBreadless Sep 27, 2024
4416d5f
wip
StanislavBreadless Sep 27, 2024
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
34 changes: 26 additions & 8 deletions da-contracts/contracts/CalldataDA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity 0.8.24;

import {OperatorDAInputLengthTooSmall, InvalidNumberOfBlobs, InvalidBlobsHashes, InvalidL2DAOutputHash, OneBlobWithCalldata, PubdataInputTooSmall, PubdataLengthTooBig, InvalidPubdataHash} from "./DAContractsErrors.sol";

// solhint-disable gas-custom-errors, reason-string

/// @dev Total number of bytes in a blob. Blob = 4096 field elements * 31 bytes per field element
Expand Down Expand Up @@ -44,26 +46,34 @@ abstract contract CalldataDA {
// - Then, there are linear hashes of the published blobs, 32 bytes each.

// Check that it accommodates enough pubdata for the state diff hash, hash of pubdata + the number of blobs.
require(_operatorDAInput.length >= BLOB_DATA_OFFSET, "too small");
if (_operatorDAInput.length < BLOB_DATA_OFFSET) {
revert OperatorDAInputLengthTooSmall(_operatorDAInput.length, BLOB_DATA_OFFSET);
}

stateDiffHash = bytes32(_operatorDAInput[:32]);
fullPubdataHash = bytes32(_operatorDAInput[32:64]);
blobsProvided = uint256(uint8(_operatorDAInput[64]));

require(blobsProvided <= _maxBlobsSupported, "invalid number of blobs");
if (blobsProvided > _maxBlobsSupported) {
revert InvalidNumberOfBlobs(blobsProvided, _maxBlobsSupported);
}

// Note that the API of the contract requires that the returned blobs linear hashes have length of
// the `_maxBlobsSupported`
blobsLinearHashes = new bytes32[](_maxBlobsSupported);

require(_operatorDAInput.length >= BLOB_DATA_OFFSET + 32 * blobsProvided, "invalid blobs hashes");
if (_operatorDAInput.length < BLOB_DATA_OFFSET + 32 * blobsProvided) {
revert InvalidBlobsHashes(_operatorDAInput.length, BLOB_DATA_OFFSET + 32 * blobsProvided);
}

_cloneCalldata(blobsLinearHashes, _operatorDAInput[BLOB_DATA_OFFSET:], blobsProvided);

uint256 ptr = BLOB_DATA_OFFSET + 32 * blobsProvided;

// Now, we need to double check that the provided input was indeed returned by the L2 DA validator.
require(keccak256(_operatorDAInput[:ptr]) == _l2DAValidatorOutputHash, "invalid l2 DA output hash");
if (keccak256(_operatorDAInput[:ptr]) != _l2DAValidatorOutputHash) {
revert InvalidL2DAOutputHash();
}

// The rest of the output was provided specifically by the operator
l1DaInput = _operatorDAInput[ptr:];
Expand All @@ -81,8 +91,12 @@ abstract contract CalldataDA {
uint256 _maxBlobsSupported,
bytes calldata _pubdataInput
) internal pure virtual returns (bytes32[] memory blobCommitments, bytes calldata _pubdata) {
require(_blobsProvided == 1, "one blob with calldata");
require(_pubdataInput.length >= BLOB_COMMITMENT_SIZE, "pubdata too small");
if (_blobsProvided != 1) {
revert OneBlobWithCalldata();
}
if (_pubdataInput.length < BLOB_COMMITMENT_SIZE) {
revert PubdataInputTooSmall(_pubdataInput.length, BLOB_COMMITMENT_SIZE);
}

// We typically do not know whether we'll use calldata or blobs at the time when
// we start proving the batch. That's why the blob commitment for a single blob is still present in the case of calldata.
Expand All @@ -91,8 +105,12 @@ abstract contract CalldataDA {

_pubdata = _pubdataInput[:_pubdataInput.length - BLOB_COMMITMENT_SIZE];

require(_pubdata.length <= BLOB_SIZE_BYTES, "cz");
require(_fullPubdataHash == keccak256(_pubdata), "wp");
if (_pubdata.length > BLOB_SIZE_BYTES) {
revert PubdataLengthTooBig(_pubdata.length, BLOB_SIZE_BYTES);
}
if (_fullPubdataHash != keccak256(_pubdata)) {
revert InvalidPubdataHash(_fullPubdataHash, keccak256(_pubdata));
}
blobCommitments[0] = bytes32(_pubdataInput[_pubdataInput.length - BLOB_COMMITMENT_SIZE:_pubdataInput.length]);
}

Expand Down
18 changes: 18 additions & 0 deletions da-contracts/contracts/DAContractsErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ error NonEmptyBlobVersionHash(uint256 index);
error PointEvalCallFailed(bytes);
// 0x4daa985d
error PointEvalFailed(bytes);

error OperatorDAInputLengthTooSmall(uint256 operatorDAInputLength, uint256 blobDataOffset);

error InvalidNumberOfBlobs(uint256 blobsProvided, uint256 maxBlobsSupported);

error InvalidBlobsHashes(uint256 operatorDAInputLength, uint256 blobsProvided);

error InvalidL2DAOutputHash();

error OneBlobWithCalldata();

error PubdataInputTooSmall(uint256 pubdataInputLength, uint256 blobCommitmentSize);

error PubdataLengthTooBig(uint256 pubdataLength, uint256 blobSizeBytes);

error InvalidPubdataHash(bytes32 fullPubdataHash, bytes32 pubdata);

error BlobCommitmentNotPublished();
7 changes: 4 additions & 3 deletions da-contracts/contracts/RollupL1DAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {CalldataDA} from "./CalldataDA.sol";

import {PubdataSource, BLS_MODULUS, PUBDATA_COMMITMENT_SIZE, PUBDATA_COMMITMENT_CLAIMED_VALUE_OFFSET, PUBDATA_COMMITMENT_COMMITMENT_OFFSET, BLOB_DA_INPUT_SIZE, POINT_EVALUATION_PRECOMPILE_ADDR} from "./DAUtils.sol";

import {PubdataCommitmentsEmpty, InvalidPubdataCommitmentsSize, BlobHashCommitmentError, EmptyBlobVersionHash, NonEmptyBlobVersionHash, PointEvalCallFailed, PointEvalFailed} from "./DAContractsErrors.sol";
import {PubdataCommitmentsEmpty, InvalidPubdataCommitmentsSize, BlobHashCommitmentError, EmptyBlobVersionHash, NonEmptyBlobVersionHash, PointEvalCallFailed, PointEvalFailed, BlobCommitmentNotPublished} from "./DAContractsErrors.sol";

uint256 constant BLOBS_SUPPORTED = 6;

Expand Down Expand Up @@ -145,8 +145,9 @@ contract RollupL1DAValidator is IL1DAValidator, CalldataDA {
if (prepublishedCommitment != bytes32(0)) {
// We double check that this commitment has indeed been published.
// If that is the case, we do not care about the actual underlying data.
require(publishedBlobCommitments[prepublishedCommitment], "not published");

if (!publishedBlobCommitments[prepublishedCommitment]) {
revert BlobCommitmentNotPublished();
}
blobsCommitments[i] = prepublishedCommitment;
} else {
blobsCommitments[i] = _getPublishedBlobCommitment(versionedHashIndex, commitmentData);
Expand Down
37 changes: 37 additions & 0 deletions l1-contracts/contracts/bridge/L1BridgeContractErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.21;

error NotNTV();

error EthTransferFailed();

error NativeTokenVaultAlreadySet();

error NativeTokenVaultZeroAddress();

error LegacyClaimDepositNotSupported();

error LegacyEthWithdrawalNotSupported();

error LegacyTokenWithdrawal();

error WrongMsgLength(uint256 expected, uint256 length);

error NotNTVorADT(address msgSender, address deploymentTracker);

error AssetHandlerNotSet();

error NewEncodingFormatNotYetSupportedForNTV(address deploymentTracker, address nativeTokenVault);

error AssetHandlerDoesNotExistForAssetId();

error EthOnlyAcceptedFromSharedBridge(address sharedBridge, address msgSender);

error ZeroAmountToTransfer();

error WrongAmountTransferred(uint256 balance, uint256 sharedBridgeBalance);

error EmptyToken(address token, address ethTokenAddress);

error ClaimDepositFailed();
60 changes: 40 additions & 20 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
import {IMessageRoot} from "./IMessageRoot.sol";
import {ICTMDeploymentTracker} from "./ICTMDeploymentTracker.sol";
import {MigrationPaused, AssetIdAlreadyRegistered, ChainAlreadyLive, ChainNotLegacy, CTMNotRegistered, ChainIdNotRegistered, AssetHandlerNotRegistered, ZKChainLimitReached, CTMAlreadyRegistered, CTMNotRegistered, ZeroChainId, ChainIdTooBig, BridgeHubAlreadyRegistered, AddressTooLow, MsgValueMismatch, ZeroAddress, Unauthorized, SharedBridgeNotSet, WrongMagicValue, ChainIdAlreadyExists, ChainIdMismatch, ChainIdCantBeCurrentChain, EmptyAssetId, AssetIdNotSupported, IncorrectBridgeHubAddress} from "../common/L1ContractErrors.sol";
import {NotChainCTM, NotL1, NotRelayedSender, NotAssetRouter, TokenNotSet, ChainAlreadyPresent, ChainIdAlreadyPresent, ChainNotPresentInCTM, NotCtmDeployer, CTMNotRegistered, ChainIdMustNotMatchCurrentChainId, AssetIdNotRegistered, SecondBridgeAddressTooLow, NotInGatewayMode, SLNotWhitelisted, IncorrectChainAsset, NotCurrentSL, HyperchainNotRegistered, IncorrectSender, AssetInfo2, AlreadyCurrentSL} from "./L1BridgehubErrors.sol";

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainIdMustNotMatchCurrentChainId is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetIdNotRegistered is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetInfo2 is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainIdMustNotMatchCurrentChainId is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetIdNotRegistered is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetInfo2 is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainIdMustNotMatchCurrentChainId is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetIdNotRegistered is not used

Check failure on line 26 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AssetInfo2 is not used
import {NoCTMForAssetId, MigrationPaused, AssetIdAlreadyRegistered, ChainAlreadyLive, ChainNotLegacy, CTMNotRegistered, ChainIdNotRegistered, AssetHandlerNotRegistered, ZKChainLimitReached, CTMAlreadyRegistered, CTMNotRegistered, ZeroChainId, ChainIdTooBig, BridgeHubAlreadyRegistered, AddressTooLow, MsgValueMismatch, ZeroAddress, Unauthorized, SharedBridgeNotSet, WrongMagicValue, ChainIdAlreadyExists, ChainIdMismatch, ChainIdCantBeCurrentChain, EmptyAssetId, AssetIdNotSupported, IncorrectBridgeHubAddress} from "../common/L1ContractErrors.sol";

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainAlreadyLive is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainNotLegacy is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressTooLow is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainAlreadyLive is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainNotLegacy is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressTooLow is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainAlreadyLive is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name ChainNotLegacy is not used

Check failure on line 27 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressTooLow is not used

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -109,29 +110,29 @@

modifier onlyChainCTM(uint256 _chainId) {
if (msg.sender != chainTypeManager[_chainId]) {
revert Unauthorized(msg.sender);
revert NotChainCTM(msg.sender, chainTypeManager[_chainId]);
}
_;
}

modifier onlyL1() {
if (L1_CHAIN_ID != block.chainid) {
revert Unauthorized(msg.sender);
revert NotL1(L1_CHAIN_ID, block.chainid);
}
_;
}

modifier onlySettlementLayerRelayedSender() {
/// There is no sender for the wrapping, we use a virtual address.
if (msg.sender != SETTLEMENT_LAYER_RELAY_SENDER) {
revert Unauthorized(msg.sender);
revert NotRelayedSender(msg.sender, SETTLEMENT_LAYER_RELAY_SENDER);
}
_;
}

modifier onlyAssetRouter() {
if (msg.sender != assetRouter) {
revert Unauthorized(msg.sender);
revert NotAssetRouter(msg.sender, assetRouter);
}
_;
}
Expand Down Expand Up @@ -220,7 +221,9 @@
return;
}
address token = __DEPRECATED_baseToken[_chainId];
require(token != address(0), "BH: token not set");
if (token == address(0)) {
revert TokenNotSet();
}
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, token);
}

Expand All @@ -229,14 +232,15 @@
function setLegacyChainAddress(uint256 _chainId) external override {
address ctm = chainTypeManager[_chainId];
if (ctm == address(0)) {
revert ChainNotLegacy();
revert ChainAlreadyPresent();
}
if (zkChainMap.contains(_chainId)) {
revert ChainAlreadyLive();
revert ChainIdAlreadyPresent();
}
/// Note we have to do this before CTM is upgraded.
address chainAddress = IChainTypeManager(ctm).getZKChainLegacy(_chainId);
if (chainAddress == address(0)) {
revert ChainNotLegacy();
revert ChainNotPresentInCTM();
}
_registerNewZKChain(_chainId, chainAddress);
}
Expand Down Expand Up @@ -312,7 +316,7 @@
address sender = L1_CHAIN_ID == block.chainid ? msg.sender : AddressAliasHelper.undoL1ToL2Alias(msg.sender);
// This method can be accessed by l1CtmDeployer only
if (sender != address(l1CtmDeployer)) {
revert Unauthorized(sender);
revert NotCtmDeployer(sender, address(l1CtmDeployer));
}
if (!chainTypeManagerIsRegistered[_assetAddress]) {
revert CTMNotRegistered();
Expand Down Expand Up @@ -496,7 +500,7 @@
L2TransactionRequestTwoBridgesOuter calldata _request
) external payable override nonReentrant whenNotPaused onlyL1 returns (bytes32 canonicalTxHash) {
if (_request.secondBridgeAddress <= BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS) {
revert AddressTooLow(_request.secondBridgeAddress);
revert SecondBridgeAddressTooLow(_request.secondBridgeAddress, BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS);
}

{
Expand Down Expand Up @@ -585,7 +589,9 @@
bytes32 _canonicalTxHash,
uint64 _expirationTimestamp
) external override onlySettlementLayerRelayedSender {
require(L1_CHAIN_ID != block.chainid, "BH: not in sync layer mode");
if (L1_CHAIN_ID == block.chainid) {
revert NotInGatewayMode();
}
address zkChain = zkChainMap.get(_chainId);
IZKChain(zkChain).bridgehubRequestL2TransactionOnGateway(_canonicalTxHash, _expirationTimestamp);
}
Expand Down Expand Up @@ -684,16 +690,26 @@
address _originalCaller,
bytes calldata _data
) external payable override onlyAssetRouter whenMigrationsNotPaused returns (bytes memory bridgehubMintData) {
require(whitelistedSettlementLayers[_settlementChainId], "BH: SL not whitelisted");
if (!whitelistedSettlementLayers[_settlementChainId]) {
revert SLNotWhitelisted();
}

BridgehubBurnCTMAssetData memory bridgehubData = abi.decode(_data, (BridgehubBurnCTMAssetData));
require(_assetId == ctmAssetIdFromChainId(bridgehubData.chainId), "BH: assetInfo 1");
require(settlementLayer[bridgehubData.chainId] == block.chainid, "BH: not current SL");
if (_assetId != ctmAssetIdFromChainId(bridgehubData.chainId)) {
revert IncorrectChainAsset(_assetId, ctmAssetIdFromChainId(bridgehubData.chainId));
}
if (settlementLayer[bridgehubData.chainId] != block.chainid) {
revert NotCurrentSL(settlementLayer[bridgehubData.chainId], block.chainid);
}
settlementLayer[bridgehubData.chainId] = _settlementChainId;

address zkChain = zkChainMap.get(bridgehubData.chainId);
require(zkChain != address(0), "BH: zkChain not registered");
require(_originalCaller == IZKChain(zkChain).getAdmin(), "BH: incorrect sender");
if (zkChain == address(0)) {
revert HyperchainNotRegistered();
}
if (_originalCaller != IZKChain(zkChain).getAdmin()) {
revert IncorrectSender(_originalCaller, IZKChain(zkChain).getAdmin());
}

bytes memory ctmMintData = IChainTypeManager(chainTypeManager[bridgehubData.chainId]).forwardedBridgeBurn(
bridgehubData.chainId,
Expand All @@ -716,7 +732,7 @@
}

/// @dev IL1AssetHandler interface, used to receive a chain on the settlement layer.
/// @param _assetId the assetId of the chain's STM
/// @param _assetId the assetId of the chain's CTM
/// @param _bridgehubMintData the data for the mint
function bridgeMint(
uint256, // originChainId
Expand All @@ -726,8 +742,12 @@
BridgehubMintCTMAssetData memory bridgehubData = abi.decode(_bridgehubMintData, (BridgehubMintCTMAssetData));

address ctm = ctmAssetIdToAddress[_assetId];
require(ctm != address(0), "BH: assetInfo 2");
require(settlementLayer[bridgehubData.chainId] != block.chainid, "BH: already current SL");
if (ctm == address(0)) {
revert NoCTMForAssetId(_assetId);
}
if (settlementLayer[bridgehubData.chainId] == block.chainid) {
revert AlreadyCurrentSL(block.chainid);
}

settlementLayer[bridgehubData.chainId] = block.chainid;
chainTypeManager[bridgehubData.chainId] = ctm;
Expand Down
25 changes: 19 additions & 6 deletions l1-contracts/contracts/bridgehub/CTMDeploymentTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {IAssetRouterBase} from "../bridge/asset-router/IAssetRouterBase.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {TWO_BRIDGES_MAGIC_VALUE} from "../common/Config.sol";
import {L2_BRIDGEHUB_ADDR} from "../common/L2ContractAddresses.sol";
import {OnlyBridgehub, CTMNotRegistered, NotOwnerViaRouter, NoEthAllowed, NotOwner, WrongCounterPart} from "./L1BridgehubErrors.sol";

/// @dev The encoding version of the data.
bytes1 constant CTM_DEPLOYMENT_TRACKER_ENCODING_VERSION = 0x01;
Expand All @@ -31,14 +32,18 @@ contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable
/// @notice Checks that the message sender is the bridgehub.
modifier onlyBridgehub() {
// solhint-disable-next-line gas-custom-errors
require(msg.sender == address(BRIDGE_HUB), "CTM DT: not BH");
if (msg.sender != address(BRIDGE_HUB)) {
revert OnlyBridgehub(msg.sender, address(BRIDGE_HUB));
}
_;
}

/// @notice Checks that the message sender is the bridgehub.
modifier onlyOwnerViaRouter(address _originalCaller) {
// solhint-disable-next-line gas-custom-errors
require(msg.sender == address(L1_ASSET_ROUTER) && _originalCaller == owner(), "CTM DT: not owner via router");
if (msg.sender != address(L1_ASSET_ROUTER) || _originalCaller != owner()) {
revert NotOwnerViaRouter(msg.sender);
}
_;
}

Expand All @@ -61,7 +66,9 @@ contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable
function registerCTMAssetOnL1(address _ctmAddress) external onlyOwner {
// solhint-disable-next-line gas-custom-errors

require(BRIDGE_HUB.chainTypeManagerIsRegistered(_ctmAddress), "CTMDT: ctm not registered");
if (!BRIDGE_HUB.chainTypeManagerIsRegistered(_ctmAddress)) {
revert CTMNotRegistered();
}
L1_ASSET_ROUTER.setAssetHandlerAddressThisChain(bytes32(uint256(uint160(_ctmAddress))), address(BRIDGE_HUB));
BRIDGE_HUB.setAssetHandlerAddress(bytes32(uint256(uint160(_ctmAddress))), _ctmAddress);
}
Expand All @@ -88,10 +95,14 @@ contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable
) external payable onlyBridgehub returns (L2TransactionRequestTwoBridgesInner memory request) {
// solhint-disable-next-line gas-custom-errors

require(msg.value == 0, "CTMDT: no eth allowed");
if (msg.value != 0) {
revert NoEthAllowed();
}
// solhint-disable-next-line gas-custom-errors

require(_originalCaller == owner(), "CTMDT: not owner");
if (_originalCaller != owner()) {
revert NotOwner(_originalCaller, owner());
}
bytes1 encodingVersion = _data[0];
require(encodingVersion == CTM_DEPLOYMENT_TRACKER_ENCODING_VERSION, "CTMDT: wrong encoding version");
(address _ctmL1Address, address _ctmL2Address) = abi.decode(_data[1:], (address, address));
Expand All @@ -112,7 +123,9 @@ contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable
address _originalCaller,
address _assetHandlerAddressOnCounterpart
) external view override onlyOwnerViaRouter(_originalCaller) {
require(_assetHandlerAddressOnCounterpart == L2_BRIDGEHUB_ADDR, "CTMDT: wrong counter part");
if (_assetHandlerAddressOnCounterpart != L2_BRIDGEHUB_ADDR) {
revert WrongCounterPart(_assetHandlerAddressOnCounterpart, L2_BRIDGEHUB_ADDR);
}
}

function getAssetId(address _l1CTM) public view override returns (bytes32) {
Expand Down
Loading
Loading