概要
TeleporterRegistryOwnableAppは、TeleporterRegistryAppの機能にOpenZeppelinのOwnableによる所有者ベースのアクセス制御を組み合わせた抽象コントラクトです。
これにより、Teleporterのバージョン管理に関する重要な操作をコントラクトの所有者(Owner)のみに制限します。
このコントラクトは、TeleporterRegistryAppを継承し、その中で定義されている抽象的なアクセス制御チェック関数 _checkTeleporterRegistryAppAccess を実装します。
実装にはOwnableコントラクトの_checkOwner関数が用いられており、updateMinTeleporterVersionやpauseTeleporterAddressといった管理者権限が必要な関数は、コントラクトの所有者だけが呼び出せるようになります。
開発者はこのコントラクトを継承することで、自身でアクセス制御ロジックを記述することなく、標準的で安全な所有者ベースの権限管理を持つTeleporter対応アプリケーションを容易に構築できます。
機能
このコントラクトの主な機能は、TeleporterRegistryAppが持つバージョン管理機能(最低バージョンの更新、特定バージョンの停止・再開)に対して、Ownableパターンを用いたアクセス制御を提供することです。
フロー
- 所有者による最低バージョンの更新
所有者による最低バージョンの更新
sequenceDiagram
participant Owner as 所有者
participant App as TeleporterRegistryOwnableApp (継承先コントラクト)
Owner->>+App: updateMinTeleporterVersion(新しいバージョン)
App->>App: _checkTeleporterRegistryAppAccess()
Note over App: 内部でOwnableの_checkOwner()を呼び出し、<br/>msg.senderが所有者であることを検証
App->>App: _setMinTeleporterVersion(新しいバージョン)
App-->>-Owner: 成功コード
// (c) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// SPDX-License-Identifier: LicenseRef-Ecosystem
pragma solidity 0.8.25;
import {TeleporterRegistryApp} from "./TeleporterRegistryApp.sol";
import {Ownable} from "@openzeppelin/contracts@5.0.2/access/Ownable.sol";
/**
* @dev Contract that inherits {TeleporterRegistryApp} and allows
* only owners of the contract to update the minimum Teleporter version or
* pause and unpause specific Teleporter versions.
*
* @custom:security-contact https://github.com/ava-labs/icm-contracts/blob/main/SECURITY.md
*/
abstract contract TeleporterRegistryOwnableApp is TeleporterRegistryApp, Ownable {
constructor(
address teleporterRegistryAddress,
address initialOwner,
uint256 minTeleporterVersion
)
TeleporterRegistryApp(teleporterRegistryAddress, minTeleporterVersion)
Ownable(initialOwner)
{}
/**
* @dev See {TeleporterRegistryApp-_checkTeleporterRegistryAppAccess}
*
* Checks that the caller is the owner of the contract for updating {minTeleporterVersion},
* and pausing/unpausing specific Teleporter version interactions.
*/
function _checkTeleporterRegistryAppAccess() internal view virtual override {
_checkOwner();
}
}関数
constructor
constructor(
address teleporterRegistryAddress,
address initialOwner,
uint256 minTeleporterVersion
)
TeleporterRegistryApp(teleporterRegistryAddress, minTeleporterVersion)
Ownable(initialOwner)
{}コントラクトを初期化する関数。
デプロイ時に、継承しているTeleporterRegistryAppとOwnableの両方のコンストラクタを呼び出して初期化します。
TeleporterRegistryAppにはレジストリのアドレスと最低バージョン番号を、Ownableにはコントラクトの初期所有者のアドレスを渡します。
処理フロー
TeleporterRegistryAppのコンストラクタをteleporterRegistryAddressとminTeleporterVersionを引数に呼び出します。OwnableのコンストラクタをinitialOwnerを引数に呼び出し、コントラクトの所有者を設定します。
引数
- teleporterRegistryAddress
TeleporterRegistryコントラクトのアドレス。 - initialOwner このコントラクトの初期所有者となるアドレス。
- minTeleporterVersion
メッセージ受信を許可する
TeleporterMessengerの最低バージョン番号。
_checkTeleporterRegistryAppAccess
function _checkTeleporterRegistryAppAccess() internal view virtual override {
_checkOwner();
}TeleporterRegistryAppの管理機能へのアクセス権を検証する内部関数。
親コントラクトTeleporterRegistryAppでvirtualとして定義された関数をoverrideして実装しています。
この関数は、updateMinTeleporterVersionなどの重要な関数から呼び出されます。
処理フロー
Ownableコントラクトから継承した内部関数_checkOwner()を呼び出します。- (
_checkOwner()内)msg.senderがコントラクトの所有者(owner)と一致するかどうかを確認します。一致しない場合はエラーを返します。