Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 4b0c72e

Browse files
CCIP-4105: adds OZ AccessControl support to the registry module (#15067)
* adds OZ AccessControl support to the registry module * [Bot] Update changeset file with jira issues * fix snap * update version --------- Co-Authored-By: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com>
1 parent 78704d3 commit 4b0c72e

File tree

5 files changed

+103
-8
lines changed

5 files changed

+103
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@chainlink/contracts': patch
3+
---
4+
5+
#feature adds OZ AccessControl support to the registry module
6+
7+
8+
PR issue: CCIP-4105
9+
10+
Solidity Review issue: CCIP-3966

contracts/gas-snapshots/ccip.gas-snapshot

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,13 @@ RateLimiter_consume:test_TokenRateLimitReached_Revert() (gas: 24886)
920920
RateLimiter_currentTokenBucketState:test_CurrentTokenBucketState_Success() (gas: 38944)
921921
RateLimiter_currentTokenBucketState:test_Refill_Success() (gas: 46849)
922922
RateLimiter_setTokenBucketConfig:test_SetRateLimiterConfig_Success() (gas: 38506)
923-
RegistryModuleOwnerCustom_constructor:test_constructor_Revert() (gas: 36033)
924-
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Revert() (gas: 19739)
925-
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Success() (gas: 130086)
926-
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Revert() (gas: 19559)
927-
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Success() (gas: 129905)
923+
RegistryModuleOwnerCustom_constructor:test_constructor_Revert() (gas: 36107)
924+
RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin:test_registerAccessControlDefaultAdmin_Revert() (gas: 20206)
925+
RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin:test_registerAccessControlDefaultAdmin_Success() (gas: 130628)
926+
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Revert() (gas: 19773)
927+
RegistryModuleOwnerCustom_registerAdminViaGetCCIPAdmin:test_registerAdminViaGetCCIPAdmin_Success() (gas: 130108)
928+
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Revert() (gas: 19593)
929+
RegistryModuleOwnerCustom_registerAdminViaOwner:test_registerAdminViaOwner_Success() (gas: 129927)
928930
Router_applyRampUpdates:test_OffRampMismatch_Revert() (gas: 89366)
929931
Router_applyRampUpdates:test_OffRampUpdatesWithRouting() (gas: 10662612)
930932
Router_applyRampUpdates:test_OnRampDisable() (gas: 56007)

contracts/src/v0.8/ccip/test/tokenAdminRegistry/RegistryModuleOwnerCustom.t.sol

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {RegistryModuleOwnerCustom} from "../../tokenAdminRegistry/RegistryModule
88
import {TokenAdminRegistry} from "../../tokenAdminRegistry/TokenAdminRegistry.sol";
99
import {BurnMintERC677Helper} from "../helpers/BurnMintERC677Helper.sol";
1010

11+
import {AccessControl} from "../../../vendor/openzeppelin-solidity/v5.0.2/contracts/access/AccessControl.sol";
1112
import {Test} from "forge-std/Test.sol";
1213

1314
contract RegistryModuleOwnerCustomSetup is Test {
@@ -102,3 +103,54 @@ contract RegistryModuleOwnerCustom_registerAdminViaOwner is RegistryModuleOwnerC
102103
s_registryModuleOwnerCustom.registerAdminViaOwner(s_token);
103104
}
104105
}
106+
107+
contract AccessController is AccessControl {
108+
constructor(
109+
address admin
110+
) {
111+
_grantRole(DEFAULT_ADMIN_ROLE, admin);
112+
}
113+
}
114+
115+
contract RegistryModuleOwnerCustom_registerAccessControlDefaultAdmin is RegistryModuleOwnerCustomSetup {
116+
function setUp() public override {
117+
super.setUp();
118+
119+
s_token = address(new AccessController(OWNER));
120+
}
121+
122+
function test_registerAccessControlDefaultAdmin_Success() public {
123+
assertEq(s_tokenAdminRegistry.getTokenConfig(s_token).administrator, address(0));
124+
125+
bytes32 defaultAdminRole = AccessController(s_token).DEFAULT_ADMIN_ROLE();
126+
127+
vm.expectCall(address(s_token), abi.encodeWithSelector(AccessControl.hasRole.selector, defaultAdminRole, OWNER), 1);
128+
vm.expectCall(
129+
address(s_tokenAdminRegistry),
130+
abi.encodeWithSelector(TokenAdminRegistry.proposeAdministrator.selector, s_token, OWNER),
131+
1
132+
);
133+
134+
vm.expectEmit();
135+
emit RegistryModuleOwnerCustom.AdministratorRegistered(s_token, OWNER);
136+
137+
s_registryModuleOwnerCustom.registerAccessControlDefaultAdmin(s_token);
138+
139+
assertEq(s_tokenAdminRegistry.getTokenConfig(s_token).pendingAdministrator, OWNER);
140+
}
141+
142+
function test_registerAccessControlDefaultAdmin_Revert() public {
143+
bytes32 defaultAdminRole = AccessController(s_token).DEFAULT_ADMIN_ROLE();
144+
145+
address wrongSender = makeAddr("Not_expected_owner");
146+
vm.startPrank(wrongSender);
147+
148+
vm.expectRevert(
149+
abi.encodeWithSelector(
150+
RegistryModuleOwnerCustom.RequiredRoleNotFound.selector, wrongSender, defaultAdminRole, s_token
151+
)
152+
);
153+
154+
s_registryModuleOwnerCustom.registerAccessControlDefaultAdmin(s_token);
155+
}
156+
}

