diff --git a/packages/protocol/contracts/common/AddressManager.sol b/packages/protocol/contracts/common/AddressManager.sol index 91ab17e86da..5f0e1c1d378 100644 --- a/packages/protocol/contracts/common/AddressManager.sol +++ b/packages/protocol/contracts/common/AddressManager.sol @@ -55,14 +55,8 @@ contract AddressManager is EssentialContract, IAddressManager { /// @inheritdoc IAddressManager function getAddress(uint64 _chainId, bytes32 _name) external view override returns (address) { - address addr = _getOverride(_chainId, _name); - if (addr != address(0)) return addr; - else return __addresses[_chainId][_name]; + return __addresses[_chainId][_name]; } - /// @notice Gets the address mapped to a specific chainId-name pair. - /// @dev Sub-contracts can override this method to avoid reading from storage. - function _getOverride(uint64 _chainId, bytes32 _name) internal pure virtual returns (address) { } - function _authorizePause(address, bool) internal pure override notImplemented { } } diff --git a/packages/protocol/contracts/common/AddressResolver.sol b/packages/protocol/contracts/common/AddressResolver.sol index 27f88b2a221..eaad49760a6 100644 --- a/packages/protocol/contracts/common/AddressResolver.sol +++ b/packages/protocol/contracts/common/AddressResolver.sol @@ -43,15 +43,7 @@ abstract contract AddressResolver is IAddressResolver, Initializable { } /// @inheritdoc IAddressResolver - function resolve( - bytes32 _name, - bool _allowZeroAddress - ) - public - view - virtual - returns (address payable) - { + function resolve(bytes32 _name, bool _allowZeroAddress) public view virtual returns (address) { return _resolve(uint64(block.chainid), _name, _allowZeroAddress); } @@ -64,7 +56,7 @@ abstract contract AddressResolver is IAddressResolver, Initializable { public view virtual - returns (address payable) + returns (address) { return _resolve(_chainId, _name, _allowZeroAddress); } @@ -90,17 +82,21 @@ abstract contract AddressResolver is IAddressResolver, Initializable { bytes32 _name, bool _allowZeroAddress ) - private + internal view - returns (address payable addr_) + returns (address addr_) { - address _addressManager = addressManager; - if (_addressManager == address(0)) revert RESOLVER_INVALID_MANAGER(); - - addr_ = payable(IAddressManager(_addressManager).getAddress(_chainId, _name)); + addr_ = _getAddress(_chainId, _name); if (!_allowZeroAddress && addr_ == address(0)) { revert RESOLVER_ZERO_ADDR(_chainId, _name); } } + + function _getAddress(uint64 _chainId, bytes32 _name) internal view virtual returns (address) { + address _addressManager = addressManager; + if (_addressManager == address(0)) revert RESOLVER_INVALID_MANAGER(); + + return IAddressManager(_addressManager).getAddress(_chainId, _name); + } } diff --git a/packages/protocol/contracts/common/IAddressResolver.sol b/packages/protocol/contracts/common/IAddressResolver.sol index 886e123e1ba..85e23f64abc 100644 --- a/packages/protocol/contracts/common/IAddressResolver.sol +++ b/packages/protocol/contracts/common/IAddressResolver.sol @@ -16,13 +16,7 @@ interface IAddressResolver { /// @param _allowZeroAddress If set to true, does not throw if the resolved /// address is `address(0)`. /// @return Address associated with the given name. - function resolve( - bytes32 _name, - bool _allowZeroAddress - ) - external - view - returns (address payable); + function resolve(bytes32 _name, bool _allowZeroAddress) external view returns (address); /// @notice Resolves a name to its address deployed on a specified chain. /// @param _chainId The chainId of interest. @@ -38,5 +32,5 @@ interface IAddressResolver { ) external view - returns (address payable); + returns (address); } diff --git a/packages/protocol/contracts/L1/TaikoL1Hekla.sol b/packages/protocol/contracts/hekla/HeklaTaikoL1.sol similarity index 90% rename from packages/protocol/contracts/L1/TaikoL1Hekla.sol rename to packages/protocol/contracts/hekla/HeklaTaikoL1.sol index 75ecc6f598d..4a809824d6c 100644 --- a/packages/protocol/contracts/L1/TaikoL1Hekla.sol +++ b/packages/protocol/contracts/hekla/HeklaTaikoL1.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.24; -import "./TaikoL1.sol"; +import "../L1/TaikoL1.sol"; -/// @title TaikoL1Hekla +/// @title HeklaTaikoL1 /// @dev Labeled in AddressResolver as "taiko" /// @custom:security-contact security@taiko.xyz -contract TaikoL1Hekla is TaikoL1 { +contract HeklaTaikoL1 is TaikoL1 { /// @inheritdoc ITaikoL1 function getConfig() public pure override returns (TaikoData.Config memory) { return TaikoData.Config({ diff --git a/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol b/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol deleted file mode 100644 index 24927d5347a..00000000000 --- a/packages/protocol/contracts/mainnet/L1RollupAddressManager.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.24; - -import "../common/AddressManager.sol"; -import "../common/LibStrings.sol"; - -/// @title L1RollupAddressManager -/// @notice See the documentation in {IAddressManager}. -/// @dev This contract shall NOT be used to upgrade existing implementation unless the name-address -/// registration becomes stable in 0x579f40D0BE111b823962043702cabe6Aaa290780. -/// @custom:security-contact security@taiko.xyz -contract L1RollupAddressManager is AddressManager { - /// @notice Gets the address mapped to a specific chainId-name pair. - /// @dev Sub-contracts can override this method to avoid reading from storage. - /// Some names are not cached as they are not used frequently or - /// its address is likely to change. - function _getOverride( - uint64 _chainId, - bytes32 _name - ) - internal - pure - override - returns (address addr_) - { - if (_chainId == 1) { - if (_name == LibStrings.B_TAIKO_TOKEN) { - return 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800; - } - if (_name == LibStrings.B_SIGNAL_SERVICE) { - return 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C; - } - if (_name == LibStrings.B_BRIDGE) { - return 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC; - } - if (_name == LibStrings.B_TAIKO) { - return 0x06a9Ab27c7e2255df1815E6CC0168d7755Feb19a; - } - if (_name == LibStrings.B_TIER_SGX) { - return 0xb0f3186FC1963f774f52ff455DC86aEdD0b31F81; - } - if (_name == LibStrings.B_TIER_GUARDIAN_MINORITY) { - return 0x579A8d63a2Db646284CBFE31FE5082c9989E985c; - } - if (_name == LibStrings.B_TIER_GUARDIAN) { - return 0xE3D777143Ea25A6E031d1e921F396750885f43aC; - } - if (_name == LibStrings.B_AUTOMATA_DCAP_ATTESTATION) { - return 0x8d7C954960a36a7596d7eA4945dDf891967ca8A3; - } - if (_name == LibStrings.B_TIER_ROUTER) { - return 0x6E997f1F22C40ba37F633B08f3b07E10Ed43155a; - } - } - return address(0); - } -} diff --git a/packages/protocol/contracts/mainnet/LibAddressCache.sol b/packages/protocol/contracts/mainnet/LibAddressCache.sol new file mode 100644 index 00000000000..4e46585f456 --- /dev/null +++ b/packages/protocol/contracts/mainnet/LibAddressCache.sol @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../common/LibStrings.sol"; + +/// @title LibAddressCache +/// @custom:security-contact security@taiko.xyz +library LibAddressCache { + function getAddress( + uint64 _chainId, + bytes32 _name + ) + internal + pure + returns (bool found, address addr) + { + if (_chainId == 1) { + if (_name == LibStrings.B_TAIKO_TOKEN) { + return (true, 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800); + } + if (_name == LibStrings.B_SIGNAL_SERVICE) { + return (true, 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C); + } + if (_name == LibStrings.B_BRIDGE) { + return (true, 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC); + } + if (_name == LibStrings.B_TAIKO) { + return (true, 0x06a9Ab27c7e2255df1815E6CC0168d7755Feb19a); + } + if (_name == LibStrings.B_TIER_ROUTER) { + return (true, 0x6E997f1F22C40ba37F633B08f3b07E10Ed43155a); + } + if (_name == LibStrings.B_TIER_SGX) { + return (true, 0xb0f3186FC1963f774f52ff455DC86aEdD0b31F81); + } + if (_name == LibStrings.B_TIER_GUARDIAN_MINORITY) { + return (true, 0x579A8d63a2Db646284CBFE31FE5082c9989E985c); + } + if (_name == LibStrings.B_TIER_GUARDIAN) { + return (true, 0xE3D777143Ea25A6E031d1e921F396750885f43aC); + } + if (_name == LibStrings.B_AUTOMATA_DCAP_ATTESTATION) { + return (true, 0x8d7C954960a36a7596d7eA4945dDf891967ca8A3); + } + } + return (false, address(0)); + } +} diff --git a/packages/protocol/contracts/mainnet/MainnetProverSet.sol b/packages/protocol/contracts/mainnet/MainnetProverSet.sol new file mode 100644 index 00000000000..39b79187979 --- /dev/null +++ b/packages/protocol/contracts/mainnet/MainnetProverSet.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../team/proving/ProverSet.sol"; +import "./LibAddressCache.sol"; + +/// @title MainnetProverSet +/// @notice See the documentation in {ProverSet}. +/// @custom:security-contact security@taiko.xyz +contract MainnetProverSet is ProverSet { + function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { + (bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); + return found ? addr : super._getAddress(_chainId, _name); + } +} diff --git a/packages/protocol/contracts/mainnet/MainnetRollupAddressManager.sol b/packages/protocol/contracts/mainnet/MainnetRollupAddressManager.sol new file mode 100644 index 00000000000..8e8cda4eda9 --- /dev/null +++ b/packages/protocol/contracts/mainnet/MainnetRollupAddressManager.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../common/AddressManager.sol"; +import "../common/LibStrings.sol"; +import "./LibAddressCache.sol"; + +/// @title MainnetRollupAddressManager +/// @notice See the documentation in {IAddressManager}. +/// @custom:security-contact security@taiko.xyz +contract MainnetRollupAddressManager is AddressManager { + function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { + (bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); + return found ? addr : super._getAddress(_chainId, _name); + } +} diff --git a/packages/protocol/contracts/mainnet/L1SharedAddressManager.sol b/packages/protocol/contracts/mainnet/MainnetSharedAddressManager.sol similarity index 72% rename from packages/protocol/contracts/mainnet/L1SharedAddressManager.sol rename to packages/protocol/contracts/mainnet/MainnetSharedAddressManager.sol index 32677bafa95..87386fa26d1 100644 --- a/packages/protocol/contracts/mainnet/L1SharedAddressManager.sol +++ b/packages/protocol/contracts/mainnet/MainnetSharedAddressManager.sol @@ -4,31 +4,17 @@ pragma solidity 0.8.24; import "../common/AddressManager.sol"; import "../common/LibStrings.sol"; -/// @title L1SharedAddressManager +/// @title MainnetSharedAddressManager /// @notice See the documentation in {IAddressManager}. -/// @dev This contract shall NOT be used to upgrade existing implementation unless the name-address -/// registration becomes stable in 0xEf9EaA1dd30a9AA1df01c36411b5F082aA65fBaa. /// @custom:security-contact security@taiko.xyz -contract L1SharedAddressManager is AddressManager { - /// @notice Gets the address mapped to a specific chainId-name pair. - /// @dev Sub-contracts can override this method to avoid reading from storage. - /// Some names are not cached as they are not used frequently or - /// its address is likely to change. - function _getOverride( - uint64 _chainId, - bytes32 _name - ) - internal - pure - override - returns (address addr_) - { +contract MainnetSharedAddressManager is AddressManager { + function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { if (_chainId == 1) { if (_name == LibStrings.B_TAIKO_TOKEN) { return 0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800; } - if (_name == LibStrings.B_SIGNAL_SERVICE) { - return 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C; + if (_name == LibStrings.B_QUOTA_MANAGER) { + return 0x91f67118DD47d502B1f0C354D0611997B022f29E; } if (_name == LibStrings.B_BRIDGE) { return 0xd60247c6848B7Ca29eDdF63AA924E53dB6Ddd8EC; @@ -42,8 +28,8 @@ contract L1SharedAddressManager is AddressManager { if (_name == LibStrings.B_ERC1155_VAULT) { return 0xaf145913EA4a56BE22E120ED9C24589659881702; } - if (_name == LibStrings.B_QUOTA_MANAGER) { - return 0x91f67118DD47d502B1f0C354D0611997B022f29E; + if (_name == LibStrings.B_SIGNAL_SERVICE) { + return 0x9e0a24964e5397B566c1ed39258e21aB5E35C77C; } } else if (_chainId == 167_000) { if (_name == LibStrings.B_BRIDGE) { @@ -63,6 +49,6 @@ contract L1SharedAddressManager is AddressManager { } } - return address(0); + return super._getAddress(_chainId, _name); } } diff --git a/packages/protocol/contracts/mainnet/MainnetTaikoL1.sol b/packages/protocol/contracts/mainnet/MainnetTaikoL1.sol new file mode 100644 index 00000000000..850e333f643 --- /dev/null +++ b/packages/protocol/contracts/mainnet/MainnetTaikoL1.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../L1/TaikoL1.sol"; +import "./LibAddressCache.sol"; + +/// @title MainnetTaikoL1 +/// @notice See the documentation in {TaikoL1}. +/// @custom:security-contact security@taiko.xyz +contract MainnetTaikoL1 is TaikoL1 { + function _getAddress(uint64 _chainId, bytes32 _name) internal view override returns (address) { + (bool found, address addr) = LibAddressCache.getAddress(_chainId, _name); + return found ? addr : super._getAddress(_chainId, _name); + } +} diff --git a/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol b/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol index 2a4884c0998..6b6f5c4a2f2 100644 --- a/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol +++ b/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol @@ -3,11 +3,12 @@ pragma solidity 0.8.24; import "forge-std/src/Script.sol"; import "forge-std/src/console2.sol"; -import "../../contracts/L1/TaikoL1Hekla.sol"; + +import "../../contracts/hekla/HeklaTaikoL1.sol"; import "./UpgradeScript.s.sol"; contract UpgradeTaikoL1 is UpgradeScript { function run() external setUp { - upgrade("TaikoL1", address(new TaikoL1Hekla())); + upgrade("HeklaTaikoL1", address(new HeklaTaikoL1())); } }