contracts/src/v0.8/ccip/tokenAdminRegistry/RegistryModuleOwnerCustom.sol

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import {IGetCCIPAdmin} from "../interfaces/IGetCCIPAdmin.sol";
66
import {IOwner} from "../interfaces/IOwner.sol";
77
import {ITokenAdminRegistry} from "../interfaces/ITokenAdminRegistry.sol";
88

9+
import {AccessControl} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/access/AccessControl.sol";
10+
911
contract RegistryModuleOwnerCustom is ITypeAndVersion {
1012
error CanOnlySelfRegister(address admin, address token);
13+
error RequiredRoleNotFound(address msgSender, bytes32 role, address token);
1114
error AddressZero();
1215

1316
event AdministratorRegistered(address indexed token, address indexed administrator);
1417

15-
string public constant override typeAndVersion = "RegistryModuleOwnerCustom 1.5.0";
18+
string public constant override typeAndVersion = "RegistryModuleOwnerCustom 1.6.0";
1619

1720
// The TokenAdminRegistry contract
1821
ITokenAdminRegistry internal immutable i_tokenAdminRegistry;
@@ -38,6 +41,20 @@ contract RegistryModuleOwnerCustom is ITypeAndVersion {
3841
_registerAdmin(token, IOwner(token).owner());
3942
}
4043

44+
/// @notice Registers the admin of the token using OZ's AccessControl DEFAULT_ADMIN_ROLE.
45+
/// @param token The token to register the admin for.
46+
/// @dev The caller must have the DEFAULT_ADMIN_ROLE as defined by the contract itself.
47+
function registerAccessControlDefaultAdmin(
48+
address token
49+
) external {
50+
bytes32 defaultAdminRole = AccessControl(token).DEFAULT_ADMIN_ROLE();
51+
if (!AccessControl(token).hasRole(defaultAdminRole, msg.sender)) {
52+
revert RequiredRoleNotFound(msg.sender, defaultAdminRole, token);
53+
}
54+
55+
_registerAdmin(token, msg.sender);
56+
}
57+
4158
/// @notice Registers the admin of the token to msg.sender given that the
4259
/// admin is equal to msg.sender.
4360
/// @param token The token to register the admin for.

core/gethwrappers/ccip/generated/registry_module_owner_custom/registry_module_owner_custom.go

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